public class

ByteBufferUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.io.ByteBufferUtil

Class Overview

Utility methods for ByteBuffers.

Summary

Public Constructors
ByteBufferUtil()
Public Methods
static int align(ByteBuffer b, int align)
Align the buffer using the provided byte alignment.
static boolean equalsByteArray(ByteBuffer b, int bufferOffset, byte[] a, int arrayOffset, int size)
Compare bytes of a buffer against the bytes of an array.
static byte[] getBytes(ByteBuffer b, int offset, int size)
Extract a sequence of bytes from a buffer into a newly-created byte array.
static byte[] getBytes(ByteBuffer b)
Read the remaining bytes of a buffer.
static long getUnsignedInt(ByteBuffer b)
Unpack a 4-byte int and zero-extend it to a long.
static long getUnsignedInt(ByteBuffer b, int index)
Unpack a 4-byte int and zero-extend it to a long.
static void skip(ByteBuffer b, int n)
Skip bytes, including "backward skipping".
static int skipAttempt(ByteBuffer b, int n)
Attempt to skip bytes, including "backward skipping".
static void skipToEnd(ByteBuffer b)
Go to the end of the buffer.
static ByteBuffer wrapBE(byte[] array, int offset, int length)
Wrap the provided bytes in a big-endian buffer.
static ByteBuffer wrapBE(byte[] array)
Wrap the provided bytes in a big-endian buffer.
static ByteBuffer wrapLE(byte[] array, int offset, int length)
Wrap the provided bytes in a little-endian buffer.
static ByteBuffer wrapLE(byte[] array)
Wrap the provided bytes in a little-endian buffer.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ByteBufferUtil ()

Public Methods

public static int align (ByteBuffer b, int align)

Align the buffer using the provided byte alignment. The position will be increased from anything from 0 to ALIGN-1 bytes so that the new position is congurent to 0 (modulo N).

Parameters
align must be >= 1
Returns
  • the buffer's new position

public static boolean equalsByteArray (ByteBuffer b, int bufferOffset, byte[] a, int arrayOffset, int size)

Compare bytes of a buffer against the bytes of an array.

Parameters
b source buffer
bufferOffset offset in buffer
a source array
arrayOffset offset in array
size number to bytes to be compared
Returns
  • true on equality

public static byte[] getBytes (ByteBuffer b, int offset, int size)

Extract a sequence of bytes from a buffer into a newly-created byte array.

Parameters
offset offset in `b` (!)
size number of bytes to read, from `b.position()`

public static byte[] getBytes (ByteBuffer b)

Read the remaining bytes of a buffer.

public static long getUnsignedInt (ByteBuffer b)

Unpack a 4-byte int and zero-extend it to a long.

public static long getUnsignedInt (ByteBuffer b, int index)

Unpack a 4-byte int and zero-extend it to a long.

public static void skip (ByteBuffer b, int n)

Skip bytes, including "backward skipping". An exception is raised if the exact amount of bytes could not be skipped.

Parameters
b buffer
n number of bytes to skip (move forward); can be negative to partially rewind the pointer

public static int skipAttempt (ByteBuffer b, int n)

Attempt to skip bytes, including "backward skipping".

Parameters
b buffer
n number of bytes to skip
Returns
  • the number of bytes skipped.

public static void skipToEnd (ByteBuffer b)

Go to the end of the buffer.

Parameters
b buffer

public static ByteBuffer wrapBE (byte[] array, int offset, int length)

Wrap the provided bytes in a big-endian buffer.

public static ByteBuffer wrapBE (byte[] array)

Wrap the provided bytes in a big-endian buffer.

public static ByteBuffer wrapLE (byte[] array, int offset, int length)

Wrap the provided bytes in a little-endian buffer.

public static ByteBuffer wrapLE (byte[] array)

Wrap the provided bytes in a little-endian buffer.