Interface BufferComponent


  • public interface BufferComponent
    A view onto the buffer component being processed in a given iteration of Buffer.forEachComponent().
    • Method Detail

      • hasReadableArray

        boolean hasReadableArray()
        Check if this component is backed by a cached byte array that can be accessed cheaply.

        Note that regardless of what this method returns, the array should not be used to modify the contents of this buffer component.

        Returns:
        true if readableArray() is a cheap operation, otherwise false.
      • hasWritableArray

        boolean hasWritableArray()
        Check if this component is backed by a cached byte array that can be accessed cheaply.
        Returns:
        true if writableArray() is a cheap operation, otherwise false.
      • readableArray

        byte[] readableArray()
        Get a byte array of the contents of this component.

        Note that the array is meant to be read-only. It may either be a direct reference to the concrete array instance that is backing this component, or it is a fresh copy. Writing to the array may produce undefined behaviour.

        Returns:
        A byte array of the contents of this component.
        Throws:
        UnsupportedOperationException - if hasReadableArray() returns false.
        See Also:
        readableArrayOffset(), readableArrayLength()
      • baseNativeAddress

        long baseNativeAddress()
        Give the base native memory address backing this buffer, or return 0 if this buffer has no native memory address.

        The base native address, is the address that the buffer components internal read- and write-offsets are relative to, and which is used to compute the readableNativeAddress() and the writableNativeAddress().

        Note that the address should not be used for reading or writing. It should only be used for offset calculations.

        Returns:
        The base native memory address, if any, otherwise 0.
      • readableNativeAddress

        long readableNativeAddress()
        Give the native memory address backing this buffer, or return 0 if this buffer has no native memory address.

        Note that the address should not be used for writing to the buffer memory, and doing so may produce undefined behaviour.

        Returns:
        The readable native memory address, if any, otherwise 0.
      • writableNativeAddress

        long writableNativeAddress()
        Give the native memory address backing this buffer, or return 0 if this buffer has no native memory address.
        Returns:
        The writable native memory address, if any, otherwise 0.
      • readableBuffer

        ByteBuffer readableBuffer()
        Get a ByteBuffer instance for this memory component.

        Note that the ByteBuffer is read-only, to prevent write accesses to the memory, when the buffer component is obtained through Buffer.forEachComponent().

        Returns:
        A new ByteBuffer, with its own position and limit, for this memory component.
      • writableBuffer

        ByteBuffer writableBuffer()
        Get a ByteBuffer instance for this memory component, which can be used for modifying the buffer contents.
        Returns:
        A new ByteBuffer, with its own position and limit, for this memory component.
      • readableBytes

        int readableBytes()
        Get the number of readable bytes from this component.
        Returns:
        The number of bytes that can be read from this readable component.
      • writableBytes

        int writableBytes()
        Get the space available to be written to this component, as a number of bytes.
        Returns:
        The maximum number of bytes that can be written to this component.
      • openCursor

        ByteCursor openCursor()
        Open a cursor to iterate the readable bytes of this component. Any offsets internal to the component are not modified by the cursor.

        Care should be taken to ensure that the buffers lifetime extends beyond the cursor and the iteration, and that the internal offsets of the component (such as Buffer.readerOffset() and Buffer.writerOffset()) are not modified while the iteration takes place. Otherwise, unpredictable behaviour might result.

        Returns:
        A ByteCursor for iterating the readable bytes of this buffer.
        See Also:
        Buffer.openCursor()
      • skipReadableBytes

        BufferComponent skipReadableBytes​(int byteCount)
        Move the read-offset to indicate that the given number of bytes were read from this component.
        Parameters:
        byteCount - The number of bytes read from this component.
        Returns:
        itself.
        See Also:
        Buffer.skipReadableBytes(int)
      • skipWritableBytes

        BufferComponent skipWritableBytes​(int byteCount)
        Move the write-offset to indicate that the given number of bytes were written to this component.
        Parameters:
        byteCount - The number of bytes written to this component.
        Returns:
        itself.
        See Also:
        Buffer.skipWritableBytes(int)