Java Utililty Methods ByteBuffer to Int

List of utility methods to do ByteBuffer to Int

Description

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

Method

longreadUnsignedInt(ByteBuffer buffer)
Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes
return buffer.getInt() & 0xffffffffL;
longreadUnsignedInt(ByteBuffer buffer, int index)
Read an unsigned integer from the given position without modifying the buffers position
return buffer.getInt(index) & 0xffffffffL;
longreadUnsignedInt(ByteBuffer byteBuf)
read Unsigned Int
long val = byteBuf.getInt();
if (val < 0)
    val &= 0xFFFFFFFFL;
return val;
intreadUnsignedMedium(ByteBuffer buf)
Gets a smart.
int peek = buf.get(buf.position()) & 0xFF;
if (peek < 128) {
    return buf.get() & 0xFF;
} else {
    return (buf.getShort() & 0xFFFF) - 32768;
intreadUnsignedShort(ByteBuffer bb)
See the general contract of the readUnsignedShort method of DataInput.
int ch1 = bb.get() & 0xFF; 
int ch2 = bb.get() & 0xFF; 
return (ch1 << 8) + (ch2 << 0);
intreadUnsignedShort(ByteBuffer buffer)
read Unsigned Short
return buffer.getShort() & 0xFFFF;
intreadUnsignedTriByte(ByteBuffer buffer)
Reads an unsigned tri byte from the specified buffer.
return (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
intreadUnsignedVarint(ByteBuffer buffer)
Read an unsigned integer.
int val = 0;
int bits = 0;
while (true) {
    final int data = buffer.get();
    val |= (data & 0x7F) << bits;
    if ((data & 0x80) == 0) {
        return val;
    bits += 7;
    if (bits > 35) {
        throw new IOException("Variable length quantity is too long for expected integer.");
intreadVarInt(ByteBuffer buff)
Read a variable size int.
int b = buff.get();
if (b >= 0) {
    return b;
return readVarIntRest(buff, b);
intreadVarInt(ByteBuffer buff)
Reads a VarInt.
int shift = 0, i = 0;
while (true) {
    byte b = (byte) buff.get();
    i |= (b & 0x7F) << shift;
    shift += 7;
    if (b >= 0) {
        return i;