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

intgetUnsignedShort(ByteBuffer bb)
get Unsigned Short
if (bb.remaining() >= 2) {
    return ((0x0FF & bb.get()) << 8) + (0x0FF & bb.get());
} else {
    throw new IndexOutOfBoundsException();
intgetUnsignedShort(ByteBuffer bb)
get Unsigned Short
return (bb.getShort() & 0xffff);
intgetUnsignedShort(ByteBuffer buf)
This is a relative method for getting 2 unsigned bytes.
return buf.getShort() & 0x0000FFFF;
intgetUnsignedShort(ByteBuffer buffer)
get Unsigned Short
return buffer.getShort() & 0xFFFF;
intgetUnsignedShort(ByteBuffer buffer, int offset)
Reads a big-endian unsigned short integer from the buffer at the provided offset.
return (buffer.get(offset) & 0xFF) << 8 | buffer.get(offset + 1) & 0xFF;
intgetUnsignedShort(ByteBuffer bytes)
get Unsigned Short
if (bytes.remaining() < 2)
    throw new IOException("too few bytes specified for unsigned short value!");
byte b1 = bytes.get();
byte b2 = bytes.get();
int value = (int) ((0xff & b1) << 8 | (0xff & b2));
return value;
intgetUnsignedSmart(ByteBuffer buf)
Gets a unsigned smart from the buffer.
int peek = buf.get(buf.position()) & 0xFF;
if (peek < 128)
    return buf.get() & 0xFF;
else
    return (buf.getShort() & 0xFFFF) - 32768;
intgetUnsignedSmartInt(ByteBuffer buffer)
get Unsigned Smart Int
if ((buffer.get(buffer.position()) & 0xff) < 128) {
    return buffer.get() & 0xff;
int shortValue = buffer.getShort() & 0xFFFF;
return shortValue - 32768;
intgetUnsignedVarInt(ByteBuffer buffer, int numBytes)
Read an unsigned variable length int from a buffer
int pos = buffer.position();
int rtn = getUnsignedVarInt(buffer, pos, numBytes);
buffer.position(pos + numBytes);
return rtn;
intgetUShort(ByteBuffer buffer)
get U Short
assert (buffer.capacity() - buffer.position() >= 2);
byte[] data = new byte[2];
data[1] = buffer.get();
data[0] = buffer.get();
return ((data[0] << 8) & 0x0000ff00) | (data[1] & 0x000000ff);