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

intreadInt8(final ByteBuffer buffer)
read Int
int value = 0;
for (int shVal = 0, octet = 0x80; (octet & 0x80) != 0; shVal += 7) {
    if (!buffer.hasRemaining()) {
        throw new EOFException();
    octet = buffer.get();
    value |= ((octet & 0x7F) << shVal);
return value;
booleanreadIntEquals(ByteBuffer buf, int i, int j)
read Int Equals
return buf.getInt(i) == buf.getInt(j);
intreadIntLE(ByteBuffer buf, int i)
read Int LE
assert buf.order() == ByteOrder.LITTLE_ENDIAN;
return buf.getInt(i);
intreadIntMSB(ByteBuffer logBuf)
Read a int from the log in MSB order.
int ret = (logBuf.get() & 0xFF) << 24;
ret += (logBuf.get() & 0xFF) << 16;
ret += (logBuf.get() & 0xFF) << 8;
ret += (logBuf.get() & 0xFF) << 0;
return ret;
intreadIntoBuffer(SocketChannel channel, ByteBuffer buf, int sleepMsecs)
read Into Buffer
if (channel == null) {
    return -1;
buf.clear();
int totRead = 0;
while (totRead < buf.capacity()) {
    int nRead;
    try {
...
int[]readInts(final ByteBuffer bb, final int length)
read Ints
final int[] result = new int[length];
for (int index = 0; index < length; index++) {
    result[index] = bb.getInt();
return result;
voidreadInts4(final ByteBuffer buffer, final int[] array, final int count)
read Ints
readInts4(buffer, array, count, 0);
intreadUnsigned(ByteBuffer in, int size)
read Unsigned
int integer = 0;
int mask = 0xff;
int shift = 0;
for (int i = 0; i < size; i++) {
    integer |= (in.get() << shift) & mask;
    mask = mask << 8;
    shift += 8;
return integer;
intreadUnsignedByte(ByteBuffer buffer)
read Unsigned Byte
return convertByteToUnsigned(buffer.get());
longreadUnsignedInt(ByteBuffer buf)
Unmarshall the next four bytes which hold an unsigned int into a long.
long ret = (buf.get() & 0xFFL) << 0;
ret += (buf.get() & 0xFFL) << 8;
ret += (buf.get() & 0xFFL) << 16;
ret += (buf.get() & 0xFFL) << 24;
return ret;