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.intReturns the offset of the first byte within the backing byte array of this buffer.static InputStreamasInputStream(Buffer buffer) Return anInputStreamthat wraps the givenBuffer.static OutputStreamasOutputStream(Buffer buffer) Return anOutputStreamthat wraps the givenBuffer.Create a read-only view for this buffer.intbytesBefore(byte value) Locates the first occurrence of the specifiedvaluein this buffer.intbytesBefore(int length, byte value) Locates the first occurrence of the specifiedvaluein this buffer.intbytesBefore(int index, int length, byte value) Locates the first occurrence of the specifiedvaluein this buffer.intcapacity()Returns the number of bytes (octets) this buffer can contain.capacity(int newCapacity) Sets the capacity of this buffer.clear()Sets thereaderIndexandwriterIndexof 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.intensureWritable(int minWritableBytes, boolean force) Expands the buffercapacity()to make sure the number of writable bytes is equal to or greater than the specified value.booleanDetermines if the content of the specified buffer is identical to the content of this array.intforEachByte(int index, int length, ByteProcessor processor) Iterates over the specified area of this buffer with the specifiedprocessorin ascending order.intforEachByte(ByteProcessor processor) Iterates over the readable bytes of this buffer with the specifiedprocessorin ascending order.intforEachByteDesc(int index, int length, ByteProcessor processor) Iterates over the specified area of this buffer with the specifiedprocessorin descending order.intforEachByteDesc(ByteProcessor processor) Iterates over the readable bytes of this buffer with the specifiedprocessorin descending order.booleangetBoolean(int index) Gets a boolean at the specified absolute (@code index) in this buffer.bytegetByte(int index) Gets a byte at the specified absoluteindexin 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 absoluteindexuntil 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 absoluteindexuntil the destination's position reaches its limit.chargetChar(int index) Gets a 2-byte UTF-16 character at the specified absoluteindexin this buffer.doublegetDouble(int index) Gets a 64-bit floating point number at the specified absoluteindexin this buffer.floatgetFloat(int index) Gets a 32-bit floating point number at the specified absoluteindexin this buffer.intgetInt(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer.intgetIntLE(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer with Little Endian Byte Order.longgetLong(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer.longgetLongLE(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetMedium(int index) Gets a 24-bit medium integer at the specified absoluteindexin this buffer.intgetMediumLE(int index) Gets a 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order.shortgetShort(int index) Gets a 16-bit short integer at the specified absoluteindexin this buffer.shortgetShortLE(int index) Gets a 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.shortgetUnsignedByte(int index) Gets an unsigned byte at the specified absoluteindexin this buffer.longgetUnsignedInt(int index) Gets an unsigned 32-bit integer at the specified absoluteindexin this buffer.longgetUnsignedIntLE(int index) Gets an unsigned 32-bit integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetUnsignedMedium(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer.intgetUnsignedMediumLE(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer in Little Endian Byte Order.intgetUnsignedShort(int index) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer.intgetUnsignedShortLE(int index) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order.booleanhasArray()Returnstrueif and only if this buffer has a backing byte array.inthashCode()Returns a hash code which was calculated from the content of this buffer.intindexOf(int fromIndex, int toIndex, byte value) Locates the first occurrence of the specifiedvaluein this buffer.booleanisDirect()Returnstrueif the buffer is direct and so not allocated on the heap.booleanDetermine if this buffer is read-only.intReturns the maximum allowed capacity of this buffer.intReturns the maximum possible number of writable bytes, which is equal to(this.maxCapacity - this.writerIndex).intReturns the maximum number of NIOByteBuffers that consist this buffer.intReturns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex).booleanGets a boolean at the currentreaderIndexand increases thereaderIndexby1in this buffer.bytereadByte()Gets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.readBytes(byte[] dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby 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 currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).readBytes(int length) Transfers this buffer's data to a newly created buffer starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination becomes non-writable, and increases thereaderIndexby the number of the transferred bytes.Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).readBytes(ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination's position reaches its limit, and increases thereaderIndexby the number of the transferred bytes.charreadChar()Gets a 2-byte UTF-16 character at the currentreaderIndexand increases thereaderIndexby2in this buffer.doubleGets a 64-bit floating point number at the currentreaderIndexand increases thereaderIndexby8in this buffer.intReturns thereaderIndexof this buffer.readerIndex(int readerIndex) Sets thereaderIndexof this buffer.floatGets a 32-bit floating point number at the currentreaderIndexand increases thereaderIndexby4in this buffer.intreadInt()Gets a 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.intGets a 32-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby4in this buffer.longreadLong()Gets a 64-bit integer at the currentreaderIndexand increases thereaderIndexby8in this buffer.longGets a 64-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby8in this buffer.intGets a 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.intGets a 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.shortGets a 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.shortGets a 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.readSlice(int length) Returns a new slice of this buffer's sub-region starting at the currentreaderIndexand increases thereaderIndexby the size of the new slice (=length).shortGets an unsigned byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.longGets an unsigned 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.longGets an unsigned 32-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby4in this buffer.intGets an unsigned 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.intGets an unsigned 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.intGets an unsigned 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.intGets an unsigned 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.setBoolean(int index, boolean value) Sets the specified boolean at the specified absoluteindexin this buffer.setByte(int index, int value) Sets the specified byte at the specified absoluteindexin 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 absoluteindexuntil 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.intsetBytes(int index, InputStream src, int length) Transfers a fixed amount from the specified sourceInputStream's data to this buffer starting at the specified absoluteindexuntillengthbytes 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 absoluteindexuntil the source buffer's position reaches its limit.intsetBytesUntilEndStream(int index, InputStream src, int chunkSize) Transfers all the specified sourceInputStream's data to this buffer starting at the specified absoluteindexuntil 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 absoluteindexin this buffer.setDouble(int index, double value) Sets the specified 64-bit floating-point number at the specified absoluteindexin this buffer.setFloat(int index, float value) Sets the specified 32-bit floating-point number at the specified absoluteindexin this buffer.setInt(int index, int value) Sets the specified 32-bit integer at the specified absoluteindexin this buffer.setIntLE(int index, int value) Sets the specified 32-bit integer at the specified absoluteindexin this buffer with Little Endian byte order .setLong(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.setLongLE(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order.setMedium(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer.setMediumLE(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order.setShort(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindexin this buffer.setShortLE(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindexin this buffer with the Little Endian Byte Order.skipBytes(int length) Increases the currentreaderIndexby the specifiedlengthin 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 booleantryEnsureWritable(int minWritableBytes, boolean force) Tries to make sure the number of writable bytes is equal to or greater than the specified value.intReturns the number of writable bytes which is equal to(this.capacity - this.writerIndex).writeAscii(CharSequence seq) Encode aCharSequencein ASCII and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes.writeBoolean(boolean value) Sets the specified boolean at the currentwriterIndexand increases thewriterIndexby1in this buffer.writeByte(int value) Sets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer.writeBytes(byte[] src) Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby 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 currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).writeBytes(Buffer src) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer becomes unreadable, and increases thewriterIndexby the number of the transferred bytes.writeBytes(Buffer src, int length) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby 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 currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).intwriteBytes(InputStream src, int length) Transfers a fixed amount from the specified sourceInputStream's data to this buffer starting at the currentwriterIndexuntillengthbytes 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 currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes.intwriteBytesUntilEndStream(InputStream src, int chunkSize) Transfers all the specified sourceInputStream's data to this buffer starting at the currentwriterIndexuntil the end of stream is reached or an exception is thrown.writeChar(int value) Sets the specified 2-byte UTF-16 character at the currentwriterIndexand increases thewriterIndexby2in this buffer.default BufferwriteCharSequence(CharSequence seq, Charset charset) Encode aCharSequenceencoded inCharsetand write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes.writeDouble(double value) Sets the specified 64-bit floating point number at the currentwriterIndexand increases thewriterIndexby8in this buffer.writeFloat(float value) Sets the specified 32-bit floating point number at the currentwriterIndexand increases thewriterIndexby4in this buffer.writeInt(int value) Sets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.writeIntLE(int value) Sets the specified 32-bit integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby4in this buffer.writeLong(long value) Sets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.writeLongLE(long value) Sets the specified 64-bit long integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby8in this buffer.writeMedium(int value) Sets the specified 24-bit medium integer at the currentwriterIndexand increases thewriterIndexby3in this buffer.writeMediumLE(int value) Sets the specified 24-bit medium integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby3in this buffer.intReturns thewriterIndexof this buffer.writerIndex(int writerIndex) Sets thewriterIndexof this buffer.writeShort(int value) Sets the specified 16-bit short integer at the currentwriterIndexand increases thewriterIndexby2in this buffer.writeShortLE(int value) Sets the specified 16-bit short integer in the Little Endian Byte Order at the currentwriterIndexand increases thewriterIndexby2in this buffer.writeUtf8(CharSequence seq) Encode aCharSequencein UTF-8 and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes.writeUtf8(CharSequence seq, int ensureWritable) Encode aCharSequencein UTF-8 and write it to this buffer starting atwriterIndexand increases thewriterIndexby 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 thenewCapacityis less than the current capacity, the content of this buffer is truncated. If thenewCapacityis 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 thenewCapacityis 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 thereaderIndexof this buffer.- Returns:
- the
readerIndexof this buffer.
-
readerIndex
Sets thereaderIndexof this buffer.- Parameters:
readerIndex- the new readerIndex of this buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedreaderIndexis less than0or greater thanthis.writerIndex
-
writerIndex
int writerIndex()Returns thewriterIndexof this buffer.- Returns:
- the
writerIndexof this buffer.
-
writerIndex
Sets thewriterIndexof this buffer.- Parameters:
writerIndex- the new writerIndex of this buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedwriterIndexis less thanthis.readerIndexor 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:
0if the buffer has enough writable bytes, and its capacity is unchanged.1if the buffer does not have enough bytes, and its capacity is unchanged.2if the buffer has enough writable bytes, and its capacity has been increased.3if 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:
trueif thisBufferhas at leastminWritableByteswritable bytes after this call.
-
clear
Buffer clear()Sets thereaderIndexandwriterIndexof this buffer to0.Please note that the behavior of this method is different from that of NIO buffer, which sets the
limitto thecapacityof 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 thereaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a boolean.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
getByte
byte getByte(int index) Gets a byte at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
getUnsignedByte
short getUnsignedByte(int index) Gets an unsigned byte at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- an unsigned byte.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacity
-
getShort
short getShort(int index) Gets a 16-bit short integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getShortLE
short getShortLE(int index) Gets a 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getUnsignedShort
int getUnsignedShort(int index) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getUnsignedShortLE
int getUnsignedShortLE(int index) Gets an unsigned 16-bit short integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getMedium
int getMedium(int index) Gets a 24-bit medium integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacity
-
getMediumLE
int getMediumLE(int index) Gets a 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacity
-
getUnsignedMedium
int getUnsignedMedium(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a medium in.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacity
-
getUnsignedMediumLE
int getUnsignedMediumLE(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacity
-
getInt
int getInt(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getIntLE
int getIntLE(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer with Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getUnsignedInt
long getUnsignedInt(int index) Gets an unsigned 32-bit integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a unsigned int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getUnsignedIntLE
long getUnsignedIntLE(int index) Gets an unsigned 32-bit integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a unsigned int.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getLong
long getLong(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
getLongLE
long getLongLE(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
getChar
char getChar(int index) Gets a 2-byte UTF-16 character at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a char.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacity
-
getFloat
float getFloat(int index) Gets a 32-bit floating point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a float.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacity
-
getDouble
double getDouble(int index) Gets a 64-bit floating point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.- Returns:
- a double.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination becomes non-writable. This method is basically same withgetBytes(int, Buffer, int, int), except that this method increases thewriterIndexof the destination by the number of the transferred bytes whilegetBytes(int, Buffer, int, int)does not. This method does not modifyreaderIndexorwriterIndexof the source buffer (i.e.this).- Parameters:
index- absolute (@code index) in this buffer.dst- the destination buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.writableBytesis 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 thewriterIndexof the destination by the number of the transferred bytes whilegetBytes(int, Buffer, int, int)does not. This method does not modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, ifindex + lengthis greater thanthis.capacity, or iflengthis greater thandst.writableBytes
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer- Parameters:
index- absolute (@code index) in this buffer.dst- the destination array.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.lengthis greater thanthis.capacity
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.length
-
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination's position reaches its limit. This method does not modifyreaderIndexorwriterIndexof this buffer while the destination'spositionwill be increased.- Parameters:
index- absolute (@code index) in this buffer.dst- the destination buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.remaining()is greater thanthis.capacity
-
setBoolean
Sets the specified boolean at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setByte
Sets the specified byte at the specified absoluteindexin this buffer. The 24 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setShort
Sets the specified 16-bit short integer at the specified absoluteindexin this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setShortLE
Sets the specified 16-bit short integer at the specified absoluteindexin this buffer with the Little Endian Byte Order. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setMedium
Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setMediumLE
Sets the specified 24-bit medium integer at the specified absoluteindexin 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 modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setInt
Sets the specified 32-bit integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setIntLE
Sets the specified 32-bit integer at the specified absoluteindexin this buffer with Little Endian byte order . This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setLong
Sets the specified 64-bit long integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setLongLE
Sets the specified 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setChar
Sets the specified 2-byte UTF-16 character at the specified absoluteindexin this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setFloat
Sets the specified 32-bit floating-point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setDouble
Sets the specified 64-bit floating-point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer becomes unreadable. This method is basically same withsetBytes(int, Buffer, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes whilesetBytes(int, Buffer, int, int)does not. This method does not modifyreaderIndexorwriterIndexof the source buffer (i.e.this).- Parameters:
index- absolute (@code index) in this buffer.src- the source buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.readableBytesis greater thanthis.capacityReadOnlyBufferException- 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 thereaderIndexof the source buffer by the number of the transferred bytes whilesetBytes(int, Buffer, int, int)does not. This method does not modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, ifindex + lengthis greater thanthis.capacity, or iflengthis greater thansrc.readableBytesReadOnlyBufferException- 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 modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.capacityReadOnlyBufferException- 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 modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.src- the source array.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.lengthis greater thanthis.capacityReadOnlyBufferException- 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 modifyreaderIndexorwriterIndexof 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 specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.lengthReadOnlyBufferException- if this buffer is read-only
-
setBytes
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer's position reaches its limit. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.src- the source buffer.- Returns:
- itself.
- Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityReadOnlyBufferException- if this buffer is read-only
-
setBytes
Transfers a fixed amount from the specified sourceInputStream's data to this buffer starting at the specified absoluteindexuntillengthbytes have been read, the end of stream is reached, or an exception is thrown.This method does not modify
readerIndexorwriterIndexof 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.-1if the specified channel is closed. - Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityIOException- 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 absoluteindexuntil the end of stream is reached or an exception is thrown.This method does not modify
readerIndexorwriterIndexof 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 fromsrcon each read attempt.- Returns:
- the actual total number of bytes read in from
src.-1if no bytes were read because the specified InputStream was closed when this method was called. - Throws:
IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityIOException- 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 currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a boolean.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than1
-
readByte
byte readByte()Gets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than1
-
readUnsignedByte
short readUnsignedByte()Gets an unsigned byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a byte.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than1
-
readShort
short readShort()Gets a 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than2
-
readShortLE
short readShortLE()Gets a 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than2
-
readUnsignedShort
int readUnsignedShort()Gets an unsigned 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than2
-
readUnsignedShortLE
int readUnsignedShortLE()Gets an unsigned 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.- Returns:
- a short.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than2
-
readMedium
int readMedium()Gets a 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than3
-
readMediumLE
int readMediumLE()Gets a 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than3
-
readUnsignedMedium
int readUnsignedMedium()Gets an unsigned 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than3
-
readUnsignedMediumLE
int readUnsignedMediumLE()Gets an unsigned 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.- Returns:
- a medium int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than3
-
readInt
int readInt()Gets a 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readIntLE
int readIntLE()Gets a 32-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby4in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readUnsignedInt
long readUnsignedInt()Gets an unsigned 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readUnsignedIntLE
long readUnsignedIntLE()Gets an unsigned 32-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby4in this buffer.- Returns:
- a int.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readLong
long readLong()Gets a 64-bit integer at the currentreaderIndexand increases thereaderIndexby8in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than8
-
readLongLE
long readLongLE()Gets a 64-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby8in this buffer.- Returns:
- a long.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than8
-
readChar
char readChar()Gets a 2-byte UTF-16 character at the currentreaderIndexand increases thereaderIndexby2in this buffer.- Returns:
- a char.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than2
-
readFloat
float readFloat()Gets a 32-bit floating point number at the currentreaderIndexand increases thereaderIndexby4in this buffer.- Returns:
- a float.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readDouble
double readDouble()Gets a 64-bit floating point number at the currentreaderIndexand increases thereaderIndexby8in this buffer.- Returns:
- a double.
- Throws:
IndexOutOfBoundsException- ifthis.readableBytesis less than8
-
readSlice
Returns a new slice of this buffer's sub-region starting at the currentreaderIndexand increases thereaderIndexby the size of the new slice (=length).- Parameters:
length- the size of the new slice- Returns:
- the newly created slice
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to a newly created buffer starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length). The returned buffer'sreaderIndexandwriterIndexare0andlengthrespectively.- Parameters:
length- the number of bytes to transfer- Returns:
- the newly created buffer which contains the transferred bytes
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination becomes non-writable, and increases thereaderIndexby the number of the transferred bytes. This method is basically same withreadBytes(Buffer, int, int), except that this method increases thewriterIndexof 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.writableBytesis greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length). This method is basically same withreadBytes(Buffer, int, int), except that this method increases thewriterIndexof 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- iflengthis greater thanthis.readableBytesor iflengthis greater thandst.writableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby 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 specifieddstIndexis less than0, iflengthis greater thanthis.readableBytes, or ifdstIndex + lengthis greater thandst.capacity
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=dst.length).- Parameters:
dst- the destination array.- Returns:
- self.
- Throws:
IndexOutOfBoundsException- ifdst.lengthis greater thanthis.readableBytes
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby 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 specifieddstIndexis less than0, iflengthis greater thanthis.readableBytes, or ifdstIndex + lengthis greater thandst.length
-
readBytes
Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination's position reaches its limit, and increases thereaderIndexby the number of the transferred bytes.- Parameters:
dst- the destination buffer.- Returns:
- self.
- Throws:
IndexOutOfBoundsException- ifdst.remaining()is less thanthis.readableBytes
-
skipBytes
Increases the currentreaderIndexby the specifiedlengthin this buffer.- Parameters:
length- number of bytes.- Returns:
- self.
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
writeBoolean
Sets the specified boolean at the currentwriterIndexand increases thewriterIndexby1in this buffer. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby1in this buffer. The 24 high-order bits of the specified value are ignored. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby2in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby2in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby3in this buffer. Ifthis.writableBytesis 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 currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby3in this buffer. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby4in this buffer. Ifthis.writableBytesis 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 currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby4in this buffer. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby8in this buffer. Ifthis.writableBytesis 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 currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby8in this buffer. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby2in this buffer. The 16 high-order bits of the specified value are ignored. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby4in this buffer. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby8in this buffer. Ifthis.writableBytesis 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 currentwriterIndexuntil the source buffer becomes unreadable, and increases thewriterIndexby the number of the transferred bytes. This method is basically same withwriteBytes(Buffer, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes whilewriteBytes(Buffer, int, int)does not. Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length). This method is basically same withwriteBytes(Buffer, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes (=length) whilewriteBytes(Buffer, int, int)does not. Ifthis.writableBytesis 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- iflengthis greater thensrc.readableBytesReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length). Ifthis.writableBytesis 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 specifiedsrcIndexis less than0, or ifsrcIndex + lengthis greater thansrc.capacityReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=src.length). Ifthis.writableBytesis 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 currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length). Ifthis.writableBytesis 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 specifiedsrcIndexis less than0, or ifsrcIndex + lengthis greater thansrc.lengthReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes. Ifthis.writableBytesis 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 currentwriterIndexuntillengthbytes have been read, the end of stream is reached, or an exception is thrown. Ifthis.writableBytesis less thanlength,ensureWritable(int)will be called in an attempt to expand capacity to accommodate.This method will increase the
writerIndexby the number of the transferred bytes if the write operation was successful.- Parameters:
src- the sourceInputStreamto 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.-1if the specified channel is closed. - Throws:
IOException- if theInputStreamthrows 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 currentwriterIndexuntil the end of stream is reached or an exception is thrown. Ifthis.writableBytesis less than the number of bytes in theInputStream,ensureWritable(int)will be called in an attempt to expand capacity to accommodate. Note that becauseInputStreamdoes not provide a reliable way to get the remaining bytes, this method may over allocate by a factor ofchunkSize.This method will increase the
writerIndexby the number of the transferred bytes if the write operation was successful.- Parameters:
src- the sourceInputStreamto write.chunkSize- the amount of data that will be read fromsrcon each read attempt.- Returns:
- the actual total number of bytes read in from
src.-1if no bytes were read because the specifiedInputStreamwas closed when this method was called. - Throws:
IOException- if theInputStreamthrows an exception while being read from.ReadOnlyBufferException- if this buffer is read-only
-
writeAscii
Encode aCharSequencein ASCII and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes. Ifthis.writableBytesis 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 aCharSequencein UTF-8 and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes. Ifthis.writableBytesis 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 aCharSequencein UTF-8 and write it to this buffer starting atwriterIndexand increases thewriterIndexby 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 aCharSequenceencoded inCharsetand write it to this buffer starting atwriterIndexand increases thewriterIndexby 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 specifiedvaluein this buffer. The search takes place from the specifiedfromIndex(inclusive) to the specifiedtoIndex(exclusive).If
fromIndexis greater thantoIndex, the search is performed in a reversed order.This method does not modify
readerIndexorwriterIndexof 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.
-1otherwise.
-
bytesBefore
int bytesBefore(byte value) Locates the first occurrence of the specifiedvaluein this buffer. The search takes place from the currentreaderIndex(inclusive) to the currentwriterIndex(exclusive).This method does not modify
readerIndexorwriterIndexof this buffer.- Parameters:
value- the value to search.- Returns:
- the number of bytes between the current
readerIndexand the first occurrence if found.-1otherwise.
-
bytesBefore
int bytesBefore(int length, byte value) Locates the first occurrence of the specifiedvaluein this buffer. The search starts from the currentreaderIndex(inclusive) and lasts for the specifiedlength.This method does not modify
readerIndexorwriterIndexof this buffer.- Parameters:
length- the length.value- the value to search.- Returns:
- the number of bytes between the current
readerIndexand the first occurrence if found.-1otherwise. - Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
bytesBefore
int bytesBefore(int index, int length, byte value) Locates the first occurrence of the specifiedvaluein this buffer. The search starts from the specifiedindex(inclusive) and lasts for the specifiedlength.This method does not modify
readerIndexorwriterIndexof this buffer.- Parameters:
index- the index.length- the length.value- the value to search.- Returns:
- the number of bytes between the specified
indexand the first occurrence if found.-1otherwise. - Throws:
IndexOutOfBoundsException- ifindex + lengthis 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 modifyreaderIndexorwriterIndexof 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 modifyreaderIndexorwriterIndexof 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 modifyreaderIndexorwriterIndexof 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 modifyreaderIndexorwriterIndexof 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 modifyreaderIndexorwriterIndexof this buffer.- Returns:
- a duplicated buffer.
-
nioBufferCount
int nioBufferCount()Returns the maximum number of NIOByteBuffers that consist this buffer. Note thattoNioBuffers()ortoNioBuffers(int, int)might return a less number ofByteBuffers.- Returns:
-1if this buffer has no underlyingByteBuffer. the number of the underlyingByteBuffers if this buffer has at least one underlyingByteBuffer. Note that this method does not return0to 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 modifyreaderIndexorwriterIndexof 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 aByteBufferthat 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 modifyreaderIndexorwriterIndexof 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 aByteBufferthat 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 modifyreaderIndexorwriterIndexof 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 aByteBufferthat 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 modifyreaderIndexorwriterIndexof 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 aByteBufferthat shares the content with itself- See Also:
-
isReadOnly
boolean isReadOnly()Determine if this buffer is read-only.- Returns:
trueif 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 originalBufferuseduplicate()before converting to a read-only view.- Returns:
- a buffer whose contents cannot be modified.
-
isDirect
boolean isDirect()Returnstrueif the buffer is direct and so not allocated on the heap.- Returns:
trueif direct.
-
hasArray
boolean hasArray()Returnstrueif and only if this buffer has a backing byte array. If this method returns true, you can safely callarray()andarrayOffset().- Returns:
trueif 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()returnstruebefore calling this method orUnsupportedOperationExceptionmaybe 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()returnstruebefore calling this method orUnsupportedOperationExceptionmaybe 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 specifiedprocessorin ascending order.- Parameters:
processor- theByteProcessorto use.- Returns:
-1if 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 specifiedprocessorin 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- theByteProcessorto use.- Returns:
-1if 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 specifiedprocessorin descending order.- Parameters:
processor- theByteProcessorto use.- Returns:
-1if 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 specifiedprocessorin 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- theByteProcessorto use.- Returns:
-1if 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 returnsfalsefornulland an object which is not an instance ofBuffertype. -
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 modifyreaderIndexorwriterIndexof 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 modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- the start index.length- the length.charset- the charset to use.- Returns:
- the string.
-
asOutputStream
Return anOutputStreamthat 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 anInputStreamthat wraps the givenBuffer. The readerIndex will be increased when reading from the buffer.- Parameters:
buffer- the buffer to wrap.- Returns:
- a new
InputStream.
-