Interface ByteDataBuffer

    • Method Detail

      • getByte

        byte getByte​(long index)
        Reads the byte at the given index.
        Parameters:
        index - the index from which the float will be read
        Returns:
        the byte at the given index
        Throws:
        IndexOutOfBoundsException - if index is negative or not smaller than the buffer size
      • setByte

        ByteDataBuffer setByte​(byte value,
                               long index)
        Writes the given byte into this buffer at the given index.
        Parameters:
        value - the byte to be written
        index - the index at which the value will be written
        Returns:
        this buffer
        Throws:
        IndexOutOfBoundsException - if index is negative or not smaller than the buffer size
        ReadOnlyBufferException - if this buffer is read-only
      • read

        default ByteDataBuffer read​(byte[] dst)
        Bulk get method, using byte arrays.

        This method transfers values from this buffer into the given destination array. If there are fewer values in the buffer than are required to satisfy the request, that is, if dst.length > size(), then no values are transferred and a BufferUnderflowException is thrown.

        Otherwise, this method copies n = dst.length values from this buffer into the given array.

        Parameters:
        dst - the array into which values are to be written
        Returns:
        this buffer
        Throws:
        BufferUnderflowException - if there are not enough values to copy from this buffer
      • read

        ByteDataBuffer read​(byte[] dst,
                            int offset,
                            int length)
        Bulk get method, using byte arrays.

        This method transfers values from this buffer into the given destination array. If there are fewer values in the buffer than are required to satisfy the request, that is, if length > size(), then no values are transferred and a BufferUnderflowException is thrown.

        Otherwise, this method copies n = length values from this buffer into the given array starting at the given offset.

        Parameters:
        dst - the array into which values are to be written
        offset - the offset within the array of the first value to be written; must be non-negative and no larger than dst.length
        length - the maximum number of values to be written to the given array; must be non-negative and no larger than dst.length - offset
        Returns:
        this buffer
        Throws:
        BufferUnderflowException - if there are fewer than length values remaining in this buffer
        IndexOutOfBoundsException - if the preconditions on the offset and length parameters do not hold
      • write

        default ByteDataBuffer write​(byte[] src)
        Bulk put method, using byte arrays.

        This method transfers the values in the given source array into this buffer. If there are more values in the source array than in this buffer, that is, if src.length > size(), then no values are transferred and a BufferOverflowException is thrown.

        Otherwise, this method copies n = src.length values from the given array.

        Parameters:
        src - the source array from which values are to be read
        Returns:
        this buffer
        Throws:
        BufferOverflowException - if there is insufficient space in this buffer for the values in the source array
        ReadOnlyBufferException - if this buffer is read-only
      • write

        ByteDataBuffer write​(byte[] src,
                             int offset,
                             int length)
        Bulk put method, using byte arrays.

        This method transfers the values in the given source array into this buffer. If there are more values in the source array than in this buffer, that is, if length > size(), then no values are transferred and a BufferOverflowException is thrown.

        Otherwise, this method copies n = length values from the given array into this buffer, starting at the given offset.

        Parameters:
        src - the source array from which values are to be read
        offset - the offset within the array of the first value to be read; must be non-negative and no larger than src.length
        length - the number of values to be read from the given array; must be non-negative and no larger than src.length - offset
        Returns:
        this buffer
        Throws:
        BufferOverflowException - if there is insufficient space in this buffer for the values in the source array
        IndexOutOfBoundsException - if the preconditions on the offset and length parameters do not hold
        ReadOnlyBufferException - if this buffer is read-only
      • asInts

        IntDataBuffer asInts()
        Return this byte buffer as a buffer of ints.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a IntDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • asShorts

        ShortDataBuffer asShorts()
        Return this byte buffer as a buffer of shorts.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a ShortDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • asLongs

        LongDataBuffer asLongs()
        Return this byte buffer as a buffer of longs.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a LongDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • asFloats

        FloatDataBuffer asFloats()
        Return this byte buffer as a buffer of floats.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a FloatDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • asDoubles

        DoubleDataBuffer asDoubles()
        Return this byte buffer as a buffer of doubles.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a DoubleDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • asBooleans

        BooleanDataBuffer asBooleans()
        Return this byte buffer as a buffer of booleans.

        The returned buffer provides a different view on the same memory as the original byte buffer, meaning that changing a value in one will affect the other.

        Returns:
        this buffer as a BooleanDataBuffer
        Throws:
        IllegalStateException - if this buffer cannot be converted
      • getObject

        default Byte getObject​(long index)
        Description copied from interface: DataBuffer
        Reads the value at the given index. Important: Usage of this method should be limited to buffers of non-primitive types or when the data type is not deterministically known by the caller. In any other case, prefer the usage of its primitive variant which will significantly improve performances (e.g. IntDataBuffer.getInt(idx)
        Specified by:
        getObject in interface DataBuffer<Byte>
        Parameters:
        index - the index from which the float will be read
        Returns:
        the value at the given index
      • setObject

        default ByteDataBuffer setObject​(Byte value,
                                         long index)
        Description copied from interface: DataBuffer
        Writes the given value into this buffer at the given index. Important: Usage of this method should be limited to buffers of non-primitive types or when the data type is not deterministically known by the caller. In any other case, prefer the usage of its primitive variant which will significantly improve performances (e.g. IntDataBuffer.setInt(idx)
        Specified by:
        setObject in interface DataBuffer<Byte>
        Parameters:
        value - the value to be written
        index - the index at which the value will be written
        Returns:
        this buffer
      • copyTo

        ByteDataBuffer copyTo​(DataBuffer<Byte> dst,
                              long size)
        Description copied from interface: DataBuffer
        Write the references of the objects in the source array into this buffer.

        If there are more values to copy than the destination buffer size, i.e. size > dst.size(), then no values are transferred and a BufferOverflowException is thrown. On the other hand, if there are more values to copy that the source buffer size, i.e. > src.size(), then a BufferUnderfloatException is thrown.

        Otherwise, this method copies n = size values from this buffer into the destination buffer.

        Specified by:
        copyTo in interface DataBuffer<Byte>
        Parameters:
        dst - the destination buffer into which values are copied; must not be this buffer
        size - number of values to copy to the destination buffer
        Returns:
        this buffer
      • offset

        default ByteDataBuffer offset​(long index)
        Description copied from interface: DataBuffer
        Creates a new buffer whose content is a shared subsequence of this buffer's content, starting at the given index.

        The index must not be greater than this buffer size. Changes to this buffer's content will be visible in the new buffer and vice versa. The new buffer will be read-only if, and only if, this buffer is read-only.

        This call is equivalent to slice(index, size() - index)

        Specified by:
        offset in interface DataBuffer<Byte>
        Parameters:
        index - index of the first value of the new buffer created, must not be greater than size()
        Returns:
        the new buffer
      • narrow

        default ByteDataBuffer narrow​(long size)
        Description copied from interface: DataBuffer
        Creates a new buffer whose content is a shared subsequence of this buffer's content, whose size is set to the given value.

        The new size must not be greater than this buffer size. Changes to this buffer's content will be visible in the new buffer and vice versa. The new buffer will be read-only if, and only if, this buffer is read-only.

        This call is equivalent to slice(0, size)

        Specified by:
        narrow in interface DataBuffer<Byte>
        Parameters:
        size - size of this new buffer
        Returns:
        the new buffer
      • slice

        ByteDataBuffer slice​(long index,
                             long size)
        Description copied from interface: DataBuffer
        Creates a new buffer whose content is a shared subsequence of this buffer's content, starting at the given index and of the given size.

        The index plus the new size must not be greater than this buffer size. Changes to this buffer's content will be visible in the new buffer and vice versa. The new buffer will be read-only if, and only if, this buffer is read-only.

        Specified by:
        slice in interface DataBuffer<Byte>
        Parameters:
        index - index of the first value of the new buffer created
        size - size of this new buffer, must not be greater than size()
        Returns:
        the new buffer
      • window

        default DataBufferWindow<ByteDataBuffer> window​(long size)
        Description copied from interface: DataBuffer
        Creates a DataBufferWindow that provides a partial view of this buffer.

        The created window has a fixed size and can "slide" along this buffer to provide different views of the data without allocating a new buffer instance, like DataBuffer.offset(long) does. This improves overall performance when this operation is repeated frequently. For example:

        
         IntDataBuffer bufferA = DataBuffers.ofInts(1024);
         // ... init buffer data
         IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);
        
         // Return the index of the first occurrence of bufferB in bufferA using a sliding window
         DataBufferWindow<IntDataBuffer> windowA = bufferA.window(4);
         for (int i = 0; i < bufferA.size() - bufferB.size(); ++i) {
             if (windowA.slideTo(i).buffer().equals(bufferB)) {
                 return i;
             }
         }
         

        The returned object is stateful and is not thread-safe.

        Specified by:
        window in interface DataBuffer<Byte>
        Parameters:
        size - size of the window
        Returns:
        a new window that starts at the index 0 of this buffer