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

intreadSmart(ByteBuffer buffer)
Reads a 'smart' (either a byte or short depending on the value) from the specified buffer.
int peek = buffer.get(buffer.position()) & 0xFF;
if (peek < 128) {
    return buffer.get() & 0xFF;
return (buffer.getShort() & 0xFFFF) - 32768;
byte[]readToBytes(ByteBuffer byteBuffer)
read To Bytes
int remain = byteBuffer.remaining();
byte[] data = new byte[remain];
byteBuffer.get(data);
return data;
longreadTs(ByteBuffer is)
read Ts
return (((long) is.get() & 0x0e) << 29) | ((is.get() & 0xff) << 22) | (((is.get() & 0xff) >> 1) << 15)
        | ((is.get() & 0xff) << 7) | ((is.get() & 0xff) >> 1);
longreadTs(ByteBuffer is, int c)
read Ts
return (((long) c & 0x0e) << 29) | ((is.get() & 0xff) << 22) | (((is.get() & 0xff) >> 1) << 15)
        | ((is.get() & 0xff) << 7) | ((is.get() & 0xff) >> 1);
UUIDreadUUID(ByteBuffer buffer)
read UUID
long most = buffer.getLong();
long least = buffer.getLong();
return new UUID(most, least);
intreadVariableLength(ByteBuffer buf)
read Variable Length
int length = 0;
int cur;
if (buf.hasRemaining())
    do {
        cur = buf.get();
        length |= (cur & 0x7F);
        if ((cur & 0x80) != 0)
            length <<= 7;
...
intreadVInt(ByteBuffer bb)
read V Int
return (int) readVLong(bb);
intreadVInt(ByteBuffer bb)
Reads an int stored in variable-length format.
byte b = bb.get();
int i = b & 0x7F;
if ((b & 0x80) == 0)
    return i;
b = bb.get();
i |= (b & 0x7F) << 7;
if ((b & 0x80) == 0)
    return i;
...
ListreadVL(ByteBuffer byteBuffer)
read VL
List<Long> ret = new ArrayList<Long>();
int size = byteBuffer.getInt();
for (int i = 0; i < size; ++i) {
    ret.add(byteBuffer.getLong());
return ret;
StringreadZeroTermStr(ByteBuffer bb)
read Zero Term Str
int off = bb.position();
while (bb.hasRemaining()) {
    byte b = bb.get();
    if (b == 0) {
        break;
int len = bb.position() - off;
...