Class Netty4ToProtonBufferAdapter

java.lang.Object
org.apache.qpid.protonj2.resource.SharedResource<ProtonBuffer>
org.apache.qpid.protonj2.buffer.netty.Netty4ToProtonBufferAdapter
All Implemented Interfaces:
AutoCloseable, Comparable<ProtonBuffer>, ProtonBuffer, ProtonBufferAccessors, ProtonBufferComponent, ProtonBufferComponentAccessor, Resource<ProtonBuffer>

public final class Netty4ToProtonBufferAdapter extends SharedResource<ProtonBuffer> implements ProtonBuffer, ProtonBufferComponentAccessor, ProtonBufferComponent
Wrapper class for Netty 4 ByteBuf instances which provides a generic way for proton to interact with Netty 4 buffers.
  • Constructor Details

  • Method Details

    • allocator

      public Netty4ProtonBufferAllocator allocator()
    • unwrapAndRelease

      public io.netty.buffer.ByteBuf unwrapAndRelease()
      Unwraps the managed Netty ByteBuf and releases it from ownership by this ProtonBuffer instance. This effectively closes the ProtonBuffer while also safely handing off the managed Netty resource.
      Returns:
      the managed Netty ByteBuf
    • unwrap

      public io.netty.buffer.ByteBuf unwrap()
      Description copied from interface: ProtonBuffer
      Return the underlying buffer object that backs this ProtonBuffer instance, or self if there is no backing object. This method should be overridden in buffer abstraction when access to the underlying backing store is needed such as when wrapping pooled resources that need explicit release calls.
      Specified by:
      unwrap in interface ProtonBuffer
      Specified by:
      unwrap in interface ProtonBufferComponent
      Returns:
      an underlying buffer object or other backing store for this buffer.
    • isComposite

      public boolean isComposite()
      Specified by:
      isComposite in interface ProtonBuffer
      Returns:
      true if the buffer is backed by one or more ProtonBuffer instances.
    • componentCount

      public int componentCount()
      Description copied from interface: ProtonBuffer
      Returns the number of constituent buffer components that are contained in this buffer instance which for a non-composite buffer will always be one (namely itself). For a composite buffer this count is the total count of all buffers mapped to the composite.
      Specified by:
      componentCount in interface ProtonBuffer
      Returns:
      the number of buffers managed by this ProtonBuffer instance.
    • readableComponentCount

      public int readableComponentCount()
      Description copied from interface: ProtonBuffer
      Returns the number of readable constituent buffer components that are contained in this buffer instance which for a non-composite buffer will always be zero or one (namely itself). For a composite buffer this count is the total count of all buffers mapped to the composite which are readable.
      Specified by:
      readableComponentCount in interface ProtonBuffer
      Returns:
      the number of readable buffers managed by this ProtonBuffer instance.
    • writableComponentCount

      public int writableComponentCount()
      Description copied from interface: ProtonBuffer
      Returns the number of writable constituent buffer components that are contained in this buffer instance which for a non-composite buffer will always be zero or one (namely itself). For a composite buffer this count is the total count of all buffers mapped to the composite which are writable.
      Specified by:
      writableComponentCount in interface ProtonBuffer
      Returns:
      the number of writable buffer components managed by this ProtonBuffer instance.
    • isReadOnly

      public boolean isReadOnly()
      Specified by:
      isReadOnly in interface ProtonBuffer
      Returns:
      whether this buffer instance is read-only or not.
    • isDirect

      public boolean isDirect()
      Specified by:
      isDirect in interface ProtonBuffer
      Returns:
      true if the buffer is backed by native memory.
    • convertToReadOnly

      public ProtonBuffer convertToReadOnly()
      Description copied from interface: ProtonBuffer
      Converts this buffer instance to a read-only buffer, any write operation that is performed on this buffer following this call will fail. A buffer cannot be made writable after this call.
      Specified by:
      convertToReadOnly in interface ProtonBuffer
      Returns:
      this buffer for use in chaining.
    • getReadOffset

      public int getReadOffset()
      Specified by:
      getReadOffset in interface ProtonBuffer
      Returns:
      the current value of the read offset for this buffer.
    • setReadOffset

      public ProtonBuffer setReadOffset(int value)
      Description copied from interface: ProtonBuffer
      Sets the read offset for this buffer.
      Specified by:
      setReadOffset in interface ProtonBuffer
      Parameters:
      value - The offset into the buffer where the read offset should be positioned.
      Returns:
      this buffer for use in chaining.
    • getReadableBytes

      public int getReadableBytes()
      Description copied from interface: ProtonBufferComponent
      Returns the number of readable bytes in the buffer safely regards of the actual memory backing this component.
      Specified by:
      getReadableBytes in interface ProtonBuffer
      Specified by:
      getReadableBytes in interface ProtonBufferComponent
      Returns:
      the number of bytes available for reading from this buffer.
    • getWriteOffset

      public int getWriteOffset()
      Specified by:
      getWriteOffset in interface ProtonBuffer
      Returns:
      the current value of the write offset for this buffer.
    • setWriteOffset

      public ProtonBuffer setWriteOffset(int value)
      Description copied from interface: ProtonBuffer
      Sets the write offset for this buffer.
      Specified by:
      setWriteOffset in interface ProtonBuffer
      Parameters:
      value - The offset into the buffer where the write offset should be positioned.
      Returns:
      this buffer for use in chaining.
    • getWritableBytes

      public int getWritableBytes()
      Description copied from interface: ProtonBufferComponent
      Returns the number of writable bytes in the buffer safely regards of the actual memory backing this component.
      Specified by:
      getWritableBytes in interface ProtonBuffer
      Specified by:
      getWritableBytes in interface ProtonBufferComponent
      Returns:
      the number of bytes that can be written to this buffer before the limit is hit.
    • capacity

      public int capacity()
      Specified by:
      capacity in interface ProtonBuffer
      Returns:
      the number of bytes this buffer can currently contain.
    • implicitGrowthLimit

      public int implicitGrowthLimit()
      Description copied from interface: ProtonBuffer
      Returns the limit assigned to this buffer if one was set which controls how large the capacity of the buffer can grow implicitly via write calls. Once the limit is hit any write call that requires more capacity than is currently available will throw an exception instead of allocating more space.

      When a capacity limit is hit the buffer can still be enlarged but must be done explicitly via the ensure writable APIs.

      Specified by:
      implicitGrowthLimit in interface ProtonBuffer
      Returns:
      the number of bytes this buffer can currently grow to..
    • implicitGrowthLimit

      public ProtonBuffer implicitGrowthLimit(int limit)
      Description copied from interface: ProtonBuffer
      Configures the limit assigned to this buffer if one was set which controls how large the capacity of the buffer can grow implicitly via write calls. Once the limit is hit any write call that requires more capacity than is currently available will throw an exception instead of allocating more space.

      When a capacity limit is hit the buffer can still be enlarged but must be done explicitly via the ensure writable APIs.

      The growth limit set applies only to this buffer instance and is not carried over to a copied buffer of the split buffer created from any of the buffer split calls.

      Specified by:
      implicitGrowthLimit in interface ProtonBuffer
      Parameters:
      limit - The limit to assign as the maximum capacity this buffer can grow
      Returns:
      this buffer for using in call chaining.
    • fill

      public ProtonBuffer fill(byte value)
      Description copied from interface: ProtonBuffer
      Assigns the given value to every byte in the buffer without respect for the buffer read or write offsets.
      Specified by:
      fill in interface ProtonBuffer
      Parameters:
      value - The byte value to assign each byte in this buffer.
      Returns:
      this ProtonBuffer for chaining.
    • compact

      public ProtonBuffer compact()
      Description copied from interface: ProtonBuffer
      Moves the readable portion of the buffer to the beginning of the underlying buffer storage and possibly makes additional bytes available for writes before a buffer expansion would occur via an ProtonBuffer.ensureWritable(int) call.
      Specified by:
      compact in interface ProtonBuffer
      Returns:
      this buffer for using in call chaining.
    • copyInto

      public void copyInto(int offset, byte[] destination, int destOffset, int length)
      Description copied from interface: ProtonBuffer
      Copies the given number of bytes from this buffer into the specified target byte array starting at the given offset into this buffer. The copied region is written into the target starting at the given offset and continues for the specified length of elements.
      Specified by:
      copyInto in interface ProtonBuffer
      Parameters:
      offset - The offset into this buffer where the copy begins from.
      destination - The destination byte array where the copied bytes are written.
      destOffset - The offset into the destination to begin writing the copied bytes.
      length - The number of bytes to copy into the destination.
    • copyInto

      public void copyInto(int offset, ByteBuffer destination, int destOffset, int length)
      Description copied from interface: ProtonBuffer
      Copies the given number of bytes from this buffer into the specified target ByteBuffer starting at the given offset into this buffer. The copied region is written into the target starting at the given offset and continues for the specified length of elements.
      Specified by:
      copyInto in interface ProtonBuffer
      Parameters:
      offset - The offset into this buffer where the copy begins from.
      destination - The destination ByteBuffer where the copied bytes are written.
      destOffset - The offset into the destination to begin writing the copied bytes.
      length - The number of bytes to copy into the destination.
    • copyInto

      public void copyInto(int offset, ProtonBuffer destination, int destOffset, int length)
      Description copied from interface: ProtonBuffer
      Copies the given number of bytes from this buffer into the specified target ProtonBuffer starting at the given offset into this buffer. The copied region is written into the target starting at the given offset and continues for the specified length of elements.
      Specified by:
      copyInto in interface ProtonBuffer
      Parameters:
      offset - The offset into this buffer where the copy begins from.
      destination - The destination ProtonBuffer where the copied bytes are written.
      destOffset - The offset into the destination to begin writing the copied bytes.
      length - The number of bytes to copy into the destination.
    • writeBytes

      public ProtonBuffer writeBytes(byte[] source, int offset, int length)
      Description copied from interface: ProtonBuffer
      Writes into this buffer, the given number of bytes from the byte array. This updates the ProtonBuffer.getWriteOffset() of this buffer by the length argument. Implementations are recommended to specialize this method and provide a more efficient version.
      Specified by:
      writeBytes in interface ProtonBuffer
      Parameters:
      source - The byte array to read from.
      offset - The position in the source from where bytes should be written to this buffer.
      length - The number of bytes to copy.
      Returns:
      this buffer for using in call chaining.
    • writeBytes

      public ProtonBuffer writeBytes(ByteBuffer source)
      Description copied from interface: ProtonBuffer
      Writes into this buffer from the source ByteBuffer. This updates the ProtonBuffer.getWriteOffset() of this buffer and also the position of the source ByteBuffer. Implementations are recommended to specialize this method and provide a more efficient version.

      Note: the behavior is undefined if the given ByteBuffer is an alias for the memory in this buffer.

      Specified by:
      writeBytes in interface ProtonBuffer
      Parameters:
      source - The ByteBuffer to read from.
      Returns:
      this buffer for using in call chaining.
    • writeBytes

      public ProtonBuffer writeBytes(ProtonBuffer source)
      Description copied from interface: ProtonBuffer
      Writes into this buffer, all the readable bytes from the given buffer. This updates the ProtonBuffer.getWriteOffset() of this buffer, and the ProtonBuffer.getReadOffset() of the given buffer.
      Specified by:
      writeBytes in interface ProtonBuffer
      Parameters:
      source - The buffer to read from.
      Returns:
      This buffer.
    • readBytes

      public ProtonBuffer readBytes(ByteBuffer destination)
      Description copied from interface: ProtonBuffer
      Read from this buffer, into the destination ByteBuffer This updates the read offset of this buffer and also the position of the destination ByteBuffer.

      Note: the behavior is undefined if the given ByteBuffer is an alias for the memory in this buffer.

      Specified by:
      readBytes in interface ProtonBuffer
      Parameters:
      destination - The ByteBuffer to write into.
      Returns:
      this buffer for using in call chaining.
    • readBytes

      public ProtonBuffer readBytes(byte[] destination, int offset, int length)
      Description copied from interface: ProtonBuffer
      Read from this buffer, into the destination array, the given number of bytes. This updates the read offset of this buffer by the length argument.
      Specified by:
      readBytes in interface ProtonBuffer
      Parameters:
      destination - The byte array to write into.
      offset - Position in the destination to where bytes should be written from this buffer.
      length - The number of bytes to copy.
      Returns:
      This buffer.
    • ensureWritable

      public ProtonBuffer ensureWritable(int size, int minimumGrowth, boolean allowCompaction) throws IndexOutOfBoundsException, IllegalArgumentException
      Description copied from interface: ProtonBuffer
      Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity. This method will not alter the write offset but may change the value returned from the capacity method if new buffer space is allocated. If the buffer cannot create the required number of byte via compaction then the buffer will be grown by either the requested number of bytes or by the minimum allowed value specified.

      This method allows buffer compaction as a strategy to reclaim already read space to make room for additional writes. This implies that a composite buffer can reuse already read buffers to extend the buffer's writable space by moving them to the end of the set of composite buffers and reseting their index values to make them fully writable.

      Specified by:
      ensureWritable in interface ProtonBuffer
      Parameters:
      size - The number of bytes beyond the current write index needed.
      minimumGrowth - The minimum number of byte that the buffer can grow by
      allowCompaction - Can the buffer use compaction as a strategy to create more writable space.
      Returns:
      this buffer for using in call chaining.
      Throws:
      IndexOutOfBoundsException - if the amount given would result in the buffer exceeding the maximum capacity for this buffer.
      IllegalArgumentException - if the amount given is less than zero.
    • copy

      public ProtonBuffer copy(int index, int length, boolean readOnly) throws IllegalArgumentException
      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.getReadOffset() or ProtonBuffer.getWriteOffset() of this buffer.

      If this buffer is read-only and the requested copy is also read-only the copy may be shallow and allow each buffer to share the same memory.

      Specified by:
      copy in interface ProtonBuffer
      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.
      readOnly - Should the returned buffer be read-only or not.
      Returns:
      a new ProtonBuffer instance containing the copied bytes.
      Throws:
      IllegalArgumentException - if the offset or length given are out of bounds.
    • split

      public ProtonBuffer split(int splitOffset)
      Description copied from interface: ProtonBuffer
      Splits this buffer at the given offset.

      This creates two independent buffers that can manage differing views of the same memory region or in the case of a composite buffer two buffers that take ownership of differing sections of the composite buffer range. For a composite buffer a single buffer might be split if the offset lays within its bounds but all others buffers are divided amongst the two split buffers.

      If this buffer is a read-only buffer then the resulting split buffer will also be read-only.

      Specified by:
      split in interface ProtonBuffer
      Parameters:
      splitOffset - The offset in this buffer where the split should occur.
      Returns:
      A new buffer that owns the memory spanning the range given.
    • toString

      public String toString(Charset charset)
      Description copied from interface: ProtonBuffer
      Returns a String created from the buffer's underlying bytes using the specified Charset for the newly created String.
      Specified by:
      toString in interface ProtonBuffer
      Parameters:
      charset - the Charset to use to construct the new string.
      Returns:
      a string created from the buffer's underlying bytes using the given Charset.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ProtonBuffer buffer)
      Description copied from interface: ProtonBuffer
      Compares the remaining content of the current buffer with the remaining content of the given buffer, which must not be null. Each byte is compared in turn as an unsigned value, returning upon the first difference. If no difference is found before the end of one buffer, the shorter buffer is considered less than the other, or else if the same length then they are considered equal.
      Specified by:
      compareTo in interface Comparable<ProtonBuffer>
      Specified by:
      compareTo in interface ProtonBuffer
      Parameters:
      buffer - The buffer to compare to this instance.
      Returns:
      a negative, zero, or positive integer when this buffer is less than, equal to, or greater than the given buffer.
      See Also:
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getByte

      public byte getByte(int index)
      Description copied from interface: ProtonBufferAccessors
      Reads a single byte at the given index and returns it without modification to the target buffer read offset.
      Specified by:
      getByte in interface ProtonBufferAccessors
      Parameters:
      index - The index into the buffer where the value should be read.
      Returns:
      the value read from the given index.
    • getUnsignedByte

      public int getUnsignedByte(int index)
      Description copied from interface: ProtonBufferAccessors
      Gets a unsigned byte from the specified index, this method will not modify the read or write index.
      Specified by:
      getUnsignedByte in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Gets a 2-byte char from the specified index, this method will not modify the read or write index.
      Specified by:
      getChar in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Gets a short from the specified index, this method will not modify the read or write index.
      Specified by:
      getShort in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Gets a int from the specified index, this method will not modify the read or write index.
      Specified by:
      getInt in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Gets a long from the specified index, this method will not modify the read or write index.
      Specified by:
      getLong in interface ProtonBufferAccessors
      Parameters:
      index - The index into the buffer where the value should be read.
      Returns:
      the value read from the given index.
    • setByte

      public ProtonBuffer setByte(int index, byte value)
      Description copied from interface: ProtonBufferAccessors
      Sets the byte value at the given write index in this buffer's backing data store.
      Specified by:
      setByte in interface ProtonBufferAccessors
      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, char value)
      Description copied from interface: ProtonBufferAccessors
      Sets the char value at the given write index in this buffer's backing data store.
      Specified by:
      setChar in interface ProtonBufferAccessors
      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, short value)
      Description copied from interface: ProtonBufferAccessors
      Sets the short value at the given write index in this buffer's backing data store.
      Specified by:
      setShort in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Sets the int value at the given write index in this buffer's backing data store.
      Specified by:
      setInt in interface ProtonBufferAccessors
      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: ProtonBufferAccessors
      Sets the long value at the given write index in this buffer's backing data store.
      Specified by:
      setLong in interface ProtonBufferAccessors
      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.
    • readByte

      public byte readByte()
      Description copied from interface: ProtonBufferAccessors
      Reads one byte from the buffer and advances the read index by one.
      Specified by:
      readByte in interface ProtonBufferAccessors
      Returns:
      a single byte from the ProtonBuffer.
    • readChar

      public char readChar()
      Description copied from interface: ProtonBufferAccessors
      Reads a character value from the buffer and advances the read index by four.
      Specified by:
      readChar in interface ProtonBufferAccessors
      Returns:
      char value read from the buffer.
    • readShort

      public short readShort()
      Description copied from interface: ProtonBufferAccessors
      Reads a short value from the buffer and advances the read index by two.
      Specified by:
      readShort in interface ProtonBufferAccessors
      Returns:
      short value read from the buffer.
    • readInt

      public int readInt()
      Description copied from interface: ProtonBufferAccessors
      Reads a integer value from the buffer and advances the read index by four.
      Specified by:
      readInt in interface ProtonBufferAccessors
      Returns:
      integer value read from the buffer.
    • readLong

      public long readLong()
      Description copied from interface: ProtonBufferAccessors
      Reads a long value from the buffer and advances the read index by eight.
      Specified by:
      readLong in interface ProtonBufferAccessors
      Returns:
      long value read from the buffer.
    • writeByte

      public ProtonBuffer writeByte(byte value)
      Description copied from interface: ProtonBufferAccessors
      Writes a single byte to the buffer and advances the write index by one.
      Specified by:
      writeByte in interface ProtonBufferAccessors
      Parameters:
      value - The byte to write into the buffer.
      Returns:
      this ProtonBuffer for chaining.
    • writeChar

      public ProtonBuffer writeChar(char value)
      Description copied from interface: ProtonBufferAccessors
      Writes a single character to the buffer and advances the write index by four.
      Specified by:
      writeChar in interface ProtonBufferAccessors
      Parameters:
      value - The char to write into the buffer.
      Returns:
      this ProtonBuffer for chaining.
    • writeShort

      public ProtonBuffer writeShort(short value)
      Description copied from interface: ProtonBufferAccessors
      Writes a single short to the buffer and advances the write index by two.
      Specified by:
      writeShort in interface ProtonBufferAccessors
      Parameters:
      value - The short to write into the buffer.
      Returns:
      this ProtonBuffer for chaining.
    • writeInt

      public ProtonBuffer writeInt(int value)
      Description copied from interface: ProtonBufferAccessors
      Writes a single integer to the buffer and advances the write index by four.
      Specified by:
      writeInt in interface ProtonBufferAccessors
      Parameters:
      value - The integer to write into the buffer.
      Returns:
      this ProtonBuffer for chaining.
    • writeLong

      public ProtonBuffer writeLong(long value)
      Description copied from interface: ProtonBufferAccessors
      Writes a single long to the buffer and advances the write index by eight.
      Specified by:
      writeLong in interface ProtonBufferAccessors
      Parameters:
      value - The long to write into the buffer.
      Returns:
      this ProtonBuffer for chaining.
    • transferTo

      public int transferTo(WritableByteChannel channel, int length) throws IOException
      Description copied from interface: ProtonBuffer
      Read from this buffer and write to the given channel.

      The number of bytes actually written to the channel are returned. No more than the given length of bytes, or the number of readable bytes, will be written to the channel, whichever is smaller. A channel that has a position marker, will be advanced by the number of bytes written. The read offset of this buffer will also be advanced by the number of bytes written.

      Specified by:
      transferTo in interface ProtonBuffer
      Parameters:
      channel - The channel to write to.
      length - The maximum number of bytes to write.
      Returns:
      The actual number of bytes written, possibly zero.
      Throws:
      IOException - If the write-operation on the channel failed for some reason.
    • transferFrom

      public int transferFrom(ReadableByteChannel channel, int length) throws IOException
      Description copied from interface: ProtonBuffer
      Reads a sequence of bytes from the given channel into this buffer.

      The method reads a given amount of bytes from the provided channel and returns the number of bytes actually read which can be zero or -1 if the channel has reached the end of stream state.

      The length value given is a maximum limit however the code will adjust this if the number of writable bytes in this buffer is smaller (or zero) and the result will indicate how many bytes where actually read. The write offset of this buffer will be advanced by the number of bytes read from the buffer as will the channel position index if one exists.

      Specified by:
      transferFrom in interface ProtonBuffer
      Parameters:
      channel - The readable byte channel where the bytes are read
      length - The maximum number of bytes to read from the channel
      Returns:
      The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
      Throws:
      IOException - if the read operation fails
    • transferFrom

      public int transferFrom(FileChannel channel, long position, int length) throws IOException
      Description copied from interface: ProtonBuffer
      Reads a sequence of bytes from the given channel into this buffer.

      The method reads a given amount of bytes from the provided channel and returns the number of bytes actually read which can be zero or -1 if the channel has reached the end of stream state.

      The length value given is a maximum limit however the code will adjust this if the number of writable bytes in this buffer is smaller (or zero) and the result will indicate how many bytes where actually read. The write offset of this buffer will be advanced by the number of bytes read from the buffer, the channel will not have its position modified.

      Specified by:
      transferFrom in interface ProtonBuffer
      Parameters:
      channel - The File channel where the bytes are read
      position - The position in the channel where the read should begin
      length - The maximum number of bytes to read from the channel
      Returns:
      The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
      Throws:
      IOException - if the read operation fails
    • componentAccessor

      public ProtonBufferComponentAccessor componentAccessor()
      Description copied from interface: ProtonBuffer
      Returns a component access object that can be used to gain access to the constituent buffer components for use in IO operations or other lower level buffer operations that need to work on single compoents.

      The general usage of the component access object should be within a try-with-resource block as follows:

      
         try (ProtonBufferComponentAccessor accessor = buffer.componentAccessor()) {
            for (ProtonBufferComponent component : accessor.readableComponents()) {
               // Access logic here....
            }
         }
       
      Specified by:
      componentAccessor in interface ProtonBuffer
      Returns:
      a component access object instance used to view the buffer internal components
    • first

      public ProtonBufferComponent first()
      Description copied from interface: ProtonBufferComponentAccessor
      Returns the first component that this access object provides which resets the iteration state to the beginning.
      Specified by:
      first in interface ProtonBufferComponentAccessor
      Returns:
      the first component in the sequence of ProtonBufferComponent instance.
    • next

      public ProtonBufferComponent next()
      Description copied from interface: ProtonBufferComponentAccessor
      Returns the next component that this access object provides which can be null if either the first method has never been called or the access of components has reached the end of the chain of buffer components that this access object is assigned to.
      Specified by:
      next in interface ProtonBufferComponentAccessor
      Returns:
      the first component in the sequence of ProtonBufferComponent instance.
    • hasReadbleArray

      public boolean hasReadbleArray()
      Specified by:
      hasReadbleArray in interface ProtonBufferComponent
      Returns:
      true if the component is backed by a byte array that has a readable portion.
    • advanceReadOffset

      public Netty4ToProtonBufferAdapter advanceReadOffset(int amount)
      Description copied from interface: ProtonBuffer
      Adjusts the current ProtonBuffer.getReadOffset() of this buffer by the specified length.
      Specified by:
      advanceReadOffset in interface ProtonBuffer
      Specified by:
      advanceReadOffset in interface ProtonBufferComponent
      Parameters:
      amount - the number of bytes to advance the read offset by.
      Returns:
      this ProtonBuffer for chaining.
    • getReadableArray

      public byte[] getReadableArray()
      Description copied from interface: ProtonBufferComponent
      Returns the readable array if one exists or throws an exception.
      Specified by:
      getReadableArray in interface ProtonBufferComponent
      Returns:
      the readable array that backs this buffer component.
    • getReadableArrayOffset

      public int getReadableArrayOffset()
      Specified by:
      getReadableArrayOffset in interface ProtonBufferComponent
      Returns:
      the offset into the readable array where the readable bytes begin.
    • getReadableArrayLength

      public int getReadableArrayLength()
      Specified by:
      getReadableArrayLength in interface ProtonBufferComponent
      Returns:
      the length of the readable array from the offset that is owned by this component..
    • getReadableBuffer

      public ByteBuffer getReadableBuffer()
      Description copied from interface: ProtonBufferComponent
      Returns the readable array if one exists or throws an exception.
      Specified by:
      getReadableBuffer in interface ProtonBufferComponent
      Returns:
      the readable array that backs this buffer component.
    • advanceWriteOffset

      public Netty4ToProtonBufferAdapter advanceWriteOffset(int amount)
      Description copied from interface: ProtonBuffer
      Adjusts the current ProtonBuffer.getWriteOffset() of this buffer by the specified length.
      Specified by:
      advanceWriteOffset in interface ProtonBuffer
      Specified by:
      advanceWriteOffset in interface ProtonBufferComponent
      Parameters:
      amount - the number of bytes to advance the write offset by.
      Returns:
      this ProtonBuffer for chaining.
    • hasWritableArray

      public boolean hasWritableArray()
      Specified by:
      hasWritableArray in interface ProtonBufferComponent
      Returns:
      true if the component is backed by a byte array that has writable bytes.
    • getWritableArray

      public byte[] getWritableArray()
      Description copied from interface: ProtonBufferComponent
      Returns the writable array if one exists or throws an exception.
      Specified by:
      getWritableArray in interface ProtonBufferComponent
      Returns:
      the writable array that backs this buffer component.
    • getWritableArrayOffset

      public int getWritableArrayOffset()
      Specified by:
      getWritableArrayOffset in interface ProtonBufferComponent
      Returns:
      the offset into the writable array where the writable bytes begin.
    • getWritableArrayLength

      public int getWritableArrayLength()
      Specified by:
      getWritableArrayLength in interface ProtonBufferComponent
      Returns:
      the length of the writable array from the offset that is owned by this component..
    • getWritableBuffer

      public ByteBuffer getWritableBuffer()
      Description copied from interface: ProtonBufferComponent
      Returns the writable ByteBuffer if one exists or throws an exception.
      Specified by:
      getWritableBuffer in interface ProtonBufferComponent
      Returns:
      the writable buffer that backs this buffer component.
    • getNativeAddress

      public long getNativeAddress()
      Description copied from interface: ProtonBufferComponent
      Gets the native address of the backing buffer if one exists otherwise returns 0.

      The returned address is the base address for the memory region that back this buffer which should not be used for reads and write as the backing region could be larger and not all portions of the backing region might be owned by this buffer component. The caller should use the methods ProtonBufferComponent.getNativeReadAddress() and ProtonBufferComponent.getNativeWriteAddress() which each use this method to compute where these value actually fall in the native memory region.

      Specified by:
      getNativeAddress in interface ProtonBufferComponent
      Returns:
      The native memory address for the region backing this buffer, if any, otherwise 0.
    • getNativeReadAddress

      public long getNativeReadAddress()
      Description copied from interface: ProtonBufferComponent
      Gets the native address where reads from this buffer component should start.
      Specified by:
      getNativeReadAddress in interface ProtonBufferComponent
      Returns:
      The native memory address where reads start, if any, otherwise 0.
    • getNativeWriteAddress

      public long getNativeWriteAddress()
      Description copied from interface: ProtonBufferComponent
      Gets the native address where write to this buffer component should start.
      Specified by:
      getNativeWriteAddress in interface ProtonBufferComponent
      Returns:
      The native memory address where writing should start, if any, otherwise 0.
    • bufferIterator

      public ProtonBufferIterator bufferIterator(int offset, int length)
      Description copied from interface: ProtonBuffer
      Creates and returns a new ProtonBufferIterator that iterates from the given offset and continues until specified number of bytes has been traversed. The source buffer read and write offsets are not modified by an iterator instance.

      The caller must ensure that the source buffer lifetime extends beyond the lifetime of the returned ProtonBufferIterator.

      Specified by:
      bufferIterator in interface ProtonBuffer
      Parameters:
      offset - The offset into the buffer where iteration begins
      length - The number of bytes to iterate over.
      Returns:
      a new buffer iterator that iterates over the readable bytes.
    • bufferIterator

      public ProtonBufferIterator bufferIterator()
      Description copied from interface: ProtonBuffer
      Creates and returns a new ProtonBufferIterator that iterates from the current read offset and continues until all readable bytes have been traversed. The source buffer read and write offsets are not modified by an iterator instance.

      The caller must ensure that the source buffer lifetime extends beyond the lifetime of the returned ProtonBufferIterator.

      Specified by:
      bufferIterator in interface ProtonBuffer
      Specified by:
      bufferIterator in interface ProtonBufferComponent
      Returns:
      a new buffer iterator that iterates over the readable bytes.
    • bufferReverseIterator

      public ProtonBufferIterator bufferReverseIterator(int offset, int length)
      Description copied from interface: ProtonBuffer
      Creates and returns a new ProtonBufferIterator that reverse iterates from the given offset and continues until specified number of bytes has been traversed. The source buffer read and write offsets are not modified by an iterator instance.

      The caller must ensure that the source buffer lifetime extends beyond the lifetime of the returned ProtonBufferIterator.

      Specified by:
      bufferReverseIterator in interface ProtonBuffer
      Parameters:
      offset - The offset into the buffer where iteration begins
      length - The number of bytes to iterate over.
      Returns:
      a new buffer iterator that iterates over the readable bytes.
    • indexOf

      public int indexOf(byte needle, int offset, int length)
      Description copied from interface: ProtonBuffer
      Starting from the given offset into this buffer, find the next offset (index) in the buffer where the given value is located or -1 if the value is not found by the time the specified number of bytes has been searched. This method does not affect the read or write offset and can be called from any point in the buffer regardless of the current read or write offsets. The search bounds are that of the buffer's readable bytes meaning that the starting office cannot be less than the read offset and the length cannot cause the search to read past the readable bytes otherwise an IndexOutOfBoundsException will be thrown.
      Specified by:
      indexOf in interface ProtonBuffer
      Parameters:
      needle - The byte value to search for in the remaining buffer bytes.
      offset - The offset into the buffer where the search should begin from.
      length - The offset into the buffer where the search should begin from.
      Returns:
      the location in the buffer where the value was found or -1 if not found.
    • releaseResourceOwnership

      protected void releaseResourceOwnership()
      Specified by:
      releaseResourceOwnership in class SharedResource<ProtonBuffer>
    • transferTheResource

      protected ProtonBuffer transferTheResource()
      Specified by:
      transferTheResource in class SharedResource<ProtonBuffer>
    • resourceIsClosedException

      protected RuntimeException resourceIsClosedException()
      Specified by:
      resourceIsClosedException in class SharedResource<ProtonBuffer>