Java Utililty Methods Convert via ByteBuffer

List of utility methods to do Convert via ByteBuffer

Description

The list of methods to do Convert via ByteBuffer are organized into topic(s).

Method

voidtoArray(IntBuffer src, int[] dst, int offset)
to Array
src.position(0);
src.get(dst, offset, dst.length - offset);
byte[]toArray(long length)
to Array
long value = length;
byte[] b = new byte[8];
for (int i = 7; i >= 0 && value > 0; i--) {
    b[i] = (byte) (value & 0xFF);
    value >>= 8;
return b;
byte[]toASCII(String str)
to ASCII
try {
    return str.getBytes("US-ASCII");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
ByteBuffertoAsciiBytes(String s)
to Ascii Bytes
return put(ByteBuffer.allocate(s.length()), s);
StringtoASCIIString(URI u)
Returns the content of this URI as a US-ASCII string.
String s = defineString(u);
return encode(s);
AttributeValuetoAttributeValue(Object value)
Copied from DynamoDB Document SDK InternalUtils.java Converts a simple value into the low-level representation.
AttributeValue result = new AttributeValue();
if (value == null) {
    return result.withNULL(Boolean.TRUE);
} else if (value instanceof Boolean) {
    return result.withBOOL((Boolean) value);
} else if (value instanceof String) {
    return result.withS((String) value);
} else if (value instanceof BigDecimal || value instanceof Number) {
...
BigDecimaltoBigDecimal(byte[] bytes, int scale)
to Big Decimal
return new BigDecimal(toBigInteger(bytes), scale);
BigIntegertoBigInteger(byte[] bytes)
to Big Integer
return new BigInteger(bytes);
byte[]toBinaryFloatingPoint(double source)
to Binary Floating Point
byte[] res = new byte[8];
ByteBuffer.wrap(res).putDouble(source);
return res;
StringtoBinaryString(byte[] b)
to Binary String
String o = "";
for (int i = 0; i < b.length; i++) {
    o += hexbin[((b[i] & 255) >>> 4)] + hexbin[(b[i] & 15)];
return o;