Class CompositeByteArraySegment

  • All Implemented Interfaces:
    BufferView, CompositeArrayView, StructuredWritableBuffer

    public class CompositeByteArraySegment
    extends AbstractBufferView
    implements CompositeArrayView
    A composite, index-based array-like structure that is made up of one or more individual arrays of equal size. Each component array maps to a contiguous offset range and is only allocated when the first index within its range needs to be set (if unallocated, any index within its range will have a value of 0).
    • Constructor Detail

      • CompositeByteArraySegment

        public CompositeByteArraySegment​(int length)
        Creates a new instance of the CompositeByteArraySegment class with a default component array size.
        Parameters:
        length - The length of the CompositeByteArraySegment. This will determine the number of components to use, but doesn't allocate any of them yet.
      • CompositeByteArraySegment

        public CompositeByteArraySegment​(@NonNull
                                         @lombok.NonNull byte[] source)
        Creates a new instance of the CompositeByteArraySegment class that wraps the given array. This instance will have a single component array.
        Parameters:
        source - The byte array to wrap. Any changes made to this array will be reflected in this CompositeByteArraySegment instance and vice-versa.
    • Method Detail

      • get

        public byte get​(int offset)
        Description copied from interface: CompositeArrayView
        Gets the value at the specified index.
        Specified by:
        get in interface CompositeArrayView
        Parameters:
        offset - The index to query.
        Returns:
        Byte indicating the value at the given index.
      • set

        public void set​(int offset,
                        byte value)
        Description copied from interface: StructuredWritableBuffer
        Sets the value at the specified index.
        Specified by:
        set in interface StructuredWritableBuffer
        Parameters:
        offset - The index to set the value at.
        value - The Byte value to set.
      • setShort

        public void setShort​(int offset,
                             short value)
        Description copied from interface: StructuredWritableBuffer
        Sets a Short value at the specified index.
        Specified by:
        setShort in interface StructuredWritableBuffer
        Parameters:
        offset - The index to set the value at.
        value - The Short value to set.
      • setInt

        public void setInt​(int offset,
                           int value)
        Description copied from interface: StructuredWritableBuffer
        Sets a 32 bit Integer value at the specified index.
        Specified by:
        setInt in interface StructuredWritableBuffer
        Parameters:
        offset - The index to set the value at.
        value - The Integer value to set.
      • setLong

        public void setLong​(int offset,
                            long value)
        Description copied from interface: StructuredWritableBuffer
        Sets a 64 bit Long value at the specified index.
        Specified by:
        setLong in interface StructuredWritableBuffer
        Parameters:
        offset - The index to set the value at.
        value - The Long value to set.
      • getReader

        public java.io.InputStream getReader()
        Description copied from interface: BufferView
        Creates an InputStream that can be used to read the contents of this BufferView. The InputStream returned spans the entire BufferView.
        Specified by:
        getReader in interface BufferView
        Returns:
        The InputStream.
      • getReader

        public java.io.InputStream getReader​(int offset,
                                             int length)
        Description copied from interface: BufferView
        Creates an InputStream that can be used to read the contents of this BufferView.
        Specified by:
        getReader in interface BufferView
        Parameters:
        offset - The starting offset of the section to read.
        length - The length of the section to read.
        Returns:
        The InputStream.
      • collect

        public <ExceptionT extends java.lang.Exception> void collect​(BufferView.Collector<ExceptionT> bufferCollector)
                                                              throws ExceptionT extends java.lang.Exception
        Description copied from interface: BufferView
        Iterates through each of the buffers that make up this BufferView, in order, and invokes the given BufferView.Collector on each.
        Specified by:
        collect in interface BufferView
        Type Parameters:
        ExceptionT - Type of exception that the BufferView.Collector function throws, if any.
        Parameters:
        bufferCollector - A BufferView.Collector function that will be invoked for each component. Each ByteBuffer passed as an argument to this function is a direct pointer to the data contained within the BufferView (i.e., they are not copies of the data).
        Throws:
        ExceptionT - If the BufferView.Collector function throws an exception of this type, the iteration will end and the exception will be bubbled up.
        ExceptionT extends java.lang.Exception
      • iterateBuffers

        public java.util.Iterator<java.nio.ByteBuffer> iterateBuffers()
        Description copied from interface: BufferView
        Gets an Iterator through each of the ByteBuffers that make up this BufferView, in order.
        Specified by:
        iterateBuffers in interface BufferView
        Returns:
        A Iterator.
      • getCopy

        public byte[] getCopy()
        Description copied from interface: BufferView
        Returns a copy of the contents of this BufferView.
        Specified by:
        getCopy in interface BufferView
        Returns:
        A byte array with the same length as this ArrayView, containing a copy of the data within it.
      • copyTo

        public void copyTo​(java.io.OutputStream target)
                    throws java.io.IOException
        Description copied from interface: BufferView
        Copies the contents of this BufferView to the given OutputStream.
        Specified by:
        copyTo in interface BufferView
        Parameters:
        target - The OutputStream to write to.
        Throws:
        java.io.IOException - If an exception occurred while writing to the target OutputStream.
      • copyTo

        public int copyTo​(java.nio.ByteBuffer target)
        Description copied from interface: BufferView
        Copies the contents of this BufferView to the given ByteBuffer.
        Specified by:
        copyTo in interface BufferView
        Parameters:
        target - The ByteBuffer to copy to. This buffer must have sufficient capacity to allow the entire contents of the BufferView to be written. If less needs to be copied, consider using BufferView.slice() to select a sub-range of this BufferView.
        Returns:
        The number of bytes copied.
      • getLength

        public int getLength()
        Description copied from interface: BufferView
        Gets a value representing the length of this BufferView.
        Specified by:
        getLength in interface BufferView
        Returns:
        The length.