Java Code Examples for com.mysql.cj.util.StringUtils#toAsciiString()

The following examples show how to use com.mysql.cj.util.StringUtils#toAsciiString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringRegressionTest.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests character conversion bug.
 * 
 * @throws Exception
 *             if there is an internal error (which is a bug).
 */
public void testAsciiCharConversion() throws Exception {
    byte[] buf = new byte[10];
    buf[0] = (byte) '?';
    buf[1] = (byte) 'S';
    buf[2] = (byte) 't';
    buf[3] = (byte) 'a';
    buf[4] = (byte) 't';
    buf[5] = (byte) 'e';
    buf[6] = (byte) '-';
    buf[7] = (byte) 'b';
    buf[8] = (byte) 'o';
    buf[9] = (byte) 't';

    String testString = "?State-bot";
    String convertedString = StringUtils.toAsciiString(buf);

    for (int i = 0; i < convertedString.length(); i++) {
        System.out.println((byte) convertedString.charAt(i));
    }

    assertTrue("Converted string != test string", testString.equals(convertedString));
}
 
Example 2
Source File: MysqlTextValueDecoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public <T> T decodeUInt8(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    // treat as a signed long if possible to avoid BigInteger overhead
    if (length <= (MAX_SIGNED_LONG_LEN - 1) && bytes[0] >= '0' && bytes[0] <= '8') {
        return decodeInt8(bytes, offset, length, vf);
    }
    BigInteger i = new BigInteger(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigInteger(i);
}
 
Example 3
Source File: Clob.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void streamClosed(WatchableStream out) {
    int streamSize = out.size();

    if (streamSize < this.charData.length()) {
        out.write(StringUtils.getBytes(this.charData), streamSize, this.charData.length() - streamSize);
    }

    this.charData = StringUtils.toAsciiString(out.toByteArray());
}
 
Example 4
Source File: Clob.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void streamClosed(WatchableStream out) {
    int streamSize = out.size();

    if (streamSize < this.charData.length()) {
        out.write(StringUtils.getBytes(this.charData), streamSize, this.charData.length() - streamSize);
    }

    this.charData = StringUtils.toAsciiString(out.toByteArray());
}
 
Example 5
Source File: MysqlTextValueDecoder.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public <T> T decodeUInt8(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    // treat as a signed long if possible to avoid BigInteger overhead
    if (length <= (MAX_SIGNED_LONG_LEN - 1) && bytes[0] >= '0' && bytes[0] <= '8') {
        return decodeInt8(bytes, offset, length, vf);
    }
    BigInteger i = new BigInteger(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigInteger(i);
}
 
Example 6
Source File: MysqlBinaryValueDecoder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    BigDecimal d = new BigDecimal(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigDecimal(d);
}
 
Example 7
Source File: MysqlTextValueDecoder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    BigDecimal d = new BigDecimal(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigDecimal(d);
}
 
Example 8
Source File: MysqlBinaryValueDecoder.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    BigDecimal d = new BigDecimal(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigDecimal(d);
}
 
Example 9
Source File: MysqlTextValueDecoder.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    BigDecimal d = new BigDecimal(StringUtils.toAsciiString(bytes, offset, length));
    return vf.createFromBigDecimal(d);
}