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

intgetUShort(ByteBuffer buffer)
get U Short
return getUShort(buffer, DEFAULT_BYTE_ORDER);
intgetUShort(java.nio.ByteBuffer buffer)
get U Short
return 0xFFFF & buffer.getShort();
intreadInt(ByteBuffer buf)
read Int
if (buf.remaining() < 4) {
    throw new IOException("Not enough bytes in buffer to read integer");
int ch1 = 0x0000ffff & buf.get();
int ch2 = 0x0000ffff & buf.get();
int ch3 = 0x0000ffff & buf.get();
int ch4 = 0x0000ffff & buf.get();
if ((ch1 | ch2 | ch3 | ch4) < 0)
...
intreadInt(ByteBuffer buf, int length)
read Int
if ((buf.position() + length) <= buf.limit() && length <= 4) {
    int r = 0;
    for (int i = 0; i < length; i++) {
        r |= ((buf.get() & 0xff) << (i << 3));
    return r;
return 0;
...
intreadInt(ByteBuffer buf, int pos)
Reads a specific integer byte value (4 bytes) from the input byte buffer at the given offset.
return (((buf.get(pos) & 0xff) << 24) | ((buf.get(pos + 1) & 0xff) << 16) | ((buf.get(pos + 2) & 0xff) << 8)
        | (buf.get(pos + 3) & 0xff));
intreadInt(ByteBuffer buffer)
read Int
buffer.order(ByteOrder.LITTLE_ENDIAN);
int value = buffer.getInt();
buffer.order(ByteOrder.BIG_ENDIAN);
return value;
intreadInt(ByteBuffer buffer)
read Int
int i = buffer.get() & 0xff;
i |= (buffer.get() & 0xff) << 8;
i |= (buffer.get() & 0xff) << 16;
i |= (buffer.get() & 0xff) << 24;
return i;
IntegerreadInt(ReadableByteChannel channel, ByteBuffer buffer)
read Int
return readAndFlip(channel, buffer, 4) ? buffer.getInt() : null;
intreadInt16(ByteBuffer bb)
read Int
return bb.getShort();
intreadInt32(ByteBuffer bb)
Read an 32-bit signed integer from the byte buffer.
return bb.getInt();