Class AllocatedBuffer

    • Constructor Summary

      Constructors 
      Constructor Description
      AllocatedBuffer()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract byte[] array()
      Returns the byte array that backs this buffer (optional operation).
      abstract int arrayOffset()
      Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).
      abstract boolean hasArray()
      Indicates whether this buffer contains a backing array (i.e.
      abstract boolean hasNioBuffer()
      Indicates whether this buffer contains a backing ByteBuffer (i.e.
      abstract int limit()
      Returns this buffer's limit.
      abstract java.nio.ByteBuffer nioBuffer()
      Returns the ByteBuffer that backs this buffer (optional operation).
      abstract int position()
      Returns this buffer's position.
      abstract AllocatedBuffer position​(int position)
      Sets this buffer's position.
      abstract int remaining()
      Returns the number of elements between the current position() and the limit() .
      static AllocatedBuffer wrap​(byte[] bytes)
      Creates a new AllocatedBuffer that is backed by the given array.
      static AllocatedBuffer wrap​(byte[] bytes, int offset, int length)
      Creates a new AllocatedBuffer that is backed by the given array.
      static AllocatedBuffer wrap​(java.nio.ByteBuffer buffer)
      Creates a new AllocatedBuffer that is backed by the given ByteBuffer.
      private static AllocatedBuffer wrapNoCheck​(byte[] bytes, int offset, int length)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AllocatedBuffer

        AllocatedBuffer()
    • Method Detail

      • hasNioBuffer

        public abstract boolean hasNioBuffer()
        Indicates whether this buffer contains a backing ByteBuffer (i.e. it is safe to call nioBuffer()).
      • hasArray

        public abstract boolean hasArray()
        Indicates whether this buffer contains a backing array (i.e. it is safe to call array()).
      • nioBuffer

        public abstract java.nio.ByteBuffer nioBuffer()
        Returns the ByteBuffer that backs this buffer (optional operation).

        Call hasNioBuffer() before invoking this method in order to ensure that this buffer has a backing ByteBuffer.

        Returns:
        The ByteBuffer that backs this buffer
        Throws:
        java.lang.UnsupportedOperationException - If this buffer is not backed by a ByteBuffer.
      • array

        public abstract byte[] array()
        Returns the byte array that backs this buffer (optional operation).

        Call hasArray() before invoking this method in order to ensure that this buffer has an accessible backing array.

        Returns:
        The array that backs this buffer
        Throws:
        java.nio.ReadOnlyBufferException - If this buffer is backed by an array but is read-only
        java.lang.UnsupportedOperationException - If this buffer is not backed by an accessible array
      • arrayOffset

        public abstract int arrayOffset()
        Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).

        If this buffer is backed by an array then position() corresponds to the array index position() + arrayOffset().

        Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.

        Returns:
        The offset within this buffer's array of the first element of the buffer
        Throws:
        java.nio.ReadOnlyBufferException - If this buffer is backed by an array but is read-only
        java.lang.UnsupportedOperationException - If this buffer is not backed by an accessible array
      • position

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

        @CanIgnoreReturnValue
        public abstract AllocatedBuffer position​(int position)
        Sets this buffer's position.
        Parameters:
        position - The new position value; must be non-negative and no larger than the current limit
        Returns:
        This buffer
        Throws:
        java.lang.IllegalArgumentException - If the preconditions on position do not hold
      • limit

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

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

        private static AllocatedBuffer wrapNoCheck​(byte[] bytes,
                                                   int offset,
                                                   int length)