Package com.glitchybyte.zappy
Class GByteBuffer
java.lang.Object
com.glitchybyte.zappy.GByteBuffer
Helper for ByteBuffer.
Ensures all storage references are little-endian.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBuffercreate()Creates a default empty buffer.static ByteBuffercreateWrapped(byte[] bytes) Creates a buffer wrapping the given byte array.static ByteBufferensureCapacity(ByteBuffer buffer, int capacity) Ensures the buffer can hold the given number of bytes.static ByteBufferensureCapacityForMoreBytes(ByteBuffer buffer, int countToAdd) Ensures the buffer can hold the given extra number of bytes.static byte[]toByteArray(ByteBuffer buffer) Returns the valid bytes from the ByteBuffer as an array.
-
Method Details
-
create
Creates a default empty buffer.- Returns:
- A ByteBuffer object.
-
createWrapped
Creates a buffer wrapping the given byte array.- Parameters:
bytes- Byte array to seed the buffer.- Returns:
- A ByteBuffer object.
-
ensureCapacity
Ensures the buffer can hold the given number of bytes.- Parameters:
buffer- Source ByteBuffer.capacity- Desired minimum buffer capacity.- Returns:
- The ByteBuffer object that should be used instead of the given one. It may be the same.
-
ensureCapacityForMoreBytes
Ensures the buffer can hold the given extra number of bytes.- Parameters:
buffer- Source ByteBuffer.countToAdd- Desired added number of bytes.- Returns:
- The ByteBuffer object that should be used instead of the given one. It may be the same.
-
toByteArray
Returns the valid bytes from the ByteBuffer as an array.- Parameters:
buffer- Source ByteBuffer.- Returns:
- Valid bytes from the ByteBuffer as an array.
-