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

The following examples show how to use com.mysql.cj.util.StringUtils#toAsciiString() . These examples are extracted from open source projects. 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
/**
 * 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
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 Project: lams   File: Clob.java    License: 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 Project: FoxTelem   File: Clob.java    License: 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
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
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
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
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
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);
}