Package com.pnfsoftware.jeb.util.io
Class ByteBufferUtil
java.lang.Object
com.pnfsoftware.jeb.util.io.ByteBufferUtil
Utility methods for
ByteBuffers.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intalign(ByteBuffer b, int align) Align the buffer using the provided byte alignment.static booleanequalsByteArray(ByteBuffer b, int bufferOffset, byte[] a, int arrayOffset, int size) Compare bytes of a buffer against the bytes of an array.static byte[]Read the remaining bytes of a buffer.static byte[]getBytes(ByteBuffer b, int offset, int size) Extract a sequence of bytes from a buffer into a newly-created byte array.static longUnpack a 4-byte int and zero-extend it to a long.static longgetUnsignedInt(ByteBuffer b, int index) Unpack a 4-byte int and zero-extend it to a long.static voidskip(ByteBuffer b, int n) Skip bytes, including "backward skipping".static intskipAttempt(ByteBuffer b, int n) Attempt to skip bytes, including "backward skipping".static voidGo to the end of the buffer.static ByteBufferwrapBE(byte[] array) Wrap the provided bytes in a big-endian buffer.static ByteBufferwrapBE(byte[] array, int offset, int length) Wrap the provided bytes in a big-endian buffer.static ByteBufferwrapLE(byte[] array) Wrap the provided bytes in a little-endian buffer.static ByteBufferwrapLE(byte[] array, int offset, int length) Wrap the provided bytes in a little-endian buffer.
-
Constructor Details
-
ByteBufferUtil
public ByteBufferUtil()
-
-
Method Details
-
equalsByteArray
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 bufferbufferOffset- offset in buffera- source arrayarrayOffset- offset in arraysize- number to bytes to be compared- Returns:
- true on equality
-
getBytes
Extract a sequence of bytes from a buffer into a newly-created byte array.- Parameters:
b-offset- offset in `b` (!)size- number of bytes to read, from `b.position()`- Returns:
-
getBytes
Read the remaining bytes of a buffer.- Parameters:
b-- Returns:
-
skip
Skip bytes, including "backward skipping". An exception is raised if the exact amount of bytes could not be skipped.- Parameters:
b- buffern- number of bytes to skip (move forward); can be negative to partially rewind the pointer
-
skipAttempt
Attempt to skip bytes, including "backward skipping".- Parameters:
b- buffern- number of bytes to skip- Returns:
- the number of bytes skipped.
-
skipToEnd
Go to the end of the buffer.- Parameters:
b- buffer
-
getUnsignedInt
Unpack a 4-byte int and zero-extend it to a long.- Parameters:
b-- Returns:
-
getUnsignedInt
Unpack a 4-byte int and zero-extend it to a long.- Parameters:
b-index-- Returns:
-
wrapLE
Wrap the provided bytes in a little-endian buffer.- Parameters:
array-- Returns:
-
wrapBE
Wrap the provided bytes in a big-endian buffer.- Parameters:
array-- Returns:
-
wrapLE
Wrap the provided bytes in a little-endian buffer.- Parameters:
array-offset-length-- Returns:
-
wrapBE
Wrap the provided bytes in a big-endian buffer.- Parameters:
array-offset-length-- Returns:
-
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:
b-align- must be >= 1- Returns:
- the buffer's new position
-