Class ProtonSlicedBuffer

  • All Implemented Interfaces:
    java.lang.Comparable<ProtonBuffer>, ProtonBuffer

    public class ProtonSlicedBuffer
    extends ProtonAbstractBuffer
    Presents a sliced view of a ProtonAbstractBuffer. The slice wraps the target buffer with a given offset into that buffer and a capped max capacity that limits how far into the wrapped buffer the slice will read or write. A sliced buffer does not allow capacity changes and as such any call to alter the capacity will result in an UnsupportedOperationException.
    • Constructor Detail

      • ProtonSlicedBuffer

        protected ProtonSlicedBuffer​(ProtonAbstractBuffer buffer,
                                     int offset,
                                     int capacity)
        Creates a sliced view of the given ProtonByteBuffer.
        Parameters:
        buffer - The buffer that this slice is a view of.
        offset - The offset into the buffer where this view starts.
        capacity - The amount of the buffer that this view spans.
    • Method Detail

      • hasArray

        public boolean hasArray()
        Returns:
        true if this buffer has a backing byte array that can be accessed.
      • getArray

        public byte[] getArray()
        Description copied from interface: ProtonBuffer
        Returns the backing array for this ProtonBuffer instance if there is such an array or throws an exception if this ProtonBuffer implementation has no backing array.

        Changes to the returned array are visible to other users of this ProtonBuffer.

        Returns:
        the backing byte array for this ProtonBuffer.
      • getArrayOffset

        public int getArrayOffset()
        Returns:
        the offset of the first byte in the backing array belonging to this buffer.
      • capacity

        public int capacity()
        Returns:
        the number of bytes this buffer can currently contain.
      • capacity

        public ProtonBuffer capacity​(int newCapacity)
        Description copied from interface: ProtonBuffer
        Adjusts the capacity of this buffer. If the new capacity is less than the current capacity, the content of this buffer is truncated. If the new capacity is greater than the current capacity, the buffer is appended with unspecified data whose length is new capacity - current capacity.
        Parameters:
        newCapacity - the new maximum capacity value of this buffer.
        Returns:
        this buffer for using in call chaining.
      • duplicate

        public ProtonBuffer duplicate()
        Description copied from interface: ProtonBuffer
        Create a duplicate of this ProtonBuffer instance that shares the same backing data store and but maintains separate position index values. Changes to one buffer are visible in any of its duplicates. This method does not copy the read or write markers to the new buffer instance.
        Specified by:
        duplicate in interface ProtonBuffer
        Overrides:
        duplicate in class ProtonAbstractBuffer
        Returns:
        a new ProtonBuffer instance that shares the backing data as this one.
      • slice

        public ProtonBuffer slice​(int index,
                                  int length)
        Description copied from interface: ProtonBuffer
        Create a new ProtonBuffer whose contents are a subsequence of the contents of this ProtonBuffer.

        The starting point of the new buffer starts at given index into this buffer and spans the number of bytes given by the length. Changes to the contents of this buffer or to the produced slice buffer are visible in the other.

        Specified by:
        slice in interface ProtonBuffer
        Overrides:
        slice in class ProtonAbstractBuffer
        Parameters:
        index - The index in this buffer where the slice should begin.
        length - The number of bytes to make visible to the new buffer from this one.
        Returns:
        a new ProtonBuffer whose contents are a subsequence of this buffer.
      • copy

        public ProtonBuffer copy​(int index,
                                 int length)
        Description copied from interface: ProtonBuffer
        Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify the value returned from ProtonBuffer.getReadIndex() or ProtonBuffer.getWriteIndex() of this buffer.
        Specified by:
        copy in interface ProtonBuffer
        Specified by:
        copy in class ProtonAbstractBuffer
        Parameters:
        index - The index in this buffer where the copy should begin
        length - The number of bytes to copy to the new buffer from this one.
        Returns:
        a new ProtonBuffer instance containing the copied bytes.
      • toByteBuffer

        public java.nio.ByteBuffer toByteBuffer​(int index,
                                                int length)
        Description copied from interface: ProtonBuffer
        Returns a ByteBuffer that represents the given span of bytes from the readable portion of this buffer.

        This method should attempt to return a ByteBuffer that shares the backing data store with this buffer however if that is not possible it is permitted that the returned ByteBuffer contain a copy of the readable bytes of this ProtonBuffer.

        Specified by:
        toByteBuffer in interface ProtonBuffer
        Specified by:
        toByteBuffer in class ProtonAbstractBuffer
        Parameters:
        index - The starting index in this where the ByteBuffer view should begin.
        length - The number of bytes to include in the ByteBuffer view.
        Returns:
        a ByteBuffer that represents the given view of this buffers readable bytes.
      • getBoolean

        public boolean getBoolean​(int index)
        Description copied from interface: ProtonBuffer
        Gets a boolean from the specified index, this method will not modify the read or write index.
        Specified by:
        getBoolean in interface ProtonBuffer
        Overrides:
        getBoolean in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getByte

        public byte getByte​(int index)
        Description copied from interface: ProtonBuffer
        Gets a byte from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getUnsignedByte

        public short getUnsignedByte​(int index)
        Description copied from interface: ProtonBuffer
        Gets a unsigned byte from the specified index, this method will not modify the read or write index.
        Specified by:
        getUnsignedByte in interface ProtonBuffer
        Overrides:
        getUnsignedByte in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getChar

        public char getChar​(int index)
        Description copied from interface: ProtonBuffer
        Gets a 2-byte char from the specified index, this method will not modify the read or write index.
        Specified by:
        getChar in interface ProtonBuffer
        Overrides:
        getChar in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getShort

        public short getShort​(int index)
        Description copied from interface: ProtonBuffer
        Gets a short from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getUnsignedShort

        public int getUnsignedShort​(int index)
        Description copied from interface: ProtonBuffer
        Gets a unsigned short from the specified index, this method will not modify the read or write index.
        Specified by:
        getUnsignedShort in interface ProtonBuffer
        Overrides:
        getUnsignedShort in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getInt

        public int getInt​(int index)
        Description copied from interface: ProtonBuffer
        Gets a int from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getUnsignedInt

        public long getUnsignedInt​(int index)
        Description copied from interface: ProtonBuffer
        Gets a unsigned int from the specified index, this method will not modify the read or write index.
        Specified by:
        getUnsignedInt in interface ProtonBuffer
        Overrides:
        getUnsignedInt in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getLong

        public long getLong​(int index)
        Description copied from interface: ProtonBuffer
        Gets a long from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getFloat

        public float getFloat​(int index)
        Description copied from interface: ProtonBuffer
        Gets a float from the specified index, this method will not modify the read or write index.
        Specified by:
        getFloat in interface ProtonBuffer
        Overrides:
        getFloat in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getDouble

        public double getDouble​(int index)
        Description copied from interface: ProtonBuffer
        Gets a double from the specified index, this method will not modify the read or write index.
        Specified by:
        getDouble in interface ProtonBuffer
        Overrides:
        getDouble in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
      • getBytes

        public ProtonBuffer getBytes​(int index,
                                     ProtonBuffer dst,
                                     int dstIndex,
                                     int length)
        Description copied from interface: ProtonBuffer
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readIndex or writeIndex of both the source (i.e. this) and the destination.
        Parameters:
        index - The index into the buffer where the value should be read.
        dst - The buffer where the bytes read will be written to
        dstIndex - The offset into the destination where the write starts
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
      • getBytes

        public ProtonBuffer getBytes​(int index,
                                     byte[] dst)
        Description copied from interface: ProtonBuffer
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer
        Specified by:
        getBytes in interface ProtonBuffer
        Overrides:
        getBytes in class ProtonAbstractBuffer
        Parameters:
        index - The index into the buffer where the value should be read.
        dst - The buffer where the bytes read will be written to
        Returns:
        this buffer for chaining
      • getBytes

        public ProtonBuffer getBytes​(int index,
                                     byte[] dst,
                                     int offset,
                                     int length)
        Description copied from interface: ProtonBuffer
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify #getReadIndex() or #getWriteIndex() of this buffer.
        Parameters:
        index - The index into the buffer where the value should be read.
        dst - The buffer where the bytes read will be written to
        offset - the offset into the destination to begin writing the bytes.
        length - the number of bytes to transfer from this buffer to the target buffer.
        Returns:
        this buffer for chaining
      • getBytes

        public ProtonBuffer getBytes​(int index,
                                     java.nio.ByteBuffer destination)
        Description copied from interface: ProtonBuffer
        Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination's position reaches its limit. This method does not modify #getReadIndex() or #getWriteIndex() of this buffer while the destination's position will be increased.
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - The buffer where the bytes read will be written to
        Returns:
        this buffer for chaining
      • setByte

        public ProtonBuffer setByte​(int index,
                                    int value)
        Description copied from interface: ProtonBuffer
        Sets the byte value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setBoolean

        public ProtonBuffer setBoolean​(int index,
                                       boolean value)
        Description copied from interface: ProtonBuffer
        Sets the boolean value at the given write index in this buffer's backing data store.
        Specified by:
        setBoolean in interface ProtonBuffer
        Overrides:
        setBoolean in class ProtonAbstractBuffer
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setChar

        public ProtonBuffer setChar​(int index,
                                    int value)
        Description copied from interface: ProtonBuffer
        Sets the char value at the given write index in this buffer's backing data store.
        Specified by:
        setChar in interface ProtonBuffer
        Overrides:
        setChar in class ProtonAbstractBuffer
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setShort

        public ProtonBuffer setShort​(int index,
                                     int value)
        Description copied from interface: ProtonBuffer
        Sets the short value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setInt

        public ProtonBuffer setInt​(int index,
                                   int value)
        Description copied from interface: ProtonBuffer
        Sets the int value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setLong

        public ProtonBuffer setLong​(int index,
                                    long value)
        Description copied from interface: ProtonBuffer
        Sets the long value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setFloat

        public ProtonBuffer setFloat​(int index,
                                     float value)
        Description copied from interface: ProtonBuffer
        Sets the float value at the given write index in this buffer's backing data store.
        Specified by:
        setFloat in interface ProtonBuffer
        Overrides:
        setFloat in class ProtonAbstractBuffer
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setDouble

        public ProtonBuffer setDouble​(int index,
                                      double value)
        Description copied from interface: ProtonBuffer
        Sets the double value at the given write index in this buffer's backing data store.
        Specified by:
        setDouble in interface ProtonBuffer
        Overrides:
        setDouble in class ProtonAbstractBuffer
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
      • setBytes

        public ProtonBuffer setBytes​(int index,
                                     ProtonBuffer source,
                                     int sourceIndex,
                                     int length)
        Description copied from interface: ProtonBuffer
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of both the source (i.e. this) and the destination.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        sourceIndex - The offset into the source where the set begins.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
      • setBytes

        public ProtonBuffer setBytes​(int index,
                                     byte[] source)
        Description copied from interface: ProtonBuffer
        Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer.
        Specified by:
        setBytes in interface ProtonBuffer
        Overrides:
        setBytes in class ProtonAbstractBuffer
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining
      • setBytes

        public ProtonBuffer setBytes​(int index,
                                     byte[] src,
                                     int srcIndex,
                                     int length)
        Description copied from interface: ProtonBuffer
        Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer.
        Parameters:
        index - The index in this buffer where the write operation starts.
        src - The source buffer from which the bytes are read.
        srcIndex - The offset into the source where the set begins.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
      • setBytes

        public ProtonBuffer setBytes​(int index,
                                     java.nio.ByteBuffer source)
        Description copied from interface: ProtonBuffer
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer's position reaches its limit. This method does not modify readIndex or writeIndex of this buffer.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining