Interface Buffer

All Known Subinterfaces:
CompositeBuffer
All Known Implementing Classes:
EmptyBuffer

public interface Buffer
An arbitrary and sequential accessible sequence of zero or more bytes (octets). This interface provides an abstract view for one or more primitive byte arrays (byte[]) and NIO buffers.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the backing byte array of this buffer.
    int
    Returns the offset of the first byte within the backing byte array of this buffer.
    Return an InputStream that wraps the given Buffer.
    Return an OutputStream that wraps the given Buffer.
    Create a read-only view for this buffer.
    int
    bytesBefore(byte value)
    Locates the first occurrence of the specified value in this buffer.
    int
    bytesBefore(int length, byte value)
    Locates the first occurrence of the specified value in this buffer.
    int
    bytesBefore(int index, int length, byte value)
    Locates the first occurrence of the specified value in this buffer.
    int
    Returns the number of bytes (octets) this buffer can contain.
    capacity(int newCapacity)
    Sets the capacity of this buffer.
    Sets the readerIndex and writerIndex of this buffer to 0.
    Returns a copy of this buffer's readable bytes.
    copy(int index, int length)
    Returns a copy of this buffer's sub-region.
    Returns a buffer which shares the whole region of this buffer.
    ensureWritable(int minWritableBytes)
    Expands the buffer capacity() to make sure the number of writable bytes is equal to or greater than the specified value.
    int
    ensureWritable(int minWritableBytes, boolean force)
    Expands the buffer capacity() to make sure the number of writable bytes is equal to or greater than the specified value.
    boolean
    Determines if the content of the specified buffer is identical to the content of this array.
    int
    forEachByte(int index, int length, ByteProcessor processor)
    Iterates over the specified area of this buffer with the specified processor in ascending order.
    int
    Iterates over the readable bytes of this buffer with the specified processor in ascending order.
    int
    forEachByteDesc(int index, int length, ByteProcessor processor)
    Iterates over the specified area of this buffer with the specified processor in descending order.
    int
    Iterates over the readable bytes of this buffer with the specified processor in descending order.
    boolean
    getBoolean(int index)
    Gets a boolean at the specified absolute (@code index) in this buffer.
    byte
    getByte(int index)
    Gets a byte at the specified absolute index in this buffer.
    getBytes(int index, byte[] dst)
    Transfers this buffer's data to the specified destination starting at the specified absolute index.
    getBytes(int index, byte[] dst, int dstIndex, int length)
    Transfers this buffer's data to the specified destination starting at the specified absolute index.
    getBytes(int index, Buffer dst)
    Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination becomes non-writable.
    getBytes(int index, Buffer dst, int length)
    Transfers this buffer's data to the specified destination starting at the specified absolute index.
    getBytes(int index, Buffer dst, int dstIndex, int length)
    Transfers this buffer's data to the specified destination starting at the specified absolute index.
    getBytes(int index, ByteBuffer dst)
    Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination's position reaches its limit.
    char
    getChar(int index)
    Gets a 2-byte UTF-16 character at the specified absolute index in this buffer.
    double
    getDouble(int index)
    Gets a 64-bit floating point number at the specified absolute index in this buffer.
    float
    getFloat(int index)
    Gets a 32-bit floating point number at the specified absolute index in this buffer.
    int
    getInt(int index)
    Gets a 32-bit integer at the specified absolute index in this buffer.
    int
    getIntLE(int index)
    Gets a 32-bit integer at the specified absolute index in this buffer with Little Endian Byte Order.
    long
    getLong(int index)
    Gets a 64-bit long integer at the specified absolute index in this buffer.
    long
    getLongLE(int index)
    Gets a 64-bit long integer at the specified absolute index in this buffer in Little Endian Byte Order.
    int
    getMedium(int index)
    Gets a 24-bit medium integer at the specified absolute index in this buffer.
    int
    getMediumLE(int index)
    Gets a 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order.
    short
    getShort(int index)
    Gets a 16-bit short integer at the specified absolute index in this buffer.
    short
    getShortLE(int index)
    Gets a 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order.
    short
    getUnsignedByte(int index)
    Gets an unsigned byte at the specified absolute index in this buffer.
    long
    getUnsignedInt(int index)
    Gets an unsigned 32-bit integer at the specified absolute index in this buffer.
    long
    getUnsignedIntLE(int index)
    Gets an unsigned 32-bit integer at the specified absolute index in this buffer in Little Endian Byte Order.
    int
    getUnsignedMedium(int index)
    Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer.
    int
    Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer in Little Endian Byte Order.
    int
    getUnsignedShort(int index)
    Gets an unsigned 16-bit short integer at the specified absolute index in this buffer.
    int
    getUnsignedShortLE(int index)
    Gets an unsigned 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order.
    boolean
    Returns true if and only if this buffer has a backing byte array.
    int
    Returns a hash code which was calculated from the content of this buffer.
    int
    indexOf(int fromIndex, int toIndex, byte value)
    Locates the first occurrence of the specified value in this buffer.
    boolean
    Returns true if the buffer is direct and so not allocated on the heap.
    boolean
    Determine if this buffer is read-only.
    int
    Returns the maximum allowed capacity of this buffer.
    int
    Returns the maximum possible number of writable bytes, which is equal to (this.maxCapacity - this.writerIndex).
    int
    Returns the maximum number of NIO ByteBuffers that consist this buffer.
    int
    Returns the number of readable bytes which is equal to (this.writerIndex - this.readerIndex).
    boolean
    Gets a boolean at the current readerIndex and increases the readerIndex by 1 in this buffer.
    byte
    Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
    readBytes(byte[] dst)
    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).
    readBytes(byte[] dst, int dstIndex, 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).
    readBytes(int length)
    Transfers this buffer's data to a newly created buffer starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length).
    Transfers this buffer's data to the specified destination starting at the current readerIndex until the destination becomes non-writable, and increases the readerIndex by the number of the transferred bytes.
    readBytes(Buffer dst, 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).
    readBytes(Buffer dst, int dstIndex, 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).
    Transfers this buffer's data to the specified destination starting at the current readerIndex until the destination's position reaches its limit, and increases the readerIndex by the number of the transferred bytes.
    char
    Gets a 2-byte UTF-16 character at the current readerIndex and increases the readerIndex by 2 in this buffer.
    double
    Gets a 64-bit floating point number at the current readerIndex and increases the readerIndex by 8 in this buffer.
    int
    Returns the readerIndex of this buffer.
    readerIndex(int readerIndex)
    Sets the readerIndex of this buffer.
    float
    Gets a 32-bit floating point number at the current readerIndex and increases the readerIndex by 4 in this buffer.
    int
    Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.
    int
    Gets a 32-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 4 in this buffer.
    long
    Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.
    long
    Gets a 64-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 8 in this buffer.
    int
    Gets a 24-bit medium integer at the current readerIndex and increases the readerIndex by 3 in this buffer.
    int
    Gets a 24-bit medium integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 3 in this buffer.
    short
    Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.
    short
    Gets a 16-bit short integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 2 in this buffer.
    readSlice(int length)
    Returns a new slice of this buffer's sub-region starting at the current readerIndex and increases the readerIndex by the size of the new slice (= length).
    short
    Gets an unsigned byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
    long
    Gets an unsigned 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.
    long
    Gets an unsigned 32-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 4 in this buffer.
    int
    Gets an unsigned 24-bit medium integer at the current readerIndex and increases the readerIndex by 3 in this buffer.
    int
    Gets an unsigned 24-bit medium integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 3 in this buffer.
    int
    Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.
    int
    Gets an unsigned 16-bit short integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 2 in this buffer.
    setBoolean(int index, boolean value)
    Sets the specified boolean at the specified absolute index in this buffer.
    setByte(int index, int value)
    Sets the specified byte at the specified absolute index in this buffer.
    setBytes(int index, byte[] src)
    Transfers the specified source array's data to this buffer starting at the specified absolute index.
    setBytes(int index, byte[] src, int srcIndex, int length)
    Transfers the specified source array's data to this buffer starting at the specified absolute index.
    setBytes(int index, Buffer src)
    Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer becomes unreadable.
    setBytes(int index, Buffer src, int length)
    Transfers the specified source buffer's data to this buffer starting at the specified absolute index.
    setBytes(int index, Buffer src, int srcIndex, int length)
    Transfers the specified source buffer's data to this buffer starting at the specified absolute index.
    int
    setBytes(int index, InputStream src, int length)
    Transfers a fixed amount from the specified source InputStream's data to this buffer starting at the specified absolute index until length bytes have been read, the end of stream is reached, or an exception is thrown.
    setBytes(int index, ByteBuffer src)
    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.
    int
    setBytesUntilEndStream(int index, InputStream src, int chunkSize)
    Transfers all the specified source InputStream's data to this buffer starting at the specified absolute index until the end of stream is reached or an exception is thrown.
    setChar(int index, int value)
    Sets the specified 2-byte UTF-16 character at the specified absolute index in this buffer.
    setDouble(int index, double value)
    Sets the specified 64-bit floating-point number at the specified absolute index in this buffer.
    setFloat(int index, float value)
    Sets the specified 32-bit floating-point number at the specified absolute index in this buffer.
    setInt(int index, int value)
    Sets the specified 32-bit integer at the specified absolute index in this buffer.
    setIntLE(int index, int value)
    Sets the specified 32-bit integer at the specified absolute index in this buffer with Little Endian byte order .
    setLong(int index, long value)
    Sets the specified 64-bit long integer at the specified absolute index in this buffer.
    setLongLE(int index, long value)
    Sets the specified 64-bit long integer at the specified absolute index in this buffer in Little Endian Byte Order.
    setMedium(int index, int value)
    Sets the specified 24-bit medium integer at the specified absolute index in this buffer.
    setMediumLE(int index, int value)
    Sets the specified 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order.
    setShort(int index, int value)
    Sets the specified 16-bit short integer at the specified absolute index in this buffer.
    setShortLE(int index, int value)
    Sets the specified 16-bit short integer at the specified absolute index in this buffer with the Little Endian Byte Order.
    skipBytes(int length)
    Increases the current readerIndex by the specified length in this buffer.
    Returns a slice of this buffer's readable bytes.
    slice(int index, int length)
    Returns a slice of this buffer's sub-region.
    Exposes this buffer's readable bytes as an NIO ByteBuffer.
    toNioBuffer(int index, int length)
    Exposes this buffer's sub-region as an NIO ByteBuffer.
    Exposes this buffer's readable bytes as an NIO ByteBuffer's.
    toNioBuffers(int index, int length)
    Exposes this buffer's bytes as an NIO ByteBuffer's for the specified index and length 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 of this buffer.
    Returns the string representation of this buffer.
    toString(int index, int length, Charset charset)
    Decodes this buffer's sub-region into a string with the specified character set.
    toString(Charset charset)
    Decodes this buffer's readable bytes into a string with the specified character set name.
    default boolean
    tryEnsureWritable(int minWritableBytes, boolean force)
    Tries to make sure the number of writable bytes is equal to or greater than the specified value.
    int
    Returns the number of writable bytes which is equal to (this.capacity - this.writerIndex).
    Encode a CharSequence in ASCII and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
    writeBoolean(boolean value)
    Sets the specified boolean at the current writerIndex and increases the writerIndex by 1 in this buffer.
    writeByte(int value)
    Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.
    writeBytes(byte[] src)
    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).
    writeBytes(byte[] src, int srcIndex, 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).
    Transfers the specified source buffer's data to this buffer starting at the current writerIndex until the source buffer becomes unreadable, and increases the writerIndex by the number of the transferred bytes.
    writeBytes(Buffer src, int length)
    Transfers the specified source buffer's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length).
    writeBytes(Buffer src, int srcIndex, int length)
    Transfers the specified source buffer's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length).
    int
    writeBytes(InputStream src, int length)
    Transfers a fixed amount from the specified source InputStream's data to this buffer starting at the current writerIndex until length bytes have been read, the end of stream is reached, or an exception is thrown.
    Transfers the specified source buffer's data to this buffer starting at the current writerIndex until the source buffer's position reaches its limit, and increases the writerIndex by the number of the transferred bytes.
    int
    Transfers all the specified source InputStream's data to this buffer starting at the current writerIndex until the end of stream is reached or an exception is thrown.
    writeChar(int value)
    Sets the specified 2-byte UTF-16 character at the current writerIndex and increases the writerIndex by 2 in this buffer.
    default Buffer
    Encode a CharSequence encoded in Charset and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
    writeDouble(double value)
    Sets the specified 64-bit floating point number at the current writerIndex and increases the writerIndex by 8 in this buffer.
    writeFloat(float value)
    Sets the specified 32-bit floating point number at the current writerIndex and increases the writerIndex by 4 in this buffer.
    writeInt(int value)
    Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.
    writeIntLE(int value)
    Sets the specified 32-bit integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 4 in this buffer.
    writeLong(long value)
    Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.
    writeLongLE(long value)
    Sets the specified 64-bit long integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 8 in this buffer.
    writeMedium(int value)
    Sets the specified 24-bit medium integer at the current writerIndex and increases the writerIndex by 3 in this buffer.
    writeMediumLE(int value)
    Sets the specified 24-bit medium integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 3 in this buffer.
    int
    Returns the writerIndex of this buffer.
    writerIndex(int writerIndex)
    Sets the writerIndex of this buffer.
    writeShort(int value)
    Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.
    writeShortLE(int value)
    Sets the specified 16-bit short integer in the Little Endian Byte Order at the current writerIndex and increases the writerIndex by 2 in this buffer.
    Encode a CharSequence in UTF-8 and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
    writeUtf8(CharSequence seq, int ensureWritable)
    Encode a CharSequence in UTF-8 and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
  • Method Details

    • capacity

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

      Buffer capacity(int newCapacity)
      Sets 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).
      Parameters:
      newCapacity - the new capacity.
      Returns:
      itself.
      Throws:
      IllegalArgumentException - if the newCapacity is greater than maxCapacity()
      ReadOnlyBufferException - if this buffer is read-only
    • maxCapacity

      int maxCapacity()
      Returns the maximum allowed capacity of this buffer. This value provides an upper bound on capacity().
      Returns:
      the max capacity of this buffer.
    • readerIndex

      int readerIndex()
      Returns the readerIndex of this buffer.
      Returns:
      the readerIndex of this buffer.
    • readerIndex

      Buffer readerIndex(int readerIndex)
      Sets the readerIndex of this buffer.
      Parameters:
      readerIndex - the new readerIndex of this buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified readerIndex is less than 0 or greater than this.writerIndex
    • writerIndex

      int writerIndex()
      Returns the writerIndex of this buffer.
      Returns:
      the writerIndex of this buffer.
    • writerIndex

      Buffer writerIndex(int writerIndex)
      Sets the writerIndex of this buffer.
      Parameters:
      writerIndex - the new writerIndex of this buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified writerIndex is less than this.readerIndex or greater than this.capacity
    • readableBytes

      int readableBytes()
      Returns the number of readable bytes which is equal to (this.writerIndex - this.readerIndex).
      Returns:
      the number of readables bytes in this buffer.
    • writableBytes

      int writableBytes()
      Returns the number of writable bytes which is equal to (this.capacity - this.writerIndex).
      Returns:
      the number of writable bytes in this buffer.
    • maxWritableBytes

      int maxWritableBytes()
      Returns the maximum possible number of writable bytes, which is equal to (this.maxCapacity - this.writerIndex).
      Returns:
      the maximum possible number of writable bytes in this buffer.
    • ensureWritable

      Buffer ensureWritable(int minWritableBytes)
      Expands the buffer capacity() to make sure the number of writable bytes is equal to or greater than the specified value. If there are enough writable bytes in this buffer, this method returns with no side effect.
      Parameters:
      minWritableBytes - the expected minimum number of writable bytes
      Returns:
      this object.
      Throws:
      IndexOutOfBoundsException - if writerIndex() + minWritableBytes > maxCapacity()
      ReadOnlyBufferException - if this buffer is read-only
    • ensureWritable

      int ensureWritable(int minWritableBytes, boolean force)
      Expands the buffer capacity() to make sure the number of writable bytes is equal to or greater than the specified value. Unlike ensureWritable(int), this method returns a status code.
      Parameters:
      minWritableBytes - the expected minimum number of writable bytes
      force - When writerIndex() + minWritableBytes > maxCapacity():
      • true - the capacity of the buffer is expanded to maxCapacity()
      • false - the capacity of the buffer is unchanged
      Returns:
      0 if the buffer has enough writable bytes, and its capacity is unchanged. 1 if the buffer does not have enough bytes, and its capacity is unchanged. 2 if the buffer has enough writable bytes, and its capacity has been increased. 3 if the buffer does not have enough bytes, but its capacity has been increased to its maximum.
    • tryEnsureWritable

      default boolean tryEnsureWritable(int minWritableBytes, boolean force)
      Tries to make sure the number of writable bytes is equal to or greater than the specified value. Unlike ensureWritable(int), this method does not raise an exception but returns a status code.
      Parameters:
      minWritableBytes - the expected minimum number of writable bytes
      force - When writerIndex() + minWritableBytes > maxCapacity():
      • true - the capacity of the buffer is expanded to maxCapacity()
      • false - the capacity of the buffer is unchanged
      Returns:
      true if this Buffer has at least minWritableBytes writable bytes after this call.
    • clear

      Buffer clear()
      Sets the readerIndex and writerIndex of this buffer to 0.

      Please note that the behavior of this method is different from that of NIO buffer, which sets the limit to the capacity of the buffer.

      Returns:
      this.
    • getBoolean

      boolean getBoolean(int index)
      Gets a boolean at the specified absolute (@code index) in this buffer. This method does not modify the readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a boolean.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.capacity
    • getByte

      byte getByte(int index)
      Gets a byte at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a byte.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.capacity
    • getUnsignedByte

      short getUnsignedByte(int index)
      Gets an unsigned byte at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      an unsigned byte.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.capacity
    • getShort

      short getShort(int index)
      Gets a 16-bit short integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
    • getShortLE

      short getShortLE(int index)
      Gets a 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
    • getUnsignedShort

      int getUnsignedShort(int index)
      Gets an unsigned 16-bit short integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
    • getUnsignedShortLE

      int getUnsignedShortLE(int index)
      Gets an unsigned 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
    • getMedium

      int getMedium(int index)
      Gets a 24-bit medium integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
    • getMediumLE

      int getMediumLE(int index)
      Gets a 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
    • getUnsignedMedium

      int getUnsignedMedium(int index)
      Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a medium in.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
    • getUnsignedMediumLE

      int getUnsignedMediumLE(int index)
      Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
    • getInt

      int getInt(int index)
      Gets a 32-bit integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
    • getIntLE

      int getIntLE(int index)
      Gets a 32-bit integer at the specified absolute index in this buffer with Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
    • getUnsignedInt

      long getUnsignedInt(int index)
      Gets an unsigned 32-bit integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a unsigned int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
    • getUnsignedIntLE

      long getUnsignedIntLE(int index)
      Gets an unsigned 32-bit integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a unsigned int.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
    • getLong

      long getLong(int index)
      Gets a 64-bit long integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a long.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
    • getLongLE

      long getLongLE(int index)
      Gets a 64-bit long integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a long.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
    • getChar

      char getChar(int index)
      Gets a 2-byte UTF-16 character at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a char.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
    • getFloat

      float getFloat(int index)
      Gets a 32-bit floating point number at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a float.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
    • getDouble

      double getDouble(int index)
      Gets a 64-bit floating point number at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      Returns:
      a double.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
    • getBytes

      Buffer getBytes(int index, Buffer dst)
      Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination becomes non-writable. This method is basically same with getBytes(int, Buffer, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes while getBytes(int, Buffer, int, int) does not. This method does not modify readerIndex or writerIndex of the source buffer (i.e. this).
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + dst.writableBytes is greater than this.capacity
    • getBytes

      Buffer getBytes(int index, Buffer dst, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index. This method is basically same with getBytes(int, Buffer, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes while getBytes(int, Buffer, int, int) does not. This method does not modify readerIndex or writerIndex of the source buffer (i.e. this).
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination buffer.
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if index + length is greater than this.capacity, or if length is greater than dst.writableBytes
    • getBytes

      Buffer getBytes(int index, Buffer dst, int dstIndex, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readerIndex or writerIndex of both the source (i.e. this) and the destination.
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination buffer.
      dstIndex - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if the specified dstIndex is less than 0, if index + length is greater than this.capacity, or if dstIndex + length is greater than dst.capacity
    • getBytes

      Buffer getBytes(int index, byte[] dst)
      Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination array.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + dst.length is greater than this.capacity
    • getBytes

      Buffer getBytes(int index, byte[] dst, int dstIndex, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination array.
      dstIndex - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if the specified dstIndex is less than 0, if index + length is greater than this.capacity, or if dstIndex + length is greater than dst.length
    • getBytes

      Buffer getBytes(int index, ByteBuffer dst)
      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 readerIndex or writerIndex of this buffer while the destination's position will be increased.
      Parameters:
      index - absolute (@code index) in this buffer.
      dst - the destination buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + dst.remaining() is greater than this.capacity
    • setBoolean

      Buffer setBoolean(int index, boolean value)
      Sets the specified boolean at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setByte

      Buffer setByte(int index, int value)
      Sets the specified byte at the specified absolute index in this buffer. The 24 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setShort

      Buffer setShort(int index, int value)
      Sets the specified 16-bit short integer at the specified absolute index in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setShortLE

      Buffer setShortLE(int index, int value)
      Sets the specified 16-bit short integer at the specified absolute index in this buffer with the Little Endian Byte Order. The 16 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setMedium

      Buffer setMedium(int index, int value)
      Sets the specified 24-bit medium integer at the specified absolute index in this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setMediumLE

      Buffer setMediumLE(int index, int value)
      Sets the specified 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order. Please note that the most significant byte is ignored in the specified value. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 3 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setInt

      Buffer setInt(int index, int value)
      Sets the specified 32-bit integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setIntLE

      Buffer setIntLE(int index, int value)
      Sets the specified 32-bit integer at the specified absolute index in this buffer with Little Endian byte order . This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setLong

      Buffer setLong(int index, long value)
      Sets the specified 64-bit long integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setLongLE

      Buffer setLongLE(int index, long value)
      Sets the specified 64-bit long integer at the specified absolute index in this buffer in Little Endian Byte Order. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setChar

      Buffer setChar(int index, int value)
      Sets the specified 2-byte UTF-16 character at the specified absolute index in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setFloat

      Buffer setFloat(int index, float value)
      Sets the specified 32-bit floating-point number at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setDouble

      Buffer setDouble(int index, double value)
      Sets the specified 64-bit floating-point number at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      value - the value.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, Buffer src)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer becomes unreadable. This method is basically same with setBytes(int, Buffer, int, int), except that this method increases the readerIndex of the source buffer by the number of the transferred bytes while setBytes(int, Buffer, int, int) does not. This method does not modify readerIndex or writerIndex of the source buffer (i.e. this).
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + src.readableBytes is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, Buffer src, int length)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method is basically same with setBytes(int, Buffer, int, int), except that this method increases the readerIndex of the source buffer by the number of the transferred bytes while setBytes(int, Buffer, int, int) does not. This method does not modify readerIndex or writerIndex of the source buffer (i.e. this).
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source buffer.
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if index + length is greater than this.capacity, or if length is greater than src.readableBytes
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, Buffer src, int srcIndex, int length)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of both the source (i.e. this) and the destination.
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source buffer.
      srcIndex - the first index of the source
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if the specified srcIndex is less than 0, if index + length is greater than this.capacity, or if srcIndex + length is greater than src.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, byte[] src)
      Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source array.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + src.length is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, byte[] src, int srcIndex, int length)
      Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source array.
      srcIndex - the first index of the source
      length - the number of bytes to transfer
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, if the specified srcIndex is less than 0, if index + length is greater than this.capacity, or if srcIndex + length is greater than src.length
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      Buffer setBytes(int index, ByteBuffer src)
      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 readerIndex or writerIndex of this buffer.
      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source buffer.
      Returns:
      itself.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + src.remaining() is greater than this.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • setBytes

      int setBytes(int index, InputStream src, int length) throws IOException
      Transfers a fixed amount from the specified source InputStream's data to this buffer starting at the specified absolute index until length bytes have been read, the end of stream is reached, or an exception is thrown.

      This method does not modify readerIndex or writerIndex of this buffer.

      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source InputStream.
      length - the maximum number of bytes to transfer. The buffer may be resized to accommodate this amount of data.
      Returns:
      the actual number of bytes read in from src. -1 if the specified channel is closed.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + src.remaining() is greater than this.capacity
      IOException - if the InputStream throws an exception while being read from.
      ReadOnlyBufferException - if this buffer is read-only
    • setBytesUntilEndStream

      int setBytesUntilEndStream(int index, InputStream src, int chunkSize) throws IOException
      Transfers all the specified source InputStream's data to this buffer starting at the specified absolute index until the end of stream is reached or an exception is thrown.

      This method does not modify readerIndex or writerIndex of this buffer.

      This method may modify the underlying storage size of this array to accomidate for reading data.

      Parameters:
      index - absolute (@code index) in this buffer.
      src - the source InputStream.
      chunkSize - chunkSize the amount of data that will be read from src on each read attempt.
      Returns:
      the actual total number of bytes read in from src. -1 if no bytes were read because the specified InputStream was closed when this method was called.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or if index + src.remaining() is greater than this.capacity
      IOException - if the InputStream throws an exception while being read from.
      ReadOnlyBufferException - if this buffer is read-only
    • readBoolean

      boolean readBoolean()
      Gets a boolean at the current readerIndex and increases the readerIndex by 1 in this buffer.
      Returns:
      a boolean.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 1
    • readByte

      byte readByte()
      Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
      Returns:
      a byte.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 1
    • readUnsignedByte

      short readUnsignedByte()
      Gets an unsigned byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
      Returns:
      a byte.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 1
    • readShort

      short readShort()
      Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 2
    • readShortLE

      short readShortLE()
      Gets a 16-bit short integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 2 in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 2
    • readUnsignedShort

      int readUnsignedShort()
      Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 2
    • readUnsignedShortLE

      int readUnsignedShortLE()
      Gets an unsigned 16-bit short integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 2 in this buffer.
      Returns:
      a short.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 2
    • readMedium

      int readMedium()
      Gets a 24-bit medium integer at the current readerIndex and increases the readerIndex by 3 in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 3
    • readMediumLE

      int readMediumLE()
      Gets a 24-bit medium integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 3 in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 3
    • readUnsignedMedium

      int readUnsignedMedium()
      Gets an unsigned 24-bit medium integer at the current readerIndex and increases the readerIndex by 3 in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 3
    • readUnsignedMediumLE

      int readUnsignedMediumLE()
      Gets an unsigned 24-bit medium integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 3 in this buffer.
      Returns:
      a medium int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 3
    • readInt

      int readInt()
      Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 4
    • readIntLE

      int readIntLE()
      Gets a 32-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 4 in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 4
    • readUnsignedInt

      long readUnsignedInt()
      Gets an unsigned 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 4
    • readUnsignedIntLE

      long readUnsignedIntLE()
      Gets an unsigned 32-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 4 in this buffer.
      Returns:
      a int.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 4
    • readLong

      long readLong()
      Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.
      Returns:
      a long.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 8
    • readLongLE

      long readLongLE()
      Gets a 64-bit integer at the current readerIndex in the Little Endian Byte Order and increases the readerIndex by 8 in this buffer.
      Returns:
      a long.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 8
    • readChar

      char readChar()
      Gets a 2-byte UTF-16 character at the current readerIndex and increases the readerIndex by 2 in this buffer.
      Returns:
      a char.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 2
    • readFloat

      float readFloat()
      Gets a 32-bit floating point number at the current readerIndex and increases the readerIndex by 4 in this buffer.
      Returns:
      a float.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 4
    • readDouble

      double readDouble()
      Gets a 64-bit floating point number at the current readerIndex and increases the readerIndex by 8 in this buffer.
      Returns:
      a double.
      Throws:
      IndexOutOfBoundsException - if this.readableBytes is less than 8
    • readSlice

      Buffer readSlice(int length)
      Returns a new slice of this buffer's sub-region starting at the current readerIndex and increases the readerIndex by the size of the new slice (= length).
      Parameters:
      length - the size of the new slice
      Returns:
      the newly created slice
      Throws:
      IndexOutOfBoundsException - if length is greater than this.readableBytes
    • readBytes

      Buffer readBytes(int length)
      Transfers this buffer's data to a newly created buffer starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length). The returned buffer's readerIndex and writerIndex are 0 and length respectively.
      Parameters:
      length - the number of bytes to transfer
      Returns:
      the newly created buffer which contains the transferred bytes
      Throws:
      IndexOutOfBoundsException - if length is greater than this.readableBytes
    • readBytes

      Buffer readBytes(Buffer dst)
      Transfers this buffer's data to the specified destination starting at the current readerIndex until the destination becomes non-writable, and increases the readerIndex by the number of the transferred bytes. This method is basically same with readBytes(Buffer, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes while readBytes(Buffer, int, int) does not.
      Parameters:
      dst - the destination buffer.
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if dst.writableBytes is greater than this.readableBytes
    • readBytes

      Buffer readBytes(Buffer dst, 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). This method is basically same with readBytes(Buffer, int, int), except that this method increases the writerIndex of the destination by the number of the transferred bytes (= length) while readBytes(Buffer, int, int) does not.
      Parameters:
      dst - the destination buffer.
      length - the number of bytes.
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if length is greater than this.readableBytes or if length is greater than dst.writableBytes
    • readBytes

      Buffer readBytes(Buffer dst, int dstIndex, 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).
      Parameters:
      dst - the destination buffer.
      dstIndex - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if the specified dstIndex is less than 0, if length is greater than this.readableBytes, or if dstIndex + length is greater than dst.capacity
    • readBytes

      Buffer readBytes(byte[] dst)
      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).
      Parameters:
      dst - the destination array.
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if dst.length is greater than this.readableBytes
    • readBytes

      Buffer readBytes(byte[] dst, int dstIndex, 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).
      Parameters:
      dst - the destination array.
      dstIndex - the first index of the destination
      length - the number of bytes to transfer
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if the specified dstIndex is less than 0, if length is greater than this.readableBytes, or if dstIndex + length is greater than dst.length
    • readBytes

      Buffer readBytes(ByteBuffer dst)
      Transfers this buffer's data to the specified destination starting at the current readerIndex until the destination's position reaches its limit, and increases the readerIndex by the number of the transferred bytes.
      Parameters:
      dst - the destination buffer.
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if dst.remaining() is less than this.readableBytes
    • skipBytes

      Buffer skipBytes(int length)
      Increases the current readerIndex by the specified length in this buffer.
      Parameters:
      length - number of bytes.
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if length is greater than this.readableBytes
    • writeBoolean

      Buffer writeBoolean(boolean value)
      Sets the specified boolean at the current writerIndex and increases the writerIndex by 1 in this buffer. If this.writableBytes is less than 1, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeByte

      Buffer writeByte(int value)
      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. If this.writableBytes is less than 1, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeShort

      Buffer writeShort(int value)
      Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer. The 16 high-order bits of the specified value are ignored. If this.writableBytes is less than 2, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeShortLE

      Buffer writeShortLE(int value)
      Sets the specified 16-bit short integer in the Little Endian Byte Order at the current writerIndex and increases the writerIndex by 2 in this buffer. The 16 high-order bits of the specified value are ignored. If this.writableBytes is less than 2, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeMedium

      Buffer writeMedium(int value)
      Sets the specified 24-bit medium integer at the current writerIndex and increases the writerIndex by 3 in this buffer. If this.writableBytes is less than 3, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeMediumLE

      Buffer writeMediumLE(int value)
      Sets the specified 24-bit medium integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 3 in this buffer. If this.writableBytes is less than 3, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeInt

      Buffer writeInt(int value)
      Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer. If this.writableBytes is less than 4, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeIntLE

      Buffer writeIntLE(int value)
      Sets the specified 32-bit integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 4 in this buffer. If this.writableBytes is less than 4, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeLong

      Buffer writeLong(long value)
      Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer. If this.writableBytes is less than 8, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeLongLE

      Buffer writeLongLE(long value)
      Sets the specified 64-bit long integer at the current writerIndex in the Little Endian Byte Order and increases the writerIndex by 8 in this buffer. If this.writableBytes is less than 8, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeChar

      Buffer writeChar(int value)
      Sets the specified 2-byte UTF-16 character at the current writerIndex and increases the writerIndex by 2 in this buffer. The 16 high-order bits of the specified value are ignored. If this.writableBytes is less than 2, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeFloat

      Buffer writeFloat(float value)
      Sets the specified 32-bit floating point number at the current writerIndex and increases the writerIndex by 4 in this buffer. If this.writableBytes is less than 4, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeDouble

      Buffer writeDouble(double value)
      Sets the specified 64-bit floating point number at the current writerIndex and increases the writerIndex by 8 in this buffer. If this.writableBytes is less than 8, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      value - the value to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(Buffer src)
      Transfers the specified source buffer's data to this buffer starting at the current writerIndex until the source buffer becomes unreadable, and increases the writerIndex by the number of the transferred bytes. This method is basically same with writeBytes(Buffer, int, int), except that this method increases the readerIndex of the source buffer by the number of the transferred bytes while writeBytes(Buffer, int, int) does not. If this.writableBytes is less than src.readableBytes, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the buffer to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(Buffer src, int length)
      Transfers the specified source buffer's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length). This method is basically same with writeBytes(Buffer, int, int), except that this method increases the readerIndex of the source buffer by the number of the transferred bytes (= length) while writeBytes(Buffer, int, int) does not. If this.writableBytes is less than length, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the buffer to write.
      length - the number of bytes to transfer
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if length is greater then src.readableBytes
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(Buffer src, int srcIndex, int length)
      Transfers the specified source buffer's data to this buffer starting at the current writerIndex and increases the writerIndex by the number of the transferred bytes (= length). If this.writableBytes is less than length, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the buffer to write.
      srcIndex - the first index of the source
      length - the number of bytes to transfer
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if the specified srcIndex is less than 0, or if srcIndex + length is greater than src.capacity
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(byte[] src)
      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). If this.writableBytes is less than src.length, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the array to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(byte[] src, int srcIndex, 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). If this.writableBytes is less than length, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the array to write.
      srcIndex - the first index of the source
      length - the number of bytes to transfer
      Returns:
      self.
      Throws:
      IndexOutOfBoundsException - if the specified srcIndex is less than 0, or if srcIndex + length is greater than src.length
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      Buffer writeBytes(ByteBuffer src)
      Transfers the specified source buffer's data to this buffer starting at the current writerIndex until the source buffer's position reaches its limit, and increases the writerIndex by the number of the transferred bytes. If this.writableBytes is less than src.remaining(), ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      src - the source buffer to write.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytes

      int writeBytes(InputStream src, int length) throws IOException
      Transfers a fixed amount from the specified source InputStream's data to this buffer starting at the current writerIndex until length bytes have been read, the end of stream is reached, or an exception is thrown. If this.writableBytes is less than length, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.

      This method will increase the writerIndex by the number of the transferred bytes if the write operation was successful.

      Parameters:
      src - the source InputStream to write.
      length - the maximum number of bytes to transfer. The buffer may be resized to accommodate this amount of data.
      Returns:
      the actual number of bytes read in from src. -1 if the specified channel is closed.
      Throws:
      IOException - if the InputStream throws an exception while being read from.
      ReadOnlyBufferException - if this buffer is read-only
    • writeBytesUntilEndStream

      int writeBytesUntilEndStream(InputStream src, int chunkSize) throws IOException
      Transfers all the specified source InputStream's data to this buffer starting at the current writerIndex until the end of stream is reached or an exception is thrown. If this.writableBytes is less than the number of bytes in the InputStream, ensureWritable(int) will be called in an attempt to expand capacity to accommodate. Note that because InputStream does not provide a reliable way to get the remaining bytes, this method may over allocate by a factor of chunkSize.

      This method will increase the writerIndex by the number of the transferred bytes if the write operation was successful.

      Parameters:
      src - the source InputStream to write.
      chunkSize - the amount of data that will be read from src on each read attempt.
      Returns:
      the actual total number of bytes read in from src. -1 if no bytes were read because the specified InputStream was closed when this method was called.
      Throws:
      IOException - if the InputStream throws an exception while being read from.
      ReadOnlyBufferException - if this buffer is read-only
    • writeAscii

      Buffer writeAscii(CharSequence seq)
      Encode a CharSequence in ASCII and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes. If this.writableBytes is not large enough to write the whole sequence, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      seq - the source of the data.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeUtf8

      Buffer writeUtf8(CharSequence seq)
      Encode a CharSequence in UTF-8 and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes. If this.writableBytes is not large enough to write the whole sequence, ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Parameters:
      seq - the source of the data.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeUtf8

      Buffer writeUtf8(CharSequence seq, int ensureWritable)
      Encode a CharSequence in UTF-8 and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
      Parameters:
      seq - the source of the data.
      ensureWritable - the number of bytes to ensure are writeable.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • writeCharSequence

      default Buffer writeCharSequence(CharSequence seq, Charset charset)
      Encode a CharSequence encoded in Charset and write it to this buffer starting at writerIndex and increases the writerIndex by the number of the transferred bytes.
      Parameters:
      seq - the source of the data.
      charset - the charset used for encoding.
      Returns:
      self.
      Throws:
      ReadOnlyBufferException - if this buffer is read-only
    • indexOf

      int indexOf(int fromIndex, int toIndex, byte value)
      Locates the first occurrence of the specified value in this buffer. The search takes place from the specified fromIndex (inclusive) to the specified toIndex (exclusive).

      If fromIndex is greater than toIndex, the search is performed in a reversed order.

      This method does not modify readerIndex or writerIndex of this buffer.

      Parameters:
      fromIndex - the start index.
      toIndex - the end index.
      value - the value to search.
      Returns:
      the absolute index of the first occurrence if found. -1 otherwise.
    • bytesBefore

      int bytesBefore(byte value)
      Locates the first occurrence of the specified value in this buffer. The search takes place from the current readerIndex (inclusive) to the current writerIndex (exclusive).

      This method does not modify readerIndex or writerIndex of this buffer.

      Parameters:
      value - the value to search.
      Returns:
      the number of bytes between the current readerIndex and the first occurrence if found. -1 otherwise.
    • bytesBefore

      int bytesBefore(int length, byte value)
      Locates the first occurrence of the specified value in this buffer. The search starts from the current readerIndex (inclusive) and lasts for the specified length.

      This method does not modify readerIndex or writerIndex of this buffer.

      Parameters:
      length - the length.
      value - the value to search.
      Returns:
      the number of bytes between the current readerIndex and the first occurrence if found. -1 otherwise.
      Throws:
      IndexOutOfBoundsException - if length is greater than this.readableBytes
    • bytesBefore

      int bytesBefore(int index, int length, byte value)
      Locates the first occurrence of the specified value in this buffer. The search starts from the specified index (inclusive) and lasts for the specified length.

      This method does not modify readerIndex or writerIndex of this buffer.

      Parameters:
      index - the index.
      length - the length.
      value - the value to search.
      Returns:
      the number of bytes between the specified index and the first occurrence if found. -1 otherwise.
      Throws:
      IndexOutOfBoundsException - if index + length is greater than this.capacity
    • copy

      Buffer copy()
      Returns a copy of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method is identical to buf.copy(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.
      Returns:
      a copy of the buffer.
    • copy

      Buffer copy(int index, int length)
      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 readerIndex or writerIndex of this buffer.
      Parameters:
      index - the start index.
      length - the length.
      Returns:
      a copy of the buffer.
    • slice

      Buffer slice()
      Returns a slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes. This method is identical to buf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.
      Returns:
      a sliced buffer.
    • slice

      Buffer slice(int index, int length)
      Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - the start index.
      length - the length.
      Returns:
      a sliced buffer.
    • duplicate

      Buffer duplicate()
      Returns a buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes. This method is identical to buf.slice(0, buf.capacity()). This method does not modify readerIndex or writerIndex of this buffer.
      Returns:
      a duplicated buffer.
    • nioBufferCount

      int nioBufferCount()
      Returns the maximum number of NIO ByteBuffers that consist this buffer. Note that toNioBuffers() or toNioBuffers(int, int) might return a less number of ByteBuffers.
      Returns:
      -1 if this buffer has no underlying ByteBuffer. the number of the underlying ByteBuffers if this buffer has at least one underlying ByteBuffer. Note that this method does not return 0 to avoid confusion.
      See Also:
    • toNioBuffer

      ByteBuffer toNioBuffer()
      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 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.
      Returns:
      the nio buffer.
      Throws:
      UnsupportedOperationException - if this buffer cannot create a ByteBuffer that shares the content with itself
      See Also:
    • toNioBuffer

      ByteBuffer toNioBuffer(int index, int length)
      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 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.
      Parameters:
      index - the start index.
      length - the length.
      Returns:
      the nio buffer.
      Throws:
      UnsupportedOperationException - if this buffer cannot create a ByteBuffer that shares the content with itself
      See Also:
    • toNioBuffers

      ByteBuffer[] toNioBuffers()
      Exposes this buffer's readable bytes as an NIO ByteBuffer's. 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 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.
      Returns:
      the nio buffers.
      Throws:
      UnsupportedOperationException - if this buffer cannot create a ByteBuffer that shares the content with itself
      See Also:
    • toNioBuffers

      ByteBuffer[] toNioBuffers(int index, int length)
      Exposes this buffer's bytes as an NIO ByteBuffer's for the specified index and length 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 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.
      Parameters:
      index - the start index.
      length - the length.
      Returns:
      the nio buffers.
      Throws:
      UnsupportedOperationException - if this buffer cannot create a ByteBuffer that shares the content with itself
      See Also:
    • isReadOnly

      boolean isReadOnly()
      Determine if this buffer is read-only.
      Returns:
      true if and only if this buffer is read-only.
    • asReadOnly

      Buffer asReadOnly()
      Create a read-only view for this buffer.

      The returned read-only view shares indexes and content with the original Buffer. All methods that try to change the content will throw ReadOnlyBufferException. Modifications for indexes are allowed and will be propagated to the original Buffer. To prevent changes of indexes for the original Buffer use duplicate() before converting to a read-only view.

      Returns:
      a buffer whose contents cannot be modified.
    • isDirect

      boolean isDirect()
      Returns true if the buffer is direct and so not allocated on the heap.
      Returns:
      true if direct.
    • hasArray

      boolean hasArray()
      Returns true if and only if this buffer has a backing byte array. If this method returns true, you can safely call array() and arrayOffset().
      Returns:
      true if backed by an byte array and is not read-only
      See Also:
    • array

      byte[] array()
      Returns the backing byte array of this buffer.

      The caller must check hasArray() returns true before calling this method or UnsupportedOperationException maybe thrown.

      Use arrayOffset() to get the starting point of data for this buffer. The returned array maybe shared and this Buffer's data may reside in a sub-section.

      Returns:
      byte array.
      Throws:
      UnsupportedOperationException - if there no accessible backing byte array
      ReadOnlyBufferException - if this buffer is read-only
      See Also:
    • arrayOffset

      int arrayOffset()
      Returns the offset of the first byte within the backing byte array of this buffer.

      The caller must check hasArray() returns true before calling this method or UnsupportedOperationException maybe thrown.

      Returns:
      the offset in the array.
      Throws:
      UnsupportedOperationException - if there no accessible backing byte array
      ReadOnlyBufferException - if this buffer is read-only
      See Also:
    • forEachByte

      int forEachByte(ByteProcessor processor)
      Iterates over the readable bytes of this buffer with the specified processor in ascending order.
      Parameters:
      processor - the ByteProcessor to use.
      Returns:
      -1 if the processor iterated to or beyond the end of the readable bytes. The last-visited index If the ByteProcessor.process(byte) returned false.
    • forEachByte

      int forEachByte(int index, int length, ByteProcessor processor)
      Iterates over the specified area of this buffer with the specified processor in ascending order. (i.e. index, (index + 1), .. (index + length - 1))
      Parameters:
      index - The index to start iterating from.
      length - The amount of bytes to iterate over.
      processor - the ByteProcessor to use.
      Returns:
      -1 if the processor iterated to or beyond the end of the specified area. The last-visited index If the ByteProcessor.process(byte) returned false.
    • forEachByteDesc

      int forEachByteDesc(ByteProcessor processor)
      Iterates over the readable bytes of this buffer with the specified processor in descending order.
      Parameters:
      processor - the ByteProcessor to use.
      Returns:
      -1 if the processor iterated to or beyond the beginning of the readable bytes. The last-visited index If the ByteProcessor.process(byte) returned false.
    • forEachByteDesc

      int forEachByteDesc(int index, int length, ByteProcessor processor)
      Iterates over the specified area of this buffer with the specified processor in descending order. (i.e. (index + length - 1), (index + length - 2), ... index)
      Parameters:
      index - The index to start iterating from.
      length - The amount of bytes to iterate over.
      processor - the ByteProcessor to use.
      Returns:
      -1 if the processor iterated to or beyond the beginning of the specified area. The last-visited index If the ByteProcessor.process(byte) returned false.
    • hashCode

      int hashCode()
      Returns a hash code which was calculated from the content of this buffer. If there's a byte array which is equal to this array, both arrays should return the same value.
      Overrides:
      hashCode in class Object
    • equals

      boolean equals(Object obj)
      Determines if the content of the specified buffer is identical to the content of this array. 'Identical' here means:
      • the size of the contents of the two buffers are same and
      • every single byte of the content of the two buffers are same.
      Please note that it does not compare readerIndex() nor writerIndex(). This method also returns false for null and an object which is not an instance of Buffer type.
      Overrides:
      equals in class Object
    • toString

      String toString()
      Returns the string representation of this buffer. This method does not necessarily return the whole content of the buffer but returns the values of the key properties such as readerIndex(), writerIndex() and capacity().
      Overrides:
      toString in class Object
    • toString

      String toString(Charset charset)
      Decodes this buffer's readable bytes into a string with the specified character set name. This method is identical to buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName). This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      charset - the charset to use.
      Returns:
      the string.
      Throws:
      UnsupportedCharsetException - if the specified character set name is not supported by the current VM
    • toString

      String toString(int index, int length, Charset charset)
      Decodes this buffer's sub-region into a string with the specified character set. This method does not modify readerIndex or writerIndex of this buffer.
      Parameters:
      index - the start index.
      length - the length.
      charset - the charset to use.
      Returns:
      the string.
    • asOutputStream

      static OutputStream asOutputStream(Buffer buffer)
      Return an OutputStream that wraps the given Buffer. The writerIndex will be increased when writing to the buffer.
      Parameters:
      buffer - the buffer to wrap.
      Returns:
      a new OutputStream.
    • asInputStream

      static InputStream asInputStream(Buffer buffer)
      Return an InputStream that wraps the given Buffer. The readerIndex will be increased when reading from the buffer.
      Parameters:
      buffer - the buffer to wrap.
      Returns:
      a new InputStream.