Interface Buffer

  • All Superinterfaces:
    BaseBuffer, BaseState
    All Known Subinterfaces:
    WritableBuffer

    public interface Buffer
    extends BaseBuffer
    Defines the read-only API for relative positional access to a resource.
    Author:
    Lee Rhodes
    • Method Detail

      • wrap

        static Buffer wrap​(ByteBuffer byteBuffer)
        Accesses the given ByteBuffer for read-only operations. The returned Buffer object has the same byte order, as the given ByteBuffer.
        Parameters:
        byteBuffer - the given ByteBuffer, must not be null.
        Returns:
        a new Buffer for read-only operations on the given ByteBuffer.
      • wrap

        static Buffer wrap​(ByteBuffer byteBuffer,
                           ByteOrder byteOrder)
        Accesses the given ByteBuffer for read-only operations. The returned Buffer object has the given byte order, ignoring the byte order of the given ByteBuffer.
        Parameters:
        byteBuffer - the given ByteBuffer, must not be null
        byteOrder - the byte order to be used, which may be independent of the byte order state of the given ByteBuffer
        Returns:
        a new Buffer for read-only operations on the given ByteBuffer.
      • duplicate

        Buffer duplicate()
        Returns a read-only duplicate view of this Buffer with the same but independent values of start, position and end.
        • Returned object's origin = this object's origin
        • Returned object's start = this object's start
        • Returned object's position = this object's position
        • Returned object's end = this object's end
        • Returned object's capacity = this object' capacityBytes
        • Returned object's start, position and end are mutable and independent of this object's start, position and end
        Returns:
        a read-only duplicate view of this Buffer with the same but independent values of start, position and end.
      • duplicate

        Buffer duplicate​(ByteOrder byteOrder)
        Returns a read-only duplicate view of this Buffer with the same but independent values of start, position and end, but with the specified byteOrder.
        • Returned object's origin = this object's origin
        • Returned object's start = this object's start
        • Returned object's position = this object's position
        • Returned object's end = this object's end
        • Returned object's capacity = this object' capacityBytes
        • Returned object's start, position and end are mutable and independent of this object's start, position and end
        Parameters:
        byteOrder - the given ByteOrder.
        Returns:
        a read-only duplicate view of this Buffer with the same but independent values of start, position and end.
      • region

        Buffer region()
        A region is a read-only view of this object.
        • Returned object's origin = this object's position
        • Returned object's start = 0
        • Returned object's position = 0
        • Returned object's end = this object's (end - position)
        • Returned object's capacity = this object's (end - position)
        • Returned object's start, position and end are mutable and independent of this object's start, position and end
        Returns:
        a new Buffer representing the defined region based on the current position and end.
      • region

        Buffer region​(long offsetBytes,
                      long capacityBytes,
                      ByteOrder byteOrder)
        A region is a read-only view of this object.
        • Returned object's origin = this objects' origin + offsetBytes
        • Returned object's start = 0
        • Returned object's position = 0
        • Returned object's end = capacityBytes
        • Returned object's capacity = capacityBytes
        • Returned object's start, position and end are mutable and independent of this object's start, position and end
        • Returned object's byte order = byteOrder
        Parameters:
        offsetBytes - the starting offset with respect to the origin of this WritableBuffer
        capacityBytes - the capacity of the returned region in bytes
        byteOrder - the given byte order
        Returns:
        a new Buffer representing the defined writable region based on the current position, end and byteOrder.
      • asMemory

        default Memory asMemory()
        Convert this Buffer to a Memory. The current start, position and end are ignored.
        Returns:
        Memory
      • asMemory

        Memory asMemory​(ByteOrder byteOrder)
        Convert this Buffer to a Memory with the given byte order. The current start, position and end are ignored.
        Parameters:
        byteOrder - the given byte order.
        Returns:
        Memory
      • getBoolean

        boolean getBoolean()
        Gets the boolean value at the current position. Increments the position by 1.
        Returns:
        the boolean at the current position
      • getBoolean

        boolean getBoolean​(long offsetBytes)
        Gets the boolean value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the boolean at the given offset
      • getBooleanArray

        void getBooleanArray​(boolean[] dstArray,
                             int dstOffsetBooleans,
                             int lengthBooleans)
        Gets the boolean array at the current position. Increments the position by lengthBooleans - dstOffsetBooleans.
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetBooleans - offset in array units
        lengthBooleans - number of array units to transfer
      • getByte

        byte getByte()
        Gets the byte value at the current position. Increments the position by Byte.BYTES.
        Returns:
        the byte at the current position
      • getByte

        byte getByte​(long offsetBytes)
        Gets the byte value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the byte at the given offset
      • getByteArray

        void getByteArray​(byte[] dstArray,
                          int dstOffsetBytes,
                          int lengthBytes)
        Gets the byte array at the current position. Increments the position by Byte.BYTES * (lengthBytes - dstOffsetBytes).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetBytes - offset in array units
        lengthBytes - number of array units to transfer
      • getChar

        char getChar()
        Gets the char value at the current position. Increments the position by Character.BYTES.
        Returns:
        the char at the current position
      • getChar

        char getChar​(long offsetBytes)
        Gets the char value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the char at the given offset
      • getCharArray

        void getCharArray​(char[] dstArray,
                          int dstOffsetChars,
                          int lengthChars)
        Gets the char array at the current position. Increments the position by Character.BYTES * (lengthChars - dstOffsetChars).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetChars - offset in array units
        lengthChars - number of array units to transfer
      • getDouble

        double getDouble()
        Gets the double value at the current position. Increments the position by Double.BYTES.
        Returns:
        the double at the current position
      • getDouble

        double getDouble​(long offsetBytes)
        Gets the double value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the double at the given offset
      • getDoubleArray

        void getDoubleArray​(double[] dstArray,
                            int dstOffsetDoubles,
                            int lengthDoubles)
        Gets the double array at the current position. Increments the position by Double.BYTES * (lengthDoubles - dstOffsetDoubles).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetDoubles - offset in array units
        lengthDoubles - number of array units to transfer
      • getFloat

        float getFloat()
        Gets the float value at the current position. Increments the position by Float.BYTES.
        Returns:
        the float at the current position
      • getFloat

        float getFloat​(long offsetBytes)
        Gets the float value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the float at the given offset
      • getFloatArray

        void getFloatArray​(float[] dstArray,
                           int dstOffsetFloats,
                           int lengthFloats)
        Gets the float array at the current position. Increments the position by Float.BYTES * (lengthFloats - dstOffsetFloats).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetFloats - offset in array units
        lengthFloats - number of array units to transfer
      • getInt

        int getInt()
        Gets the int value at the current position. Increments the position by Integer.BYTES.
        Returns:
        the int at the current position
      • getInt

        int getInt​(long offsetBytes)
        Gets the int value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the int at the given offset
      • getIntArray

        void getIntArray​(int[] dstArray,
                         int dstOffsetInts,
                         int lengthInts)
        Gets the int array at the current position. Increments the position by Integer.BYTES * (lengthInts - dstOffsetInts).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetInts - offset in array units
        lengthInts - number of array units to transfer
      • getLong

        long getLong()
        Gets the long value at the current position. Increments the position by Long.BYTES.
        Returns:
        the long at the current position
      • getLong

        long getLong​(long offsetBytes)
        Gets the long value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the long at the given offset
      • getLongArray

        void getLongArray​(long[] dstArray,
                          int dstOffsetLongs,
                          int lengthLongs)
        Gets the long array at the current position. Increments the position by Long.BYTES * (lengthLongs - dstOffsetLongs).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetLongs - offset in array units
        lengthLongs - number of array units to transfer
      • getShort

        short getShort()
        Gets the short value at the current position. Increments the position by Short.BYTES.
        Returns:
        the short at the current position
      • getShort

        short getShort​(long offsetBytes)
        Gets the short value at the given offset. This does not change the position.
        Parameters:
        offsetBytes - offset bytes relative to this Memory start
        Returns:
        the short at the given offset
      • getShortArray

        void getShortArray​(short[] dstArray,
                           int dstOffsetShorts,
                           int lengthShorts)
        Gets the short array at the current position. Increments the position by Short.BYTES * (lengthShorts - dstOffsetShorts).
        Parameters:
        dstArray - The preallocated destination array.
        dstOffsetShorts - offset in array units
        lengthShorts - number of array units to transfer
      • compareTo

        int compareTo​(long thisOffsetBytes,
                      long thisLengthBytes,
                      Buffer that,
                      long thatOffsetBytes,
                      long thatLengthBytes)
        Compares the bytes of this Buffer to that Buffer. This uses absolute offsets not the start, position and end. Returns (this < that) ? (some negative value) : (this > that) ? (some positive value) : 0;. If all bytes are equal up to the shorter of the two lengths, the shorter length is considered to be less than the other.
        Parameters:
        thisOffsetBytes - the starting offset for this Buffer
        thisLengthBytes - the length of the region to compare from this Buffer
        that - the other Buffer to compare with
        thatOffsetBytes - the starting offset for that Buffer
        thatLengthBytes - the length of the region to compare from that Buffer
        Returns:
        (this < that) ? (some negative value) : (this > that) ? (some positive value) : 0;