Class GByteBuffer

java.lang.Object
com.glitchybyte.zappy.GByteBuffer

public final class GByteBuffer extends Object
Helper for ByteBuffer.

Ensures all storage references are little-endian.

  • Method Details

    • create

      public static ByteBuffer create()
      Creates a default empty buffer.
      Returns:
      A ByteBuffer object.
    • createWrapped

      public static ByteBuffer createWrapped(byte[] bytes)
      Creates a buffer wrapping the given byte array.
      Parameters:
      bytes - Byte array to seed the buffer.
      Returns:
      A ByteBuffer object.
    • ensureCapacity

      public static ByteBuffer ensureCapacity(ByteBuffer buffer, int capacity)
      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

      public static ByteBuffer ensureCapacityForMoreBytes(ByteBuffer buffer, int countToAdd)
      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

      public static byte[] toByteArray(ByteBuffer buffer)
      Returns the valid bytes from the ByteBuffer as an array.
      Parameters:
      buffer - Source ByteBuffer.
      Returns:
      Valid bytes from the ByteBuffer as an array.