Class DelegateByteBuffer<T>

java.lang.Object
io.micronaut.core.io.buffer.DelegateByteBuffer<T>
Type Parameters:
T - The native buffer type
All Implemented Interfaces:
ByteBuffer<T>

@Internal public class DelegateByteBuffer<T> extends Object implements ByteBuffer<T>
Delegate class for ByteBuffer.
Since:
4.0.0
Author:
Jonas Konrad
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    Exposes this buffer's readable bytes as an NIO ByteBuffer.
    asNioBuffer(int index, int length)
    Exposes this buffer's sub-region as an NIO ByteBuffer.
    capacity(int capacity)
    Adjusts the capacity of this buffer.
    byte
    getByte(int index)
    Get the byte at the specified index.
    int
    indexOf(byte b)
    Find the index of the first occurrence of the given byte.
    int
    Returns the maximum allowed capacity of this buffer.
    byte
    Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
    read(byte[] destination)
    Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= dst.length).
    read(byte[] destination, int offset, int length)
    Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length).
    int
    Returns the number of readable bytes which is equal to (this.writerIndex - this.readerIndex).
    readCharSequence(int length, Charset charset)
    Gets a CharSequence with the given length at the current readerIndex and increases the readerIndex by the given length.
    int
    Returns the readerIndex of this buffer.
    readerIndex(int readPosition)
    Sets the readerIndex of this buffer.
    slice(int index, int length)
    Create a new ByteBuffer whose contents is a shared subsequence of this data buffer's content.
    byte[]
    Create a copy of the underlying storage from buf into a byte array.
    Convert the ByteBuffer into an input stream.
    Convert the ByteBuffer into an output stream.
    toString(Charset charset)
    To string.
    int
    Returns the number of writable bytes which is equal to (this.capacity - this.writerIndex).
    write(byte b)
    Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.
    write(byte[] source)
    Transfers the specified source array's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= src.length).
    write(byte[] source, int offset, int length)
    Transfers the specified source array's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length).
    write(ByteBuffer... buffers)
    Write the given ByteBuffer instances to this buffer.
    write(CharSequence source, Charset charset)
    Transfers the specified source CharSequence's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= src.length).
    write(ByteBuffer... buffers)
    Write the given ByteBuffer instances to this buffer.
    int
    Returns the writerIndex of this buffer.
    writerIndex(int position)
    Sets the writerIndex of this buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DelegateByteBuffer

      public DelegateByteBuffer(ByteBuffer<T> delegate)
  • Method Details

    • asNativeBuffer

      public T asNativeBuffer()
      Specified by:
      asNativeBuffer in interface ByteBuffer<T>
      Returns:
      The native buffer type
    • readableBytes

      public int readableBytes()
      Description copied from interface: ByteBuffer
      Returns the number of readable bytes which is equal to (this.writerIndex - this.readerIndex).
      Specified by:
      readableBytes in interface ByteBuffer<T>
      Returns:
      bytes
    • writableBytes

      public int writableBytes()
      Description copied from interface: ByteBuffer
      Returns the number of writable bytes which is equal to (this.capacity - this.writerIndex).
      Specified by:
      writableBytes in interface ByteBuffer<T>
      Returns:
      The bytes
    • maxCapacity

      public int maxCapacity()
      Description copied from interface: ByteBuffer
      Returns the maximum allowed capacity of this buffer. If a user attempts to increase the capacity of this buffer beyond the maximum capacity using ByteBuffer.capacity(int) or IllegalArgumentException.
      Specified by:
      maxCapacity in interface ByteBuffer<T>
      Returns:
      The max capacity
    • capacity

      public ByteBuffer capacity(int capacity)
      Description copied from interface: ByteBuffer
      Adjusts the capacity of this buffer. If the newCapacity is less than the current capacity, the content of this buffer is truncated. If the newCapacity is greater than the current capacity, the buffer is appended with unspecified data whose length is (newCapacity - currentCapacity).
      Specified by:
      capacity in interface ByteBuffer<T>
      Parameters:
      capacity - capacity
      Returns:
      The bytebuffer
    • readerIndex

      public int readerIndex()
      Description copied from interface: ByteBuffer
      Returns the readerIndex of this buffer.
      Specified by:
      readerIndex in interface ByteBuffer<T>
      Returns:
      The index
    • readerIndex

      public ByteBuffer readerIndex(int readPosition)
      Description copied from interface: ByteBuffer
      Sets the readerIndex of this buffer.
      Specified by:
      readerIndex in interface ByteBuffer<T>
      Parameters:
      readPosition - readPosition
      Returns:
      The buffer
    • writerIndex

      public int writerIndex()
      Description copied from interface: ByteBuffer
      Returns the writerIndex of this buffer.
      Specified by:
      writerIndex in interface ByteBuffer<T>
      Returns:
      The index
    • writerIndex

      public ByteBuffer writerIndex(int position)
      Description copied from interface: ByteBuffer
      Sets the writerIndex of this buffer.
      Specified by:
      writerIndex in interface ByteBuffer<T>
      Parameters:
      position - The position
      Returns:
      The index as buffer
    • read

      public byte read()
      Description copied from interface: ByteBuffer
      Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
      Specified by:
      read in interface ByteBuffer<T>
      Returns:
      bytes
    • readCharSequence

      public CharSequence readCharSequence(int length, Charset charset)
      Description copied from interface: ByteBuffer
      Gets a CharSequence with the given length at the current readerIndex and increases the readerIndex by the given length.
      Specified by:
      readCharSequence in interface ByteBuffer<T>
      Parameters:
      length - the length to read
      charset - that should be used
      Returns:
      the sequence
    • read

      public ByteBuffer read(byte[] destination)
      Description copied from interface: ByteBuffer
      Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= dst.length).
      Specified by:
      read in interface ByteBuffer<T>
      Parameters:
      destination - destination
      Returns:
      bytesBuffer
    • read

      public ByteBuffer read(byte[] destination, int offset, int length)
      Description copied from interface: ByteBuffer
      Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length).
      Specified by:
      read in interface ByteBuffer<T>
      Parameters:
      destination - The destination byte array
      offset - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      bytesBuffer
    • write

      public ByteBuffer write(byte b)
      Description copied from interface: ByteBuffer
      Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer. The 24 high-order bits of the specified value are ignored.
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      b - The byte to write
      Returns:
      bytesBuffer
    • write

      public ByteBuffer write(byte[] source)
      Description copied from interface: ByteBuffer
      Transfers the specified source array's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= src.length).
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      source - The source bytes
      Returns:
      bytesBuffer
    • write

      public ByteBuffer write(CharSequence source, Charset charset)
      Description copied from interface: ByteBuffer
      Transfers the specified source CharSequence's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= src.length).
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      source - The char sequence
      charset - The charset
      Returns:
      This buffer
    • write

      public ByteBuffer write(byte[] source, int offset, int length)
      Description copied from interface: ByteBuffer
      Transfers the specified source array's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length).
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      source - The source byte array
      offset - the first index of the source
      length - the number of bytes to transfer
      Returns:
      bytesBuffer
    • write

      public ByteBuffer write(ByteBuffer... buffers)
      Description copied from interface: ByteBuffer
      Write the given ByteBuffer instances to this buffer.
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      buffers - The buffers to write
      Returns:
      this buffer
    • write

      public ByteBuffer write(ByteBuffer... buffers)
      Description copied from interface: ByteBuffer
      Write the given ByteBuffer instances to this buffer.
      Specified by:
      write in interface ByteBuffer<T>
      Parameters:
      buffers - The buffers to write
      Returns:
      this buffer
    • slice

      public ByteBuffer slice(int index, int length)
      Description copied from interface: ByteBuffer
      Create a new ByteBuffer whose contents is a shared subsequence of this data buffer's content. Data between this byte buffer and the returned buffer is shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.
      Specified by:
      slice in interface ByteBuffer<T>
      Parameters:
      index - the index at which to start the slice
      length - the length of the slice
      Returns:
      the specified slice of this data buffer
    • asNioBuffer

      public ByteBuffer asNioBuffer()
      Description copied from interface: ByteBuffer
      Exposes this buffer's readable bytes as an NIO ByteBuffer. The returned buffer shares the content with this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method is identical to buf.nioBuffer(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.
      Specified by:
      asNioBuffer in interface ByteBuffer<T>
      Returns:
      byteBuffer
    • asNioBuffer

      public ByteBuffer asNioBuffer(int index, int length)
      Description copied from interface: ByteBuffer
      Exposes this buffer's sub-region as an NIO ByteBuffer. The returned buffer shares the content with this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify readerIndex or writerIndex of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.
      Specified by:
      asNioBuffer in interface ByteBuffer<T>
      Parameters:
      index - The index
      length - The length
      Returns:
      byteBuffer
    • toInputStream

      public InputStream toInputStream()
      Description copied from interface: ByteBuffer
      Convert the ByteBuffer into an input stream.
      Specified by:
      toInputStream in interface ByteBuffer<T>
      Returns:
      this buffer as an input stream
    • toOutputStream

      public OutputStream toOutputStream()
      Description copied from interface: ByteBuffer
      Convert the ByteBuffer into an output stream.
      Specified by:
      toOutputStream in interface ByteBuffer<T>
      Returns:
      this buffer as an input stream
    • toByteArray

      public byte[] toByteArray()
      Description copied from interface: ByteBuffer
      Create a copy of the underlying storage from buf into a byte array. The copy will start at ByteBuffer.readerIndex() and copy ByteBuffer.readableBytes() bytes.
      Specified by:
      toByteArray in interface ByteBuffer<T>
      Returns:
      byte array
    • toString

      public String toString(Charset charset)
      Description copied from interface: ByteBuffer
      To string.
      Specified by:
      toString in interface ByteBuffer<T>
      Parameters:
      charset - converted charset
      Returns:
      string
    • indexOf

      public int indexOf(byte b)
      Description copied from interface: ByteBuffer
      Find the index of the first occurrence of the given byte.
      Specified by:
      indexOf in interface ByteBuffer<T>
      Parameters:
      b - The byte to find
      Returns:
      The index of the byte
    • getByte

      public byte getByte(int index)
      Description copied from interface: ByteBuffer
      Get the byte at the specified index.
      Specified by:
      getByte in interface ByteBuffer<T>
      Parameters:
      index - The index
      Returns:
      The byte