public interface Buffer
byte[]
) and NIO buffers
.Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Returns the backing byte array of this buffer.
|
int |
arrayOffset()
Returns the offset of the first byte within the backing byte array of
this buffer.
|
static java.io.InputStream |
asInputStream(Buffer buffer)
Return an
InputStream that wraps the given Buffer . |
static java.io.OutputStream |
asOutputStream(Buffer buffer)
Return an
OutputStream that wraps the given Buffer . |
Buffer |
asReadOnly()
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 |
capacity()
Returns the number of bytes (octets) this buffer can contain.
|
Buffer |
capacity(int newCapacity)
Sets the capacity of this buffer.
|
Buffer |
clear()
Sets the
readerIndex and writerIndex of this buffer to
0 . |
Buffer |
copy()
Returns a copy of this buffer's readable bytes.
|
Buffer |
copy(int index,
int length)
Returns a copy of this buffer's sub-region.
|
Buffer |
duplicate()
Returns a buffer which shares the whole region of this buffer.
|
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 |
equals(java.lang.Object obj)
Determines if the content of the specified buffer is identical to the
content of this array.
|
int |
forEachByte(ByteProcessor processor)
Iterates over the readable bytes of this buffer with the specified
processor in ascending order. |
int |
forEachByte(int index,
int length,
ByteProcessor processor)
Iterates over the specified area of this buffer with the specified
processor in ascending order. |
int |
forEachByteDesc(ByteProcessor processor)
Iterates over the readable bytes of this buffer with the specified
processor in descending order. |
int |
forEachByteDesc(int index,
int length,
ByteProcessor processor)
Iterates over the specified area 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. |
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. |
Buffer |
getBytes(int index,
Buffer dst,
int length)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index . |
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 . |
Buffer |
getBytes(int index,
byte[] dst)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index . |
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 . |
Buffer |
getBytes(int index,
java.nio.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 |
getUnsignedMediumLE(int index)
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 |
hasArray()
Returns
true 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 specified
value in this
buffer. |
boolean |
isDirect()
Returns
true if the buffer is direct and so not allocated on the heap. |
boolean |
isReadOnly()
Determine if this buffer is read-only.
|
int |
maxCapacity()
Returns the maximum allowed capacity of this buffer.
|
int |
maxWritableBytes()
Returns the maximum possible number of writable bytes, which is equal to
(this.maxCapacity - this.writerIndex) . |
int |
nioBufferCount()
Returns the maximum number of NIO
ByteBuffer s that consist this buffer. |
int |
readableBytes()
Returns the number of readable bytes which is equal to
(this.writerIndex - this.readerIndex) . |
boolean |
readBoolean()
Gets a boolean at the current
readerIndex and increases
the readerIndex by 1 in this buffer. |
byte |
readByte()
Gets a byte at the current
readerIndex and increases
the readerIndex by 1 in this buffer. |
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. |
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 ). |
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 ). |
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 ). |
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 ). |
Buffer |
readBytes(java.nio.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. |
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 ). |
char |
readChar()
Gets a 2-byte UTF-16 character at the current
readerIndex
and increases the readerIndex by 2 in this buffer. |
double |
readDouble()
Gets a 64-bit floating point number at the current
readerIndex
and increases the readerIndex by 8 in this buffer. |
int |
readerIndex()
Returns the
readerIndex of this buffer. |
Buffer |
readerIndex(int readerIndex)
Sets the
readerIndex of this buffer. |
float |
readFloat()
Gets a 32-bit floating point number at the current
readerIndex
and increases the readerIndex by 4 in this buffer. |
int |
readInt()
Gets a 32-bit integer at the current
readerIndex
and increases the readerIndex by 4 in this buffer. |
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. |
long |
readLong()
Gets a 64-bit integer at the current
readerIndex
and increases the readerIndex by 8 in this buffer. |
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. |
int |
readMedium()
Gets a 24-bit medium integer at the current
readerIndex
and increases the readerIndex by 3 in this buffer. |
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. |
short |
readShort()
Gets a 16-bit short integer at the current
readerIndex
and increases the readerIndex by 2 in this buffer. |
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. |
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 |
readUnsignedByte()
Gets an unsigned byte at the current
readerIndex and increases
the readerIndex by 1 in this buffer. |
long |
readUnsignedInt()
Gets an unsigned 32-bit integer at the current
readerIndex
and increases the readerIndex by 4 in this buffer. |
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. |
int |
readUnsignedMedium()
Gets an unsigned 24-bit medium integer at the current
readerIndex
and increases the readerIndex by 3 in this buffer. |
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. |
int |
readUnsignedShort()
Gets an unsigned 16-bit short integer at the current
readerIndex
and increases the readerIndex by 2 in this buffer. |
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. |
Buffer |
setBoolean(int index,
boolean value)
Sets the specified boolean at the specified absolute
index in this
buffer. |
Buffer |
setByte(int index,
int value)
Sets the specified byte at the specified absolute
index in this
buffer. |
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. |
Buffer |
setBytes(int index,
Buffer src,
int length)
Transfers the specified source buffer's data to this buffer starting at
the specified absolute
index . |
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 . |
Buffer |
setBytes(int index,
byte[] src)
Transfers the specified source array's data to this buffer starting at
the specified absolute
index . |
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 . |
Buffer |
setBytes(int index,
java.nio.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 |
setBytes(int index,
java.io.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. |
int |
setBytesUntilEndStream(int index,
java.io.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. |
Buffer |
setChar(int index,
int value)
Sets the specified 2-byte UTF-16 character at the specified absolute
index in this buffer. |
Buffer |
setDouble(int index,
double value)
Sets the specified 64-bit floating-point number at the specified
absolute
index in this buffer. |
Buffer |
setFloat(int index,
float value)
Sets the specified 32-bit floating-point number at the specified
absolute
index in this buffer. |
Buffer |
setInt(int index,
int value)
Sets the specified 32-bit integer at the specified absolute
index in this buffer. |
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
. |
Buffer |
setLong(int index,
long value)
Sets the specified 64-bit long integer at the specified absolute
index in this buffer. |
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. |
Buffer |
setMedium(int index,
int value)
Sets the specified 24-bit medium integer at the specified absolute
index in this buffer. |
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. |
Buffer |
setShort(int index,
int value)
Sets the specified 16-bit short integer at the specified absolute
index in this buffer. |
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. |
Buffer |
skipBytes(int length)
Increases the current
readerIndex by the specified
length in this buffer. |
Buffer |
slice()
Returns a slice of this buffer's readable bytes.
|
Buffer |
slice(int index,
int length)
Returns a slice of this buffer's sub-region.
|
java.nio.ByteBuffer |
toNioBuffer()
Exposes this buffer's readable bytes as an NIO
ByteBuffer . |
java.nio.ByteBuffer |
toNioBuffer(int index,
int length)
Exposes this buffer's sub-region as an NIO
ByteBuffer . |
java.nio.ByteBuffer[] |
toNioBuffers()
Exposes this buffer's readable bytes as an NIO
ByteBuffer 's. |
java.nio.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. |
java.lang.String |
toString()
Returns the string representation of this buffer.
|
java.lang.String |
toString(java.nio.charset.Charset charset)
Decodes this buffer's readable bytes into a string with the specified
character set name.
|
java.lang.String |
toString(int index,
int length,
java.nio.charset.Charset charset)
Decodes this buffer's sub-region into a string with the specified
character set.
|
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 |
writableBytes()
Returns the number of writable bytes which is equal to
(this.capacity - this.writerIndex) . |
Buffer |
writeAscii(java.lang.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. |
Buffer |
writeBoolean(boolean value)
Sets the specified boolean at the current
writerIndex
and increases the writerIndex by 1 in this buffer. |
Buffer |
writeByte(int value)
Sets the specified byte at the current
writerIndex
and increases the writerIndex by 1 in this buffer. |
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. |
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 ). |
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 ). |
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 ). |
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 ). |
Buffer |
writeBytes(java.nio.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. |
int |
writeBytes(java.io.InputStream src,
int length)
Transfers ta 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. |
int |
writeBytesUntilEndStream(java.io.InputStream src,
int chunkSize)
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. |
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. |
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. |
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. |
Buffer |
writeInt(int value)
Sets the specified 32-bit integer at the current
writerIndex
and increases the writerIndex by 4 in this buffer. |
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. |
Buffer |
writeLong(long value)
Sets the specified 64-bit long integer at the current
writerIndex and increases the writerIndex by 8
in this buffer. |
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. |
Buffer |
writeMedium(int value)
Sets the specified 24-bit medium integer at the current
writerIndex and increases the writerIndex by 3
in this buffer. |
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 |
writerIndex()
Returns the
writerIndex of this buffer. |
Buffer |
writerIndex(int writerIndex)
Sets the
writerIndex of this buffer. |
Buffer |
writeShort(int value)
Sets the specified 16-bit short integer at the current
writerIndex and increases the writerIndex by 2
in this buffer. |
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. |
Buffer |
writeUtf8(java.lang.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. |
Buffer |
writeUtf8(java.lang.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. |
int capacity()
Buffer capacity(int newCapacity)
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)
.newCapacity
- the new capacity.java.lang.IllegalArgumentException
- if the newCapacity
is greater than maxCapacity()
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint maxCapacity()
capacity()
.int readerIndex()
readerIndex
of this buffer.readerIndex
of this buffer.Buffer readerIndex(int readerIndex)
readerIndex
of this buffer.readerIndex
- the new readerIndex of this buffer.java.lang.IndexOutOfBoundsException
- if the specified readerIndex
is
less than 0
or
greater than this.writerIndex
int writerIndex()
writerIndex
of this buffer.writerIndex
of this buffer.Buffer writerIndex(int writerIndex)
writerIndex
of this buffer.writerIndex
- the new writerIndex of this buffer.java.lang.IndexOutOfBoundsException
- if the specified writerIndex
is
less than this.readerIndex
or
greater than this.capacity
int readableBytes()
(this.writerIndex - this.readerIndex)
.int writableBytes()
(this.capacity - this.writerIndex)
.int maxWritableBytes()
(this.maxCapacity - this.writerIndex)
.Buffer ensureWritable(int minWritableBytes)
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.minWritableBytes
- the expected minimum number of writable bytesjava.lang.IndexOutOfBoundsException
- if writerIndex()
+ minWritableBytes
> maxCapacity()
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint ensureWritable(int minWritableBytes, boolean force)
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.minWritableBytes
- the expected minimum number of writable bytesforce
- When writerIndex()
+ minWritableBytes
> maxCapacity()
:
true
- the capacity of the buffer is expanded to maxCapacity()
false
- the capacity of the buffer is unchanged0
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.default boolean tryEnsureWritable(int minWritableBytes, boolean force)
ensureWritable(int)
,
this method does not raise an exception but returns a status code.minWritableBytes
- the expected minimum number of writable bytesforce
- When writerIndex()
+ minWritableBytes
> maxCapacity()
:
true
- the capacity of the buffer is expanded to maxCapacity()
false
- the capacity of the buffer is unchangedtrue
if this Buffer
has at least minWritableBytes
writable bytes after this call.Buffer clear()
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.
boolean getBoolean(int index)
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
byte getByte(int index)
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
short getUnsignedByte(int index)
index
in this
buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
short getShort(int index)
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
short getShortLE(int index)
index
in
this buffer in Little Endian Byte Order. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
int getUnsignedShort(int index)
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
int getUnsignedShortLE(int index)
index
in this buffer in Little Endian Byte Order.
This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
int getMedium(int index)
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
int getMediumLE(int index)
index
in
this buffer in the Little Endian Byte Order. This method does not
modify readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
int getUnsignedMedium(int index)
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
int getUnsignedMediumLE(int index)
index
in this buffer in Little Endian Byte Order.
This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
int getInt(int index)
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
int getIntLE(int index)
index
in
this buffer with Little Endian Byte Order. This method does not
modify readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
long getUnsignedInt(int index)
index
in this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
long getUnsignedIntLE(int index)
index
in this buffer in Little Endian Byte Order. This method does not
modify readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
long getLong(int index)
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
long getLongLE(int index)
index
in
this buffer in Little Endian Byte Order. This method does not
modify readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
char getChar(int index)
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
float getFloat(int index)
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
double getDouble(int index)
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
Buffer getBytes(int index, Buffer dst)
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
).index
- absolute (@code index) in this buffer.dst
- the destination buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + dst.writableBytes
is greater than
this.capacity
Buffer getBytes(int index, Buffer dst, int length)
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
).index
- absolute (@code index) in this buffer.dst
- the destination buffer.length
- the number of bytes to transferjava.lang.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
Buffer getBytes(int index, Buffer dst, int dstIndex, int length)
index
.
This method does not modify readerIndex
or writerIndex
of both the source (i.e. this
) and the destination.index
- absolute (@code index) in this buffer.dst
- the destination buffer.dstIndex
- the first index of the destinationlength
- the number of bytes to transferjava.lang.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
Buffer getBytes(int index, byte[] dst)
index
.
This method does not modify readerIndex
or writerIndex
of
this bufferindex
- absolute (@code index) in this buffer.dst
- the destination array.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + dst.length
is greater than
this.capacity
Buffer getBytes(int index, byte[] dst, int dstIndex, int length)
index
.
This method does not modify readerIndex
or writerIndex
of this buffer.index
- absolute (@code index) in this buffer.dst
- the destination array.dstIndex
- the first index of the destinationlength
- the number of bytes to transferjava.lang.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
Buffer getBytes(int index, java.nio.ByteBuffer dst)
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.index
- absolute (@code index) in this buffer.dst
- the destination buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + dst.remaining()
is greater than
this.capacity
Buffer setBoolean(int index, boolean value)
index
in this
buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setByte(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setShort(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setShortLE(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setMedium(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setMediumLE(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 3
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setInt(int index, int value)
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setIntLE(int index, int value)
index
in this buffer with Little Endian byte order
.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setLong(int index, long value)
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setLongLE(int index, long value)
index
in this buffer in Little Endian Byte Order.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setChar(int index, int value)
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.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setFloat(int index, float value)
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setDouble(int index, double value)
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.value
- the value.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, Buffer src)
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
).index
- absolute (@code index) in this buffer.src
- the source buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.readableBytes
is greater than
this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, Buffer src, int length)
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
).index
- absolute (@code index) in this buffer.src
- the source buffer.length
- the number of bytes to transferjava.lang.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
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, Buffer src, int srcIndex, int length)
index
.
This method does not modify readerIndex
or writerIndex
of both the source (i.e. this
) and the destination.index
- absolute (@code index) in this buffer.src
- the source buffer.srcIndex
- the first index of the sourcelength
- the number of bytes to transferjava.lang.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
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, byte[] src)
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.src
- the source array.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.length
is greater than
this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, byte[] src, int srcIndex, int length)
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.src
- the source array.srcIndex
- the first index of the sourcelength
- the number of bytes to transferjava.lang.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
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer setBytes(int index, java.nio.ByteBuffer src)
index
until the source buffer's position
reaches its limit.
This method does not modify readerIndex
or writerIndex
of
this buffer.index
- absolute (@code index) in this buffer.src
- the source buffer.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.remaining()
is greater than
this.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint setBytes(int index, java.io.InputStream src, int length) throws java.io.IOException
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.
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.src
.
-1
if the specified channel is closed.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.remaining()
is greater than
this.capacity
java.io.IOException
- if the InputStream throws an exception while being read from.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint setBytesUntilEndStream(int index, java.io.InputStream src, int chunkSize) throws java.io.IOException
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.
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.src
.
-1
if no bytes were read because the specified InputStream was closed when this method was called.java.lang.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.remaining()
is greater than
this.capacity
java.io.IOException
- if the InputStream throws an exception while being read from.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyboolean readBoolean()
readerIndex
and increases
the readerIndex
by 1
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 1
byte readByte()
readerIndex
and increases
the readerIndex
by 1
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 1
short readUnsignedByte()
readerIndex
and increases
the readerIndex
by 1
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 1
short readShort()
readerIndex
and increases the readerIndex
by 2
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 2
short readShortLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 2
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 2
int readUnsignedShort()
readerIndex
and increases the readerIndex
by 2
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 2
int readUnsignedShortLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 2
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 2
int readMedium()
readerIndex
and increases the readerIndex
by 3
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 3
int readMediumLE()
readerIndex
in the Little Endian Byte Order and increases the
readerIndex
by 3
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 3
int readUnsignedMedium()
readerIndex
and increases the readerIndex
by 3
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 3
int readUnsignedMediumLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 3
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 3
int readInt()
readerIndex
and increases the readerIndex
by 4
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 4
int readIntLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 4
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 4
long readUnsignedInt()
readerIndex
and increases the readerIndex
by 4
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 4
long readUnsignedIntLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 4
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 4
long readLong()
readerIndex
and increases the readerIndex
by 8
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 8
long readLongLE()
readerIndex
in the Little Endian Byte Order and increases the readerIndex
by 8
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 8
char readChar()
readerIndex
and increases the readerIndex
by 2
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 2
float readFloat()
readerIndex
and increases the readerIndex
by 4
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 4
double readDouble()
readerIndex
and increases the readerIndex
by 8
in this buffer.java.lang.IndexOutOfBoundsException
- if this.readableBytes
is less than 8
Buffer readSlice(int length)
readerIndex
and increases the readerIndex
by the size
of the new slice (= length
).length
- the size of the new slicejava.lang.IndexOutOfBoundsException
- if length
is greater than this.readableBytes
Buffer readBytes(int length)
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.length
- the number of bytes to transferjava.lang.IndexOutOfBoundsException
- if length
is greater than this.readableBytes
Buffer readBytes(Buffer dst)
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.dst
- the destination buffer.java.lang.IndexOutOfBoundsException
- if dst.writableBytes
is greater than
this.readableBytes
Buffer readBytes(Buffer dst, int length)
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.dst
- the destination buffer.length
- the number of bytes.java.lang.IndexOutOfBoundsException
- if length
is greater than this.readableBytes
or
if length
is greater than dst.writableBytes
Buffer readBytes(Buffer dst, int dstIndex, int length)
readerIndex
and increases the readerIndex
by the number of the transferred bytes (= length
).dst
- the destination buffer.dstIndex
- the first index of the destinationlength
- the number of bytes to transferjava.lang.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
Buffer readBytes(byte[] dst)
readerIndex
and increases the readerIndex
by the number of the transferred bytes (= dst.length
).dst
- the destination array.java.lang.IndexOutOfBoundsException
- if dst.length
is greater than this.readableBytes
Buffer readBytes(byte[] dst, int dstIndex, int length)
readerIndex
and increases the readerIndex
by the number of the transferred bytes (= length
).dst
- the destination array.dstIndex
- the first index of the destinationlength
- the number of bytes to transferjava.lang.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
Buffer readBytes(java.nio.ByteBuffer dst)
readerIndex
until the destination's position
reaches its limit, and increases the readerIndex
by the
number of the transferred bytes.dst
- the destination buffer.java.lang.IndexOutOfBoundsException
- if dst.remaining()
is less than
this.readableBytes
Buffer skipBytes(int length)
readerIndex
by the specified
length
in this buffer.length
- number of bytes.java.lang.IndexOutOfBoundsException
- if length
is greater than this.readableBytes
Buffer writeBoolean(boolean value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeByte(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeShort(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeShortLE(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeMedium(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeMediumLE(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeInt(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeIntLE(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeLong(long value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeLongLE(long value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeChar(int value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeFloat(float value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeDouble(double value)
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.value
- the value to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(Buffer src)
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.src
- the buffer to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(Buffer src, int length)
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.src
- the buffer to write.length
- the number of bytes to transferjava.lang.IndexOutOfBoundsException
- if length
is greater then src.readableBytes
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(Buffer src, int srcIndex, int length)
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.src
- the buffer to write.srcIndex
- the first index of the sourcelength
- the number of bytes to transferjava.lang.IndexOutOfBoundsException
- if the specified srcIndex
is less than 0
, or
if srcIndex + length
is greater than src.capacity
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(byte[] src)
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.src
- the array to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(byte[] src, int srcIndex, int length)
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.src
- the array to write.srcIndex
- the first index of the sourcelength
- the number of bytes to transferjava.lang.IndexOutOfBoundsException
- if the specified srcIndex
is less than 0
, or
if srcIndex + length
is greater than src.length
java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeBytes(java.nio.ByteBuffer src)
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.src
- the source buffer to write.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint writeBytes(java.io.InputStream src, int length) throws java.io.IOException
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.
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.src
.
-1
if the specified channel is closed.java.io.IOException
- if the InputStream
throws an exception while being read from.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint writeBytesUntilEndStream(java.io.InputStream src, int chunkSize) throws java.io.IOException
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.
src
- the source InputStream
to write.chunkSize
- the amount of data that will be read from src
on each read attempt.src
.
-1
if no bytes were read because the specified InputStream
was closed when this method
was called.java.io.IOException
- if the InputStream
throws an exception while being read from.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeAscii(java.lang.CharSequence seq)
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.seq
- the source of the data.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeUtf8(java.lang.CharSequence seq)
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.seq
- the source of the data.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyBuffer writeUtf8(java.lang.CharSequence seq, int ensureWritable)
CharSequence
in UTF-8 and write it
to this buffer starting at writerIndex
and increases the writerIndex
by the
number of the transferred bytes.seq
- the source of the data.ensureWritable
- the number of bytes to ensure are writeable.java.nio.ReadOnlyBufferException
- if this buffer is read-onlyint indexOf(int fromIndex, int toIndex, byte value)
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.
fromIndex
- the start index.toIndex
- the end index.value
- the value to search.-1
otherwise.int bytesBefore(byte value)
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.
value
- the value to search.readerIndex
and the first occurrence if found. -1
otherwise.int bytesBefore(int length, byte value)
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.
length
- the length.value
- the value to search.readerIndex
and the first occurrence if found. -1
otherwise.java.lang.IndexOutOfBoundsException
- if length
is greater than this.readableBytes
int bytesBefore(int index, int length, byte value)
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.
index
- the index.length
- the length.value
- the value to search.index
and the first occurrence if found. -1
otherwise.java.lang.IndexOutOfBoundsException
- if index + length
is greater than this.capacity
Buffer copy()
buf.copy(buf.readerIndex(), buf.readableBytes())
.
This method does not modify readerIndex
or writerIndex
of
this buffer.Buffer copy(int index, int length)
readerIndex
or writerIndex
of
this buffer.index
- the start index.length
- the length.Buffer slice()
buf.slice(buf.readerIndex(), buf.readableBytes())
.
This method does not modify readerIndex
or writerIndex
of
this buffer.Buffer slice(int index, int length)
readerIndex
or writerIndex
of
this buffer.index
- the start index.length
- the length.Buffer duplicate()
buf.slice(0, buf.capacity())
.
This method does not modify readerIndex
or writerIndex
of
this buffer.int nioBufferCount()
ByteBuffer
s that consist this buffer. Note that
toNioBuffers()
or toNioBuffers(int, int)
might return a less number of ByteBuffer
s.-1
if this buffer has no underlying ByteBuffer
.
the number of the underlying ByteBuffer
s if this buffer has at least one underlying
ByteBuffer
. Note that this method does not return 0
to avoid confusion.toNioBuffer()
,
toNioBuffer(int, int)
,
toNioBuffers()
,
toNioBuffers(int, int)
java.nio.ByteBuffer toNioBuffer()
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.java.lang.UnsupportedOperationException
- if this buffer cannot create a ByteBuffer
that shares the content with itselfnioBufferCount()
,
toNioBuffers()
,
toNioBuffers(int, int)
java.nio.ByteBuffer toNioBuffer(int index, int length)
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.index
- the start index.length
- the length.java.lang.UnsupportedOperationException
- if this buffer cannot create a ByteBuffer
that shares the content with itselfnioBufferCount()
,
toNioBuffers()
,
toNioBuffers(int, int)
java.nio.ByteBuffer[] toNioBuffers()
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.java.lang.UnsupportedOperationException
- if this buffer cannot create a ByteBuffer
that shares the content with itselfnioBufferCount()
,
toNioBuffer()
,
toNioBuffer(int, int)
java.nio.ByteBuffer[] toNioBuffers(int index, int length)
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.index
- the start index.length
- the length.java.lang.UnsupportedOperationException
- if this buffer cannot create a ByteBuffer
that shares the content with itselfnioBufferCount()
,
toNioBuffer()
,
toNioBuffer(int, int)
boolean isReadOnly()
true
if and only if this buffer is read-only.Buffer asReadOnly()
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.
boolean isDirect()
true
if the buffer is direct and so not allocated on the heap.true
if direct.boolean hasArray()
true
if and only if this buffer has a backing byte array.
If this method returns true, you can safely call array()
and
arrayOffset()
.true
if backed by an byte array and is not read-onlybyte[] array()
java.lang.UnsupportedOperationException
- if there no accessible backing byte arrayjava.nio.ReadOnlyBufferException
- if this buffer is read-onlyint arrayOffset()
java.lang.UnsupportedOperationException
- if there no accessible backing byte arrayjava.nio.ReadOnlyBufferException
- if this buffer is read-onlyint forEachByte(ByteProcessor processor)
processor
in ascending order.processor
- the ByteProcessor
to use.-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
.int forEachByte(int index, int length, ByteProcessor processor)
processor
in ascending order.
(i.e. index
, (index + 1)
, .. (index + length - 1)
)index
- The index to start iterating from.length
- The amount of bytes to iterate over.processor
- the ByteProcessor
to use.-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
.int forEachByteDesc(ByteProcessor processor)
processor
in descending order.processor
- the ByteProcessor
to use.-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
.int forEachByteDesc(int index, int length, ByteProcessor processor)
processor
in descending order.
(i.e. (index + length - 1)
, (index + length - 2)
, ... index
)index
- The index to start iterating from.length
- The amount of bytes to iterate over.processor
- the ByteProcessor
to use.-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
.int hashCode()
hashCode
in class java.lang.Object
boolean equals(java.lang.Object obj)
readerIndex()
nor
writerIndex()
. This method also returns false
for
null
and an object which is not an instance of
Buffer
type.equals
in class java.lang.Object
java.lang.String toString()
readerIndex()
,
writerIndex()
and capacity()
.toString
in class java.lang.Object
java.lang.String toString(java.nio.charset.Charset charset)
buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)
.
This method does not modify readerIndex
or writerIndex
of
this buffer.charset
- the charset to use.java.nio.charset.UnsupportedCharsetException
- if the specified character set name is not supported by the
current VMjava.lang.String toString(int index, int length, java.nio.charset.Charset charset)
readerIndex
or
writerIndex
of this buffer.index
- the start index.length
- the length.charset
- the charset to use.static java.io.OutputStream asOutputStream(Buffer buffer)
OutputStream
that wraps the given Buffer
. The writerIndex will be increased when
writing to the buffer.buffer
- the buffer to wrap.OutputStream
.