Package com.pnfsoftware.jeb.util.io
Class ByteBufferUtil
java.lang.Object
com.pnfsoftware.jeb.util.io.ByteBufferUtil
Utility methods for
ByteBuffers.-
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 intskipAttempt(ByteBuffer b, int n) Attempt to skip bytes, including "backward skipping".static voidskipExact(ByteBuffer b, int n) 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.
-
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 of 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- source bufferoffset- offset inbsize- number of bytes to read- Returns:
- newly allocated byte array
-
getBytes
Read the remaining bytes of a buffer.- Parameters:
b- source buffer- Returns:
- newly allocated byte array
-
skipExact
Skip bytes, including "backward skipping". An exception is raised if the exact amount of bytes could not be skipped.- Parameters:
b- buffer byte 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- buffer byte buffern- number of bytes to skip (move forward); can be negative to partially rewind the pointer- 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- source buffer- Returns:
- unsigned integer value
-
getUnsignedInt
Unpack a 4-byte int and zero-extend it to a long.- Parameters:
b- source bufferindex- absolute buffer index- Returns:
- unsigned integer value
-
wrapLE
Wrap the provided bytes in a little-endian buffer.- Parameters:
array- backing byte array- Returns:
- little-endian byte buffer
-
wrapBE
Wrap the provided bytes in a big-endian buffer.- Parameters:
array- backing byte array- Returns:
- big-endian byte buffer
-
wrapLE
Wrap the provided bytes in a little-endian buffer.- Parameters:
array- backing byte arrayoffset- first byte to exposelength- number of bytes to expose- Returns:
- little-endian byte buffer
-
wrapBE
Wrap the provided bytes in a big-endian buffer.- Parameters:
array- backing byte arrayoffset- first byte to exposelength- number of bytes to expose- Returns:
- big-endian byte buffer
-
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 congruent to 0 (modulo N).- Parameters:
b- buffer to alignalign- must be >= 1- Returns:
- the buffer's new position
-