Java Utililty Methods ByteBuffer Read

List of utility methods to do ByteBuffer Read

Description

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

Method

SerializablereadObject(ByteBuffer byteBuffer)
read Object
ByteArrayInputStream bis = null;
ObjectInputStream ois = null;
Serializable object = null;
try {
    byte[] bytes = readToBytes(byteBuffer);
    bis = new ByteArrayInputStream(bytes);
    ois = new ObjectInputStream(new BufferedInputStream(bis));
    object = (Serializable) ois.readObject();
...
doublereadReal(ByteBuffer bb)
read Real
return bb.getDouble();
intreadResBit15(ByteBuffer fromBuffer)
read Res Bit
int b = readUnsignedByte(fromBuffer);
if ((b & 0x80) != 0) {
    return (short) (((b & 0x7F) << 8) + readUnsignedByte(fromBuffer));
return (short) b;
intreadShortLE(ByteBuffer buf, int i)
read Short LE
return (buf.get(i) & 0xFF) | ((buf.get(i + 1) & 0xFF) << 8);
intreadShortLength(ByteBuffer bb)
read Short Length
int length = (bb.get() & 0xFF) << 8;
return length | (bb.get() & 0xFF);
short[]readShorts(final ByteBuffer bb, final int length)
read Shorts
final short[] result = new short[length];
for (int index = 0; index < length; index++) {
    result[index] = bb.getShort();
return result;
StringreadShortString(ByteBuffer buffer)
read bytes with a short sign prefix(mark the size of bytes)
short size = buffer.getShort();
if (size < 0) {
    return null;
byte[] bytes = new byte[size];
buffer.get(bytes);
return fromBytes(bytes);
intreadSignedVarint(ByteBuffer buffer)
Read a signed integer.
final int raw = readUnsignedVarint(buffer);
return (raw >>> 1) ^ -(raw & 1);
intreadSize(ByteBuffer buf)
Read size from ByteBuffer
int s = 0;
for (int count = 0; count < 4; count++) {
    byte b = (byte) (buf.get() & 0xff);
    s <<= 7;
    s |= b & 0x7f;
    if (0 == (b & 0x80)) {
        break;
return s;
intreadSize(ByteBuffer buffer)
read Size
final byte b = buffer.get();
if (b == -1)
    return -1;
else if (b == -2) {
    final int s = buffer.getInt();
    if (s < 0)
        throw new RuntimeException("negative array size");
    return s;
...