List of utility methods to do ByteBuffer Serialize
Object | deserialize(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); ... |
T | deserialize(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); |
Boolean | deserializeBoolean(ByteBuffer buf) deserialize Boolean byte bb = buf.get(); return (bb != 0); |
T | deserializeFromByteBufferNoHeader(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) { ... |
Object | deserializeObject(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; |
void | serializeBigDecimal(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"); ... |
void | serializeNull(ByteBuffer buf) Serialize the null decimal sigil to a the provided java.nio.ByteBuffer ByteBuffer buf.put(NULL_INDICATOR); |
void | serializeString(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()); |
void | serializeStringArray(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]); |