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

intreadVarint(ByteBuffer buffer)
Read an integer stored in variable-length format using zig-zag decoding from Google Protocol Buffers.
int value = 0;
int i = 0;
int b;
while (((b = buffer.get()) & 0x80) != 0) {
    value |= (b & 0x7f) << i;
    i += 7;
    if (i > 28)
        throw illegalVarintException(value);
...
intreadVarInt(ByteBuffer buffer)
read Var Int
int i = 0;
int j = 0;
while (true) {
    int b0 = buffer.get();
    i |= (b0 & 127) << j++ * 7;
    if (j > 5) {
        throw new IOException("VarInt too big");
    if ((b0 & 128) != 128) {
        break;
return i;
intreadVarInt(ByteBuffer stream)
read Var Int
final byte b[] = new byte[1];
int count = 0;
int result = 0;
do {
    if (count == 5) {
        throw new IOException("stream corrupted");
    stream.get(b);
...
intreadVarIntRest(ByteBuffer buff, int b)
read Var Int Rest
int x = b & 0x7f;
b = buff.get();
if (b >= 0) {
    return x | (b << 7);
x |= (b & 0x7f) << 7;
b = buff.get();
if (b >= 0) {
...
inttoInt(ByteBuffer buffer)
to Int
return toByteBuffer(buffer, Integer.BYTES).getInt();
inttoInt(ByteBuffer buffer)
Convert buffer to an integer.
return toInt(buffer, buffer.position(), buffer.remaining());
inttoInt(ByteBuffer bytes)
Convert a byte buffer to an integer.
return bytes.getInt(bytes.position());
inttoInt(ByteBuffer value)
to Int
int result = 0;
try {
    if (value != null) {
        int originPos = value.position();
        result = value.getInt();
        value.position(originPos);
} catch (Exception ex) {
...
inttoInt16BE(ByteBuffer buf, int[] out)
to Int BE
int samples = 0;
while (buf.remaining() >= 2 && samples < out.length) {
    out[samples++] = (short) (((buf.get() & 0xff) << 8) | (buf.get() & 0xff));
return samples;