Java Utililty Methods ByteBuffer Serialize

List of utility methods to do ByteBuffer Serialize

Description

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

Method

Objectdeserialize(ByteBuffer b)
Deserialize an object from a ByteBuffer.
try {
    ByteArrayInputStream bais = new ByteArrayInputStream(b.array());
    ObjectInputStream ois = new ObjectInputStream(bais);
    return ois.readObject();
} catch (IOException e) {
    throw new RuntimeException(e);
} catch (ClassNotFoundException ce) {
    throw new RuntimeException(ce);
...
Tdeserialize(ByteBuffer byteBuffer)
deserialize
ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer.array());
try (ObjectInputStream oip = new ObjectInputStream(bais)) {
    T result = (T) oip.readObject();
    return result;
} catch (IOException | ClassNotFoundException e) {
    throw new IllegalArgumentException(e);
BooleandeserializeBoolean(ByteBuffer buf)
deserialize Boolean
byte bb = buf.get();
return (bb != 0);
TdeserializeFromByteBufferNoHeader(ByteBuffer bytes)
deserialize From Byte Buffer No Header
ObjectInputStream in = new ObjectInputStream(newInputStream(bytes)) {
    @Override
    protected void readStreamHeader() throws IOException {
};
try {
    T value = deserializeFromStream(in);
    if (in.read() != -1) {
...
ObjectdeserializeObject(ByteBuffer obj)
This method deserializes an object stored in byte buffer form.
byte[] objAsByteArray = new byte[obj.limit()];
obj.get(objAsByteArray);
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(objAsByteArray);
ObjectInputStream objInputStream = new ObjectInputStream(byteInputStream);
Object result = objInputStream.readObject();
objInputStream.close();
return result;
voidserializeBigDecimal(BigDecimal bd, ByteBuffer buf)
Serialize the java.math.BigDecimal BigDecimal to Volt's fixed precision and scale 16-byte format.
if (bd == null) {
    serializeNull(buf);
    return;
final int scale = bd.scale();
final int precision = bd.precision();
if (scale > 12) {
    throw new RuntimeException("Scale of " + bd + " is " + scale + " and the max is 12");
...
voidserializeNull(ByteBuffer buf)
Serialize the null decimal sigil to a the provided java.nio.ByteBuffer ByteBuffer
buf.put(NULL_INDICATOR);
voidserializeString(final String value, ByteBuffer buffer)
serialize String
if (value == null)
    writeSize(-1, buffer);
else {
    final int len = value.length();
    writeSize(len, buffer);
    buffer.put(value.getBytes()); 
voidserializeStringArray(ByteBuffer buf, String[] strArray)
serialize String Array
if (strArray == null || strArray.length == 0) {
    buf.putInt(0);
    return;
buf.putInt(strArray.length);
for (int i = 0; i < strArray.length; i++) {
    serializeString(buf, strArray[i]);