Interface Buffer
- All Known Subinterfaces:
CompositeBuffer
- All Known Implementing Classes:
EmptyBuffer
byte[]
) and NIO buffers
.-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns the backing byte array of this buffer.int
Returns the offset of the first byte within the backing byte array of this buffer.static InputStream
asInputStream
(Buffer buffer) Return anInputStream
that wraps the givenBuffer
.static OutputStream
asOutputStream
(Buffer buffer) Return anOutputStream
that wraps the givenBuffer
.Create a read-only view for this buffer.int
bytesBefore
(byte value) Locates the first occurrence of the specifiedvalue
in this buffer.int
bytesBefore
(int length, byte value) Locates the first occurrence of the specifiedvalue
in this buffer.int
bytesBefore
(int index, int length, byte value) Locates the first occurrence of the specifiedvalue
in this buffer.int
capacity()
Returns the number of bytes (octets) this buffer can contain.capacity
(int newCapacity) Sets the capacity of this buffer.clear()
Sets thereaderIndex
andwriterIndex
of this buffer to0
.copy()
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 buffercapacity()
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 buffercapacity()
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 specifiedprocessor
in ascending order.int
forEachByte
(ByteProcessor processor) Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.int
forEachByteDesc
(int index, int length, ByteProcessor processor) Iterates over the specified area of this buffer with the specifiedprocessor
in descending order.int
forEachByteDesc
(ByteProcessor processor) Iterates over the readable bytes of this buffer with the specifiedprocessor
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 absoluteindex
in this buffer.getBytes
(int index, byte[] dst) Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.getBytes
(int index, byte[] dst, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination becomes non-writable.Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.getBytes
(int index, ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit.char
getChar
(int index) Gets a 2-byte UTF-16 character at the specified absoluteindex
in this buffer.double
getDouble
(int index) Gets a 64-bit floating point number at the specified absoluteindex
in this buffer.float
getFloat
(int index) Gets a 32-bit floating point number at the specified absoluteindex
in this buffer.int
getInt
(int index) Gets a 32-bit integer at the specified absoluteindex
in this buffer.int
getIntLE
(int index) Gets a 32-bit integer at the specified absoluteindex
in this buffer with Little Endian Byte Order.long
getLong
(int index) Gets a 64-bit long integer at the specified absoluteindex
in this buffer.long
getLongLE
(int index) Gets a 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
getMedium
(int index) Gets a 24-bit medium integer at the specified absoluteindex
in this buffer.int
getMediumLE
(int index) Gets a 24-bit medium integer at the specified absoluteindex
in this buffer in the Little Endian Byte Order.short
getShort
(int index) Gets a 16-bit short integer at the specified absoluteindex
in this buffer.short
getShortLE
(int index) Gets a 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.short
getUnsignedByte
(int index) Gets an unsigned byte at the specified absoluteindex
in this buffer.long
getUnsignedInt
(int index) Gets an unsigned 32-bit integer at the specified absoluteindex
in this buffer.long
getUnsignedIntLE
(int index) Gets an unsigned 32-bit integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
getUnsignedMedium
(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer.int
getUnsignedMediumLE
(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
getUnsignedShort
(int index) Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer.int
getUnsignedShortLE
(int index) Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.boolean
hasArray()
Returnstrue
if and only if this buffer has a backing byte array.int
hashCode()
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 specifiedvalue
in this buffer.boolean
isDirect()
Returnstrue
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 NIOByteBuffer
s 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 currentreaderIndex
and increases thereaderIndex
by1
in this buffer.byte
readByte()
Gets a byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.readBytes
(byte[] dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
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 currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).readBytes
(int length) Transfers this buffer's data to a newly created buffer starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).Transfers this buffer's data to the specified destination starting at the currentreaderIndex
until the destination becomes non-writable, and increases thereaderIndex
by the number of the transferred bytes.Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).readBytes
(ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndex
until the destination's position reaches its limit, and increases thereaderIndex
by the number of the transferred bytes.char
readChar()
Gets a 2-byte UTF-16 character at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.double
Gets a 64-bit floating point number at the currentreaderIndex
and increases thereaderIndex
by8
in this buffer.int
Returns thereaderIndex
of this buffer.readerIndex
(int readerIndex) Sets thereaderIndex
of this buffer.float
Gets a 32-bit floating point number at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.int
readInt()
Gets a 32-bit integer at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.int
Gets a 32-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by4
in this buffer.long
readLong()
Gets a 64-bit integer at the currentreaderIndex
and increases thereaderIndex
by8
in this buffer.long
Gets a 64-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by8
in this buffer.int
Gets a 24-bit medium integer at the currentreaderIndex
and increases thereaderIndex
by3
in this buffer.int
Gets a 24-bit medium integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by3
in this buffer.short
Gets a 16-bit short integer at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.short
Gets a 16-bit short integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by2
in this buffer.readSlice
(int length) Returns a new slice of this buffer's sub-region starting at the currentreaderIndex
and increases thereaderIndex
by the size of the new slice (=length
).short
Gets an unsigned byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.long
Gets an unsigned 32-bit integer at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.long
Gets an unsigned 32-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by4
in this buffer.int
Gets an unsigned 24-bit medium integer at the currentreaderIndex
and increases thereaderIndex
by3
in this buffer.int
Gets an unsigned 24-bit medium integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by3
in this buffer.int
Gets an unsigned 16-bit short integer at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.int
Gets an unsigned 16-bit short integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by2
in this buffer.setBoolean
(int index, boolean value) Sets the specified boolean at the specified absoluteindex
in this buffer.setByte
(int index, int value) Sets the specified byte at the specified absoluteindex
in this buffer.setBytes
(int index, byte[] src) Transfers the specified source array's data to this buffer starting at the specified absoluteindex
.setBytes
(int index, byte[] src, int srcIndex, int length) Transfers the specified source array's data to this buffer starting at the specified absoluteindex
.Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer becomes unreadable.Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
.Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
.int
setBytes
(int index, InputStream src, int length) Transfers a fixed amount from the specified sourceInputStream
's data to this buffer starting at the specified absoluteindex
untillength
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 absoluteindex
until the source buffer's position reaches its limit.int
setBytesUntilEndStream
(int index, InputStream src, int chunkSize) Transfers all the specified sourceInputStream
's data to this buffer starting at the specified absoluteindex
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 absoluteindex
in this buffer.setDouble
(int index, double value) Sets the specified 64-bit floating-point number at the specified absoluteindex
in this buffer.setFloat
(int index, float value) Sets the specified 32-bit floating-point number at the specified absoluteindex
in this buffer.setInt
(int index, int value) Sets the specified 32-bit integer at the specified absoluteindex
in this buffer.setIntLE
(int index, int value) Sets the specified 32-bit integer at the specified absoluteindex
in this buffer with Little Endian byte order .setLong
(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer.setLongLE
(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.setMedium
(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer.setMediumLE
(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer in the Little Endian Byte Order.setShort
(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer.setShortLE
(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer with the Little Endian Byte Order.skipBytes
(int length) Increases the currentreaderIndex
by the specifiedlength
in this buffer.slice()
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 NIOByteBuffer
.toNioBuffer
(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer
.Exposes this buffer's readable bytes as an NIOByteBuffer
's.toNioBuffers
(int index, int length) Exposes this buffer's bytes as an NIOByteBuffer
'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.toString()
Returns the string representation of this buffer.Decodes this buffer's sub-region into a string with the specified character set.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)
.writeAscii
(CharSequence seq) Encode aCharSequence
in ASCII and write it to this buffer starting atwriterIndex
and increases thewriterIndex
by the number of the transferred bytes.writeBoolean
(boolean value) Sets the specified boolean at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer.writeByte
(int value) Sets the specified byte at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer.writeBytes
(byte[] src) Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
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 currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
).writeBytes
(Buffer src) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
until the source buffer becomes unreadable, and increases thewriterIndex
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 currentwriterIndex
and increases thewriterIndex
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 currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
).int
writeBytes
(InputStream src, int length) Transfers a fixed amount from the specified sourceInputStream
's data to this buffer starting at the currentwriterIndex
untillength
bytes have been read, the end of stream is reached, or an exception is thrown.writeBytes
(ByteBuffer src) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
until the source buffer's position reaches its limit, and increases thewriterIndex
by the number of the transferred bytes.int
writeBytesUntilEndStream
(InputStream src, int chunkSize) Transfers all the specified sourceInputStream
's data to this buffer starting at the currentwriterIndex
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 currentwriterIndex
and increases thewriterIndex
by2
in this buffer.default Buffer
writeCharSequence
(CharSequence seq, Charset charset) Encode aCharSequence
encoded inCharset
and write it to this buffer starting atwriterIndex
and increases thewriterIndex
by the number of the transferred bytes.writeDouble
(double value) Sets the specified 64-bit floating point number at the currentwriterIndex
and increases thewriterIndex
by8
in this buffer.writeFloat
(float value) Sets the specified 32-bit floating point number at the currentwriterIndex
and increases thewriterIndex
by4
in this buffer.writeInt
(int value) Sets the specified 32-bit integer at the currentwriterIndex
and increases thewriterIndex
by4
in this buffer.writeIntLE
(int value) Sets the specified 32-bit integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by4
in this buffer.writeLong
(long value) Sets the specified 64-bit long integer at the currentwriterIndex
and increases thewriterIndex
by8
in this buffer.writeLongLE
(long value) Sets the specified 64-bit long integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by8
in this buffer.writeMedium
(int value) Sets the specified 24-bit medium integer at the currentwriterIndex
and increases thewriterIndex
by3
in this buffer.writeMediumLE
(int value) Sets the specified 24-bit medium integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by3
in this buffer.int
Returns thewriterIndex
of this buffer.writerIndex
(int writerIndex) Sets thewriterIndex
of this buffer.writeShort
(int value) Sets the specified 16-bit short integer at the currentwriterIndex
and increases thewriterIndex
by2
in this buffer.writeShortLE
(int value) Sets the specified 16-bit short integer in the Little Endian Byte Order at the currentwriterIndex
and increases thewriterIndex
by2
in this buffer.writeUtf8
(CharSequence seq) Encode aCharSequence
in UTF-8 and write it to this buffer starting atwriterIndex
and increases thewriterIndex
by the number of the transferred bytes.writeUtf8
(CharSequence seq, int ensureWritable) Encode aCharSequence
in UTF-8 and write it to this buffer starting atwriterIndex
and increases thewriterIndex
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
Sets the capacity of this buffer. If thenewCapacity
is less than the current capacity, the content of this buffer is truncated. If thenewCapacity
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 thenewCapacity
is greater thanmaxCapacity()
ReadOnlyBufferException
- if this buffer is read-only
-
maxCapacity
int maxCapacity()Returns the maximum allowed capacity of this buffer. This value provides an upper bound oncapacity()
.- Returns:
- the max capacity of this buffer.
-
readerIndex
int readerIndex()Returns thereaderIndex
of this buffer.- Returns:
- the
readerIndex
of this buffer.
-
readerIndex
Sets thereaderIndex
of this buffer.- Parameters:
readerIndex
- the new readerIndex of this buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedreaderIndex
is less than0
or greater thanthis.writerIndex
-
writerIndex
int writerIndex()Returns thewriterIndex
of this buffer.- Returns:
- the
writerIndex
of this buffer.
-
writerIndex
Sets thewriterIndex
of this buffer.- Parameters:
writerIndex
- the new writerIndex of this buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedwriterIndex
is less thanthis.readerIndex
or greater thanthis.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
Expands the buffercapacity()
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
- ifwriterIndex()
+minWritableBytes
>maxCapacity()
ReadOnlyBufferException
- if this buffer is read-only
-
ensureWritable
int ensureWritable(int minWritableBytes, boolean force) Expands the buffercapacity()
to make sure the number of writable bytes is equal to or greater than the specified value. UnlikeensureWritable(int)
, this method returns a status code.- Parameters:
minWritableBytes
- the expected minimum number of writable bytesforce
- WhenwriterIndex()
+minWritableBytes
>maxCapacity()
:true
- the capacity of the buffer is expanded tomaxCapacity()
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. UnlikeensureWritable(int)
, this method does not raise an exception but returns a status code.- Parameters:
minWritableBytes
- the expected minimum number of writable bytesforce
- WhenwriterIndex()
+minWritableBytes
>maxCapacity()
:true
- the capacity of the buffer is expanded tomaxCapacity()
false
- the capacity of the buffer is unchanged
- Returns:
true
if thisBuffer
has at leastminWritableBytes
writable bytes after this call.
-
clear
Buffer clear()Sets thereaderIndex
andwriterIndex
of this buffer to0
.Please note that the behavior of this method is different from that of NIO buffer, which sets the
limit
to thecapacity
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 thereaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a boolean.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 1
is greater thanthis.capacity
-
getByte
byte getByte(int index) Gets a byte at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 1
is greater thanthis.capacity
-
getUnsignedByte
short getUnsignedByte(int index) Gets an unsigned byte at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- an unsigned byte.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 1
is greater thanthis.capacity
-
getShort
short getShort(int index) Gets a 16-bit short integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
-
getShortLE
short getShortLE(int index) Gets a 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
-
getUnsignedShort
int getUnsignedShort(int index) Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
-
getUnsignedShortLE
int getUnsignedShortLE(int index) Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
-
getMedium
int getMedium(int index) Gets a 24-bit medium integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
-
getMediumLE
int getMediumLE(int index) Gets a 24-bit medium integer at the specified absoluteindex
in this buffer in the Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
-
getUnsignedMedium
int getUnsignedMedium(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a medium in.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
-
getUnsignedMediumLE
int getUnsignedMediumLE(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
-
getInt
int getInt(int index) Gets a 32-bit integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
-
getIntLE
int getIntLE(int index) Gets a 32-bit integer at the specified absoluteindex
in this buffer with Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
-
getUnsignedInt
long getUnsignedInt(int index) Gets an unsigned 32-bit integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a unsigned int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
-
getUnsignedIntLE
long getUnsignedIntLE(int index) Gets an unsigned 32-bit integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a unsigned int.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
-
getLong
long getLong(int index) Gets a 64-bit long integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
-
getLongLE
long getLongLE(int index) Gets a 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
-
getChar
char getChar(int index) Gets a 2-byte UTF-16 character at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a char.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
-
getFloat
float getFloat(int index) Gets a 32-bit floating point number at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a float.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
-
getDouble
double getDouble(int index) Gets a 64-bit floating point number at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.- Returns:
- a double.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination becomes non-writable. This method is basically same withgetBytes(int, Buffer, int, int)
, except that this method increases thewriterIndex
of the destination by the number of the transferred bytes whilegetBytes(int, Buffer, int, int)
does not. This method does not modifyreaderIndex
orwriterIndex
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 specifiedindex
is less than0
or ifindex + dst.writableBytes
is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method is basically same withgetBytes(int, Buffer, int, int)
, except that this method increases thewriterIndex
of the destination by the number of the transferred bytes whilegetBytes(int, Buffer, int, int)
does not. This method does not modifyreaderIndex
orwriterIndex
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 specifiedindex
is less than0
, ifindex + length
is greater thanthis.capacity
, or iflength
is greater thandst.writableBytes
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
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 destinationlength
- the number of bytes to transfer- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
, if the specifieddstIndex
is less than0
, ifindex + length
is greater thanthis.capacity
, or ifdstIndex + length
is greater thandst.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer- Parameters:
index
- absolute (@code index) in this buffer.dst
- the destination array.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
or ifindex + dst.length
is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.dst
- the destination array.dstIndex
- the first index of the destinationlength
- the number of bytes to transfer- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
, if the specifieddstIndex
is less than0
, ifindex + length
is greater thanthis.capacity
, or ifdstIndex + length
is greater thandst.length
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit. This method does not modifyreaderIndex
orwriterIndex
of this buffer while the destination'sposition
will be increased.- Parameters:
index
- absolute (@code index) in this buffer.dst
- the destination buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
or ifindex + dst.remaining()
is greater thanthis.capacity
-
setBoolean
Sets the specified boolean at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 1
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setByte
Sets the specified byte at the specified absoluteindex
in this buffer. The 24 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 1
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setShort
Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setShortLE
Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer with the Little Endian Byte Order. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setMedium
Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setMediumLE
Sets the specified 24-bit medium integer at the specified absoluteindex
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 modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 3
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setInt
Sets the specified 32-bit integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setIntLE
Sets the specified 32-bit integer at the specified absoluteindex
in this buffer with Little Endian byte order . This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setLong
Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setLongLE
Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setChar
Sets the specified 2-byte UTF-16 character at the specified absoluteindex
in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 2
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setFloat
Sets the specified 32-bit floating-point number at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 4
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setDouble
Sets the specified 64-bit floating-point number at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.value
- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
orindex + 8
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer becomes unreadable. This method is basically same withsetBytes(int, Buffer, int, int)
, except that this method increases thereaderIndex
of the source buffer by the number of the transferred bytes whilesetBytes(int, Buffer, int, int)
does not. This method does not modifyreaderIndex
orwriterIndex
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 specifiedindex
is less than0
or ifindex + src.readableBytes
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
. This method is basically same withsetBytes(int, Buffer, int, int)
, except that this method increases thereaderIndex
of the source buffer by the number of the transferred bytes whilesetBytes(int, Buffer, int, int)
does not. This method does not modifyreaderIndex
orwriterIndex
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 specifiedindex
is less than0
, ifindex + length
is greater thanthis.capacity
, or iflength
is greater thansrc.readableBytes
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
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 sourcelength
- the number of bytes to transfer- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
, if the specifiedsrcIndex
is less than0
, ifindex + length
is greater thanthis.capacity
, or ifsrcIndex + length
is greater thansrc.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.src
- the source array.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
or ifindex + src.length
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.src
- the source array.srcIndex
- the first index of the sourcelength
- the number of bytes to transfer- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
, if the specifiedsrcIndex
is less than0
, ifindex + length
is greater thanthis.capacity
, or ifsrcIndex + length
is greater thansrc.length
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer's position reaches its limit. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- absolute (@code index) in this buffer.src
- the source buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException
- if the specifiedindex
is less than0
or ifindex + src.remaining()
is greater thanthis.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
setBytes
Transfers a fixed amount from the specified sourceInputStream
's data to this buffer starting at the specified absoluteindex
untillength
bytes have been read, the end of stream is reached, or an exception is thrown.This method does not modify
readerIndex
orwriterIndex
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 specifiedindex
is less than0
or ifindex + src.remaining()
is greater thanthis.capacity
IOException
- if the InputStream throws an exception while being read from.ReadOnlyBufferException
- if this buffer is read-only
-
setBytesUntilEndStream
Transfers all the specified sourceInputStream
's data to this buffer starting at the specified absoluteindex
until the end of stream is reached or an exception is thrown.This method does not modify
readerIndex
orwriterIndex
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 fromsrc
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 specifiedindex
is less than0
or ifindex + src.remaining()
is greater thanthis.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 currentreaderIndex
and increases thereaderIndex
by1
in this buffer.- Returns:
- a boolean.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than1
-
readByte
byte readByte()Gets a byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than1
-
readUnsignedByte
short readUnsignedByte()Gets an unsigned byte at the currentreaderIndex
and increases thereaderIndex
by1
in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than1
-
readShort
short readShort()Gets a 16-bit short integer at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than2
-
readShortLE
short readShortLE()Gets a 16-bit short integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by2
in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than2
-
readUnsignedShort
int readUnsignedShort()Gets an unsigned 16-bit short integer at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than2
-
readUnsignedShortLE
int readUnsignedShortLE()Gets an unsigned 16-bit short integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by2
in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than2
-
readMedium
int readMedium()Gets a 24-bit medium integer at the currentreaderIndex
and increases thereaderIndex
by3
in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than3
-
readMediumLE
int readMediumLE()Gets a 24-bit medium integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by3
in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than3
-
readUnsignedMedium
int readUnsignedMedium()Gets an unsigned 24-bit medium integer at the currentreaderIndex
and increases thereaderIndex
by3
in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than3
-
readUnsignedMediumLE
int readUnsignedMediumLE()Gets an unsigned 24-bit medium integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by3
in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than3
-
readInt
int readInt()Gets a 32-bit integer at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than4
-
readIntLE
int readIntLE()Gets a 32-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by4
in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than4
-
readUnsignedInt
long readUnsignedInt()Gets an unsigned 32-bit integer at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than4
-
readUnsignedIntLE
long readUnsignedIntLE()Gets an unsigned 32-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by4
in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than4
-
readLong
long readLong()Gets a 64-bit integer at the currentreaderIndex
and increases thereaderIndex
by8
in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than8
-
readLongLE
long readLongLE()Gets a 64-bit integer at the currentreaderIndex
in the Little Endian Byte Order and increases thereaderIndex
by8
in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than8
-
readChar
char readChar()Gets a 2-byte UTF-16 character at the currentreaderIndex
and increases thereaderIndex
by2
in this buffer.- Returns:
- a char.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than2
-
readFloat
float readFloat()Gets a 32-bit floating point number at the currentreaderIndex
and increases thereaderIndex
by4
in this buffer.- Returns:
- a float.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than4
-
readDouble
double readDouble()Gets a 64-bit floating point number at the currentreaderIndex
and increases thereaderIndex
by8
in this buffer.- Returns:
- a double.
- Throws:
IndexOutOfBoundsException
- ifthis.readableBytes
is less than8
-
readSlice
Returns a new slice of this buffer's sub-region starting at the currentreaderIndex
and increases thereaderIndex
by the size of the new slice (=length
).- Parameters:
length
- the size of the new slice- Returns:
- the newly created slice
- Throws:
IndexOutOfBoundsException
- iflength
is greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to a newly created buffer starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
). The returned buffer'sreaderIndex
andwriterIndex
are0
andlength
respectively.- Parameters:
length
- the number of bytes to transfer- Returns:
- the newly created buffer which contains the transferred bytes
- Throws:
IndexOutOfBoundsException
- iflength
is greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
until the destination becomes non-writable, and increases thereaderIndex
by the number of the transferred bytes. This method is basically same withreadBytes(Buffer, int, int)
, except that this method increases thewriterIndex
of the destination by the number of the transferred bytes whilereadBytes(Buffer, int, int)
does not.- Parameters:
dst
- the destination buffer.- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- ifdst.writableBytes
is greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
). This method is basically same withreadBytes(Buffer, int, int)
, except that this method increases thewriterIndex
of the destination by the number of the transferred bytes (=length
) whilereadBytes(Buffer, int, int)
does not.- Parameters:
dst
- the destination buffer.length
- the number of bytes.- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- iflength
is greater thanthis.readableBytes
or iflength
is greater thandst.writableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).- Parameters:
dst
- the destination buffer.dstIndex
- the first index of the destinationlength
- the number of bytes to transfer- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- if the specifieddstIndex
is less than0
, iflength
is greater thanthis.readableBytes
, or ifdstIndex + length
is greater thandst.capacity
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=dst.length
).- Parameters:
dst
- the destination array.- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- ifdst.length
is greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
and increases thereaderIndex
by the number of the transferred bytes (=length
).- Parameters:
dst
- the destination array.dstIndex
- the first index of the destinationlength
- the number of bytes to transfer- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- if the specifieddstIndex
is less than0
, iflength
is greater thanthis.readableBytes
, or ifdstIndex + length
is greater thandst.length
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndex
until the destination's position reaches its limit, and increases thereaderIndex
by the number of the transferred bytes.- Parameters:
dst
- the destination buffer.- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- ifdst.remaining()
is less thanthis.readableBytes
-
skipBytes
Increases the currentreaderIndex
by the specifiedlength
in this buffer.- Parameters:
length
- number of bytes.- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- iflength
is greater thanthis.readableBytes
-
writeBoolean
Sets the specified boolean at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer. Ifthis.writableBytes
is less than1
,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
Sets the specified byte at the currentwriterIndex
and increases thewriterIndex
by1
in this buffer. The 24 high-order bits of the specified value are ignored. Ifthis.writableBytes
is less than1
,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
Sets the specified 16-bit short integer at the currentwriterIndex
and increases thewriterIndex
by2
in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytes
is less than2
,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
Sets the specified 16-bit short integer in the Little Endian Byte Order at the currentwriterIndex
and increases thewriterIndex
by2
in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytes
is less than2
,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
Sets the specified 24-bit medium integer at the currentwriterIndex
and increases thewriterIndex
by3
in this buffer. Ifthis.writableBytes
is less than3
,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
Sets the specified 24-bit medium integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by3
in this buffer. Ifthis.writableBytes
is less than3
,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
Sets the specified 32-bit integer at the currentwriterIndex
and increases thewriterIndex
by4
in this buffer. Ifthis.writableBytes
is less than4
,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
Sets the specified 32-bit integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by4
in this buffer. Ifthis.writableBytes
is less than4
,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
Sets the specified 64-bit long integer at the currentwriterIndex
and increases thewriterIndex
by8
in this buffer. Ifthis.writableBytes
is less than8
,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
Sets the specified 64-bit long integer at the currentwriterIndex
in the Little Endian Byte Order and increases thewriterIndex
by8
in this buffer. Ifthis.writableBytes
is less than8
,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
Sets the specified 2-byte UTF-16 character at the currentwriterIndex
and increases thewriterIndex
by2
in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytes
is less than2
,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
Sets the specified 32-bit floating point number at the currentwriterIndex
and increases thewriterIndex
by4
in this buffer. Ifthis.writableBytes
is less than4
,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
Sets the specified 64-bit floating point number at the currentwriterIndex
and increases thewriterIndex
by8
in this buffer. Ifthis.writableBytes
is less than8
,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
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
until the source buffer becomes unreadable, and increases thewriterIndex
by the number of the transferred bytes. This method is basically same withwriteBytes(Buffer, int, int)
, except that this method increases thereaderIndex
of the source buffer by the number of the transferred bytes whilewriteBytes(Buffer, int, int)
does not. Ifthis.writableBytes
is less thansrc.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
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
). This method is basically same withwriteBytes(Buffer, int, int)
, except that this method increases thereaderIndex
of the source buffer by the number of the transferred bytes (=length
) whilewriteBytes(Buffer, int, int)
does not. Ifthis.writableBytes
is less thanlength
,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
- iflength
is greater thensrc.readableBytes
ReadOnlyBufferException
- if this buffer is read-only
-
writeBytes
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
). Ifthis.writableBytes
is less thanlength
,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 sourcelength
- the number of bytes to transfer- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- if the specifiedsrcIndex
is less than0
, or ifsrcIndex + length
is greater thansrc.capacity
ReadOnlyBufferException
- if this buffer is read-only
-
writeBytes
Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=src.length
). Ifthis.writableBytes
is less thansrc.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
Transfers the specified source array's data to this buffer starting at the currentwriterIndex
and increases thewriterIndex
by the number of the transferred bytes (=length
). Ifthis.writableBytes
is less thanlength
,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 sourcelength
- the number of bytes to transfer- Returns:
- self.
- Throws:
IndexOutOfBoundsException
- if the specifiedsrcIndex
is less than0
, or ifsrcIndex + length
is greater thansrc.length
ReadOnlyBufferException
- if this buffer is read-only
-
writeBytes
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndex
until the source buffer's position reaches its limit, and increases thewriterIndex
by the number of the transferred bytes. Ifthis.writableBytes
is less thansrc.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
Transfers a fixed amount from the specified sourceInputStream
's data to this buffer starting at the currentwriterIndex
untillength
bytes have been read, the end of stream is reached, or an exception is thrown. Ifthis.writableBytes
is less thanlength
,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 sourceInputStream
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 theInputStream
throws an exception while being read from.ReadOnlyBufferException
- if this buffer is read-only
-
writeBytesUntilEndStream
Transfers all the specified sourceInputStream
's data to this buffer starting at the currentwriterIndex
until the end of stream is reached or an exception is thrown. Ifthis.writableBytes
is less than the number of bytes in theInputStream
,ensureWritable(int)
will be called in an attempt to expand capacity to accommodate. Note that becauseInputStream
does not provide a reliable way to get the remaining bytes, this method may over allocate by a factor ofchunkSize
.This method will increase the
writerIndex
by the number of the transferred bytes if the write operation was successful.- Parameters:
src
- the sourceInputStream
to write.chunkSize
- the amount of data that will be read fromsrc
on each read attempt.- Returns:
- the actual total number of bytes read in from
src
.-1
if no bytes were read because the specifiedInputStream
was closed when this method was called. - Throws:
IOException
- if theInputStream
throws an exception while being read from.ReadOnlyBufferException
- if this buffer is read-only
-
writeAscii
Encode aCharSequence
in ASCII and write it to this buffer starting atwriterIndex
and increases thewriterIndex
by the number of the transferred bytes. Ifthis.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
Encode aCharSequence
in UTF-8 and write it to this buffer starting atwriterIndex
and increases thewriterIndex
by the number of the transferred bytes. Ifthis.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
Encode aCharSequence
in UTF-8 and write it to this buffer starting atwriterIndex
and increases thewriterIndex
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
Encode aCharSequence
encoded inCharset
and write it to this buffer starting atwriterIndex
and increases thewriterIndex
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 specifiedvalue
in this buffer. The search takes place from the specifiedfromIndex
(inclusive) to the specifiedtoIndex
(exclusive).If
fromIndex
is greater thantoIndex
, the search is performed in a reversed order.This method does not modify
readerIndex
orwriterIndex
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 specifiedvalue
in this buffer. The search takes place from the currentreaderIndex
(inclusive) to the currentwriterIndex
(exclusive).This method does not modify
readerIndex
orwriterIndex
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 specifiedvalue
in this buffer. The search starts from the currentreaderIndex
(inclusive) and lasts for the specifiedlength
.This method does not modify
readerIndex
orwriterIndex
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
- iflength
is greater thanthis.readableBytes
-
bytesBefore
int bytesBefore(int index, int length, byte value) Locates the first occurrence of the specifiedvalue
in this buffer. The search starts from the specifiedindex
(inclusive) and lasts for the specifiedlength
.This method does not modify
readerIndex
orwriterIndex
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
- ifindex + length
is greater thanthis.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 tobuf.copy(buf.readerIndex(), buf.readableBytes())
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Returns:
- a copy of the buffer.
-
copy
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 modifyreaderIndex
orwriterIndex
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 tobuf.slice(buf.readerIndex(), buf.readableBytes())
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Returns:
- a sliced buffer.
-
slice
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 modifyreaderIndex
orwriterIndex
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 tobuf.slice(0, buf.capacity())
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Returns:
- a duplicated buffer.
-
nioBufferCount
int nioBufferCount()Returns the maximum number of NIOByteBuffer
s that consist this buffer. Note thattoNioBuffers()
ortoNioBuffers(int, int)
might return a less number ofByteBuffer
s.- Returns:
-1
if this buffer has no underlyingByteBuffer
. the number of the underlyingByteBuffer
s if this buffer has at least one underlyingByteBuffer
. Note that this method does not return0
to avoid confusion.- See Also:
-
toNioBuffer
ByteBuffer toNioBuffer()Exposes this buffer's readable bytes as an NIOByteBuffer
. 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 tobuf.nioBuffer(buf.readerIndex(), buf.readableBytes())
. This method does not modifyreaderIndex
orwriterIndex
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 aByteBuffer
that shares the content with itself- See Also:
-
toNioBuffer
Exposes this buffer's sub-region as an NIOByteBuffer
. 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 modifyreaderIndex
orwriterIndex
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 aByteBuffer
that shares the content with itself- See Also:
-
toNioBuffers
ByteBuffer[] toNioBuffers()Exposes this buffer's readable bytes as an NIOByteBuffer
'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 modifyreaderIndex
orwriterIndex
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 aByteBuffer
that shares the content with itself- See Also:
-
toNioBuffers
Exposes this buffer's bytes as an NIOByteBuffer
'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 modifyreaderIndex
orwriterIndex
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 aByteBuffer
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 throwReadOnlyBufferException
. Modifications for indexes are allowed and will be propagated to the originalBuffer
. To prevent changes of indexes for the originalBuffer
useduplicate()
before converting to a read-only view.- Returns:
- a buffer whose contents cannot be modified.
-
isDirect
boolean isDirect()Returnstrue
if the buffer is direct and so not allocated on the heap.- Returns:
true
if direct.
-
hasArray
boolean hasArray()Returnstrue
if and only if this buffer has a backing byte array. If this method returns true, you can safely callarray()
andarrayOffset()
.- 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()
returnstrue
before calling this method orUnsupportedOperationException
maybe thrown.Use
arrayOffset()
to get the starting point of data for this buffer. The returned array maybe shared and thisBuffer
's data may reside in a sub-section.- Returns:
- byte array.
- Throws:
UnsupportedOperationException
- if there no accessible backing byte arrayReadOnlyBufferException
- 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()
returnstrue
before calling this method orUnsupportedOperationException
maybe thrown.- Returns:
- the offset in the array.
- Throws:
UnsupportedOperationException
- if there no accessible backing byte arrayReadOnlyBufferException
- if this buffer is read-only- See Also:
-
forEachByte
Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.- Parameters:
processor
- theByteProcessor
to use.- Returns:
-1
if the processor iterated to or beyond the end of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByte
Iterates over the specified area of this buffer with the specifiedprocessor
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
- theByteProcessor
to use.- Returns:
-1
if the processor iterated to or beyond the end of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
Iterates over the readable bytes of this buffer with the specifiedprocessor
in descending order.- Parameters:
processor
- theByteProcessor
to use.- Returns:
-1
if the processor iterated to or beyond the beginning of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
Iterates over the specified area of this buffer with the specifiedprocessor
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
- theByteProcessor
to use.- Returns:
-1
if the processor iterated to or beyond the beginning of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
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. -
equals
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.
readerIndex()
norwriterIndex()
. This method also returnsfalse
fornull
and an object which is not an instance ofBuffer
type. -
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 asreaderIndex()
,writerIndex()
andcapacity()
. -
toString
Decodes this buffer's readable bytes into a string with the specified character set name. This method is identical tobuf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)
. This method does not modifyreaderIndex
orwriterIndex
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
Decodes this buffer's sub-region into a string with the specified character set. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Parameters:
index
- the start index.length
- the length.charset
- the charset to use.- Returns:
- the string.
-
asOutputStream
Return anOutputStream
that wraps the givenBuffer
. The writerIndex will be increased when writing to the buffer.- Parameters:
buffer
- the buffer to wrap.- Returns:
- a new
OutputStream
.
-
asInputStream
Return anInputStream
that wraps the givenBuffer
. The readerIndex will be increased when reading from the buffer.- Parameters:
buffer
- the buffer to wrap.- Returns:
- a new
InputStream
.
-