Class SmallBuffer

java.lang.Object
tech.bitey.bufferstuff.SmallBuffer
Direct Known Subclasses:
SmallByteBuffer, SmallDoubleBuffer, SmallFloatBuffer, SmallIntBuffer, SmallLongBuffer, SmallShortBuffer

public abstract sealed class SmallBuffer extends Object permits SmallByteBuffer, SmallShortBuffer, SmallIntBuffer, SmallLongBuffer, SmallFloatBuffer, SmallDoubleBuffer
This class has an API similar to Buffer. All implementations are backed by a BigByteBuffer. "Small" refers to the fact that these buffers are indexed by ints rather than longs.

Differences from Buffer include:

  • mark and reset are not supported
  • read-only is not supported
  • byte order is preserved in duplicate() and slice().
Author:
biteytech@protonmail.com, adapted from Buffer
  • Method Details

    • unwrap

      public BigByteBuffer unwrap()
      Returns the underlying buffer.
      Returns:
      the underlying buffer.
    • position

      public int position()
      Returns this buffer's position.
      Returns:
      The position of this buffer
    • limit

      public int limit()
      Returns this buffer's limit.
      Returns:
      The limit of this buffer
    • capacity

      public int capacity()
      Returns this buffer's capacity.
      Returns:
      The capacity of this buffer
    • position

      public SmallBuffer position(int newPosition)
      Sets this buffer's position.
      Parameters:
      newPosition - The new position value; must be non-negative and no larger than the current limit
      Returns:
      this buffer
      Throws:
      IllegalArgumentException - If the preconditions on newPosition do not hold
    • limit

      public SmallBuffer limit(int newLimit)
      Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit.
      Parameters:
      newLimit - The new limit value; must be non-negative and no larger than this buffer's capacity
      Returns:
      this buffer
      Throws:
      IllegalArgumentException - If the preconditions on newLimit do not hold
    • remaining

      public int remaining()
      Returns the number of elements between the current position and the limit.
      Returns:
      The number of elements remaining in this buffer
    • hasRemaining

      public boolean hasRemaining()
      Tells whether there are any elements between the current position and the limit.
      Returns:
      true if, and only if, there is at least one element remaining in this buffer
    • order

      public ByteOrder order()
      Retrieves this buffer's byte order.

      The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer.

      Returns:
      This buffer's byte order
    • duplicate

      public abstract SmallBuffer duplicate()
      Creates a new buffer that shares this buffer's content.

      The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position and limit values will be independent.

      The new buffer's capacity, limit, position, and byte order values will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct.

      Returns:
      The new buffer
    • slice

      public abstract SmallBuffer slice()
      Creates a new buffer whose content is a shared subsequence of this buffer's content.

      The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position and limit values will be independent.

      The new buffer's position will be zero, its capacity and its limit will be the number of elements remaining in this buffer, and the byte order will be the same as this buffer. The new buffer will be direct if, and only if, this buffer is direct.

      Returns:
      The new buffer
    • clear

      public SmallBuffer clear()
      Clears this buffer. The position is set to zero and the limit is set to the capacity.

      This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.

      Returns:
      This buffer
    • flip

      public SmallBuffer flip()
      Flips this buffer. The limit is set to the current position and then the position is set to zero.
      Returns:
      This buffer