Class ByteArrayByteBuffer

java.lang.Object
io.micronaut.core.io.buffer.ByteArrayByteBuffer
All Implemented Interfaces:
ByteBuffer<byte[]>

@Internal public final class ByteArrayByteBuffer extends Object implements ByteBuffer<byte[]>
A ByteBuffer implementation that is backed by a byte array.
Since:
4.7
  • Method Details

    • asNativeBuffer

      public byte[] asNativeBuffer()
      Specified by:
      asNativeBuffer in interface ByteBuffer<byte[]>
      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<byte[]>
      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<byte[]>
      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<byte[]>
      Returns:
      The max capacity
    • capacity

      public ByteArrayByteBuffer 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<byte[]>
      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<byte[]>
      Returns:
      The index
    • readerIndex

      public ByteArrayByteBuffer readerIndex(int readPosition)
      Description copied from interface: ByteBuffer
      Sets the readerIndex of this buffer.
      Specified by:
      readerIndex in interface ByteBuffer<byte[]>
      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<byte[]>
      Returns:
      The index
    • writerIndex

      public ByteArrayByteBuffer writerIndex(int position)
      Description copied from interface: ByteBuffer
      Sets the writerIndex of this buffer.
      Specified by:
      writerIndex in interface ByteBuffer<byte[]>
      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<byte[]>
      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<byte[]>
      Parameters:
      length - the length to read
      charset - that should be used
      Returns:
      the sequence
    • read

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      destination - destination
      Returns:
      bytesBuffer
    • read

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      destination - The destination byte array
      offset - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      bytesBuffer
    • write

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      b - The byte to write
      Returns:
      bytesBuffer
    • write

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      source - The source bytes
      Returns:
      bytesBuffer
    • write

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      source - The char sequence
      charset - The charset
      Returns:
      This buffer
    • write

      public ByteArrayByteBuffer 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<byte[]>
      Parameters:
      source - The source byte array
      offset - the first index of the source
      length - the number of bytes to transfer
      Returns:
      bytesBuffer
    • write

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

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

      public ByteArrayByteBuffer 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<byte[]>
      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<byte[]>
      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<byte[]>
      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<byte[]>
      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<byte[]>
      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<byte[]>
      Returns:
      byte array
    • toString

      public String toString(Charset charset)
      Description copied from interface: ByteBuffer
      To string.
      Specified by:
      toString in interface ByteBuffer<byte[]>
      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<byte[]>
      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<byte[]>
      Parameters:
      index - The index
      Returns:
      The byte