Is this the recommended way to get the bytes from the ByteBuffer
ByteBuffer bb =.. byte[] b = new byte[bb.remaining()] bb.get(b, 0, b.length);
As simple as that
private static byte[] getByteArrayFromByteBuffer(ByteBuffer byteBuffer) { byte[] bytesArray = new byte[byteBuffer.remaining()]; byteBuffer.get(bytesArray, 0, bytesArray.length); return bytesArray; }