Interface Buffer
-
- All Known Subinterfaces:
CompositeBuffer
- All Known Implementing Classes:
EmptyBuffer
public interface BufferAn arbitrary and sequential accessible sequence of zero or more bytes (octets). This interface provides an abstract view for one or more primitive byte arrays (byte[]) andNIO buffers.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description byte[]array()Returns the backing byte array of this buffer.intarrayOffset()Returns the offset of the first byte within the backing byte array of this buffer.static java.io.InputStreamasInputStream(Buffer buffer)Return anInputStreamthat wraps the givenBuffer.static java.io.OutputStreamasOutputStream(Buffer buffer)Return anOutputStreamthat wraps the givenBuffer.BufferasReadOnly()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.Buffercapacity(int newCapacity)Sets the capacity of this buffer.Bufferclear()Sets thereaderIndexandwriterIndexof this buffer to0.Buffercopy()Returns a copy of this buffer's readable bytes.Buffercopy(int index, int length)Returns a copy of this buffer's sub-region.Bufferduplicate()Returns a buffer which shares the whole region of this buffer.BufferensureWritable(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.booleanequals(java.lang.Object obj)Determines 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.BuffergetBytes(int index, byte[] dst)Transfers this buffer's data to the specified destination starting at the specified absoluteindex.BuffergetBytes(int index, byte[] dst, int dstIndex, int length)Transfers this buffer's data to the specified destination starting at the specified absoluteindex.BuffergetBytes(int index, Buffer dst)Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination becomes non-writable.BuffergetBytes(int index, Buffer dst, int length)Transfers this buffer's data to the specified destination starting at the specified absoluteindex.BuffergetBytes(int index, Buffer dst, int dstIndex, int length)Transfers this buffer's data to the specified destination starting at the specified absoluteindex.BuffergetBytes(int index, java.nio.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.booleanisReadOnly()Determine if this buffer is read-only.intmaxCapacity()Returns the maximum allowed capacity of this buffer.intmaxWritableBytes()Returns the maximum possible number of writable bytes, which is equal to(this.maxCapacity - this.writerIndex).intnioBufferCount()Returns the maximum number of NIOByteBuffers that consist this buffer.intreadableBytes()Returns the number of readable bytes which is equal to(this.writerIndex - this.readerIndex).booleanreadBoolean()Gets a boolean at the currentreaderIndexand increases thereaderIndexby1in this buffer.bytereadByte()Gets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.BufferreadBytes(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).BufferreadBytes(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).BufferreadBytes(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).BufferreadBytes(Buffer dst)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.BufferreadBytes(Buffer dst, int length)Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).BufferreadBytes(Buffer 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).BufferreadBytes(java.nio.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.doublereadDouble()Gets a 64-bit floating point number at the currentreaderIndexand increases thereaderIndexby8in this buffer.intreaderIndex()Returns thereaderIndexof this buffer.BufferreaderIndex(int readerIndex)Sets thereaderIndexof this buffer.floatreadFloat()Gets 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.intreadIntLE()Gets 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.longreadLongLE()Gets a 64-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby8in this buffer.intreadMedium()Gets a 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.intreadMediumLE()Gets a 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.shortreadShort()Gets a 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.shortreadShortLE()Gets a 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.BufferreadSlice(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).shortreadUnsignedByte()Gets an unsigned byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.longreadUnsignedInt()Gets an unsigned 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.longreadUnsignedIntLE()Gets an unsigned 32-bit integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby4in this buffer.intreadUnsignedMedium()Gets an unsigned 24-bit medium integer at the currentreaderIndexand increases thereaderIndexby3in this buffer.intreadUnsignedMediumLE()Gets an unsigned 24-bit medium integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby3in this buffer.intreadUnsignedShort()Gets an unsigned 16-bit short integer at the currentreaderIndexand increases thereaderIndexby2in this buffer.intreadUnsignedShortLE()Gets an unsigned 16-bit short integer at the currentreaderIndexin the Little Endian Byte Order and increases thereaderIndexby2in this buffer.BuffersetBoolean(int index, boolean value)Sets the specified boolean at the specified absoluteindexin this buffer.BuffersetByte(int index, int value)Sets the specified byte at the specified absoluteindexin this buffer.BuffersetBytes(int index, byte[] src)Transfers the specified source array's data to this buffer starting at the specified absoluteindex.BuffersetBytes(int index, byte[] src, int srcIndex, int length)Transfers the specified source array's data to this buffer starting at the specified absoluteindex.BuffersetBytes(int index, Buffer src)Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer becomes unreadable.BuffersetBytes(int index, Buffer src, int length)Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex.BuffersetBytes(int index, Buffer src, int srcIndex, int length)Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex.intsetBytes(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 absoluteindexuntillengthbytes have been read, the end of stream is reached, or an exception is thrown.BuffersetBytes(int index, java.nio.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, java.io.InputStream src, int chunkSize)Transfers all the specified source InputStream's data to this buffer starting at the specified absoluteindexuntil the end of stream is reached or an exception is thrown.BuffersetChar(int index, int value)Sets the specified 2-byte UTF-16 character at the specified absoluteindexin this buffer.BuffersetDouble(int index, double value)Sets the specified 64-bit floating-point number at the specified absoluteindexin this buffer.BuffersetFloat(int index, float value)Sets the specified 32-bit floating-point number at the specified absoluteindexin this buffer.BuffersetInt(int index, int value)Sets the specified 32-bit integer at the specified absoluteindexin this buffer.BuffersetIntLE(int index, int value)Sets the specified 32-bit integer at the specified absoluteindexin this buffer with Little Endian byte order .BuffersetLong(int index, long value)Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.BuffersetLongLE(int index, long value)Sets the specified 64-bit long integer at the specified absoluteindexin this buffer in Little Endian Byte Order.BuffersetMedium(int index, int value)Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer.BuffersetMediumLE(int index, int value)Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer in the Little Endian Byte Order.BuffersetShort(int index, int value)Sets the specified 16-bit short integer at the specified absoluteindexin this buffer.BuffersetShortLE(int index, int value)Sets the specified 16-bit short integer at the specified absoluteindexin this buffer with the Little Endian Byte Order.BufferskipBytes(int length)Increases the currentreaderIndexby the specifiedlengthin this buffer.Bufferslice()Returns a slice of this buffer's readable bytes.Bufferslice(int index, int length)Returns a slice of this buffer's sub-region.java.nio.ByteBuffertoNioBuffer()Exposes this buffer's readable bytes as an NIOByteBuffer.java.nio.ByteBuffertoNioBuffer(int index, int length)Exposes this buffer's sub-region as an NIOByteBuffer.java.nio.ByteBuffer[]toNioBuffers()Exposes this buffer's readable bytes as an NIOByteBuffer's.java.nio.ByteBuffer[]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.java.lang.StringtoString()Returns the string representation of this buffer.java.lang.StringtoString(int index, int length, java.nio.charset.Charset charset)Decodes this buffer's sub-region into a string with the specified character set.java.lang.StringtoString(java.nio.charset.Charset charset)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.intwritableBytes()Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex).BufferwriteAscii(java.lang.CharSequence seq)Encode aCharSequencein ASCII and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes.BufferwriteBoolean(boolean value)Sets the specified boolean at the currentwriterIndexand increases thewriterIndexby1in this buffer.BufferwriteByte(int value)Sets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer.BufferwriteBytes(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).BufferwriteBytes(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).BufferwriteBytes(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.BufferwriteBytes(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).BufferwriteBytes(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(java.io.InputStream src, int length)Transfers ta 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.BufferwriteBytes(java.nio.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(java.io.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.BufferwriteChar(int value)Sets the specified 2-byte UTF-16 character at the currentwriterIndexand increases thewriterIndexby2in this buffer.BufferwriteDouble(double value)Sets the specified 64-bit floating point number at the currentwriterIndexand increases thewriterIndexby8in this buffer.BufferwriteFloat(float value)Sets the specified 32-bit floating point number at the currentwriterIndexand increases thewriterIndexby4in this buffer.BufferwriteInt(int value)Sets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.BufferwriteIntLE(int value)Sets the specified 32-bit integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby4in this buffer.BufferwriteLong(long value)Sets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.BufferwriteLongLE(long value)Sets the specified 64-bit long integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby8in this buffer.BufferwriteMedium(int value)Sets the specified 24-bit medium integer at the currentwriterIndexand increases thewriterIndexby3in this buffer.BufferwriteMediumLE(int value)Sets the specified 24-bit medium integer at the currentwriterIndexin the Little Endian Byte Order and increases thewriterIndexby3in this buffer.intwriterIndex()Returns thewriterIndexof this buffer.BufferwriterIndex(int writerIndex)Sets thewriterIndexof this buffer.BufferwriteShort(int value)Sets the specified 16-bit short integer at the currentwriterIndexand increases thewriterIndexby2in this buffer.BufferwriteShortLE(int value)Sets the specified 16-bit short integer in the Little Endian Byte Order at the currentwriterIndexand increases thewriterIndexby2in this buffer.BufferwriteUtf8(java.lang.CharSequence seq)Encode aCharSequencein UTF-8 and write it to this buffer starting atwriterIndexand increases thewriterIndexby the number of the transferred bytes.BufferwriteUtf8(java.lang.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 Detail
-
capacity
int capacity()
Returns the number of bytes (octets) this buffer can contain.- Returns:
- the number of bytes (octets) this buffer can contain.
-
capacity
Buffer capacity(int newCapacity)
Sets the capacity of this buffer. If 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:
java.lang.IllegalArgumentException- if thenewCapacityis greater thanmaxCapacity()java.nio.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
Buffer readerIndex(int readerIndex)
Sets thereaderIndexof this buffer.- Parameters:
readerIndex- the new readerIndex of this buffer.- Returns:
- itself.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifiedreaderIndexis less than0or greater thanthis.writerIndex
-
writerIndex
int writerIndex()
Returns thewriterIndexof this buffer.- Returns:
- the
writerIndexof this buffer.
-
writerIndex
Buffer writerIndex(int writerIndex)
Sets thewriterIndexof this buffer.- Parameters:
writerIndex- the new writerIndex of this buffer.- Returns:
- itself.
- Throws:
java.lang.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
Buffer ensureWritable(int minWritableBytes)
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:
java.lang.IndexOutOfBoundsException- ifwriterIndex()+minWritableBytes>maxCapacity()java.nio.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacity
-
getBytes
Buffer getBytes(int index, Buffer dst)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.writableBytesis greater thanthis.capacity
-
getBytes
Buffer getBytes(int index, Buffer dst, int length)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, ifindex + lengthis greater thanthis.capacity, or iflengthis greater thandst.writableBytes
-
getBytes
Buffer getBytes(int index, Buffer dst, int dstIndex, int length)
Transfers this buffer's data to the specified destination starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.capacity
-
getBytes
Buffer getBytes(int index, byte[] dst)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.lengthis greater thanthis.capacity
-
getBytes
Buffer getBytes(int index, byte[] dst, int dstIndex, int length)
Transfers this buffer's data to the specified destination starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifieddstIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifdstIndex + lengthis greater thandst.length
-
getBytes
Buffer getBytes(int index, java.nio.ByteBuffer dst)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + dst.remaining()is greater thanthis.capacity
-
setBoolean
Buffer setBoolean(int index, boolean value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setByte
Buffer setByte(int index, int value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 1is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setShort
Buffer setShort(int index, int value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setShortLE
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. 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setMedium
Buffer setMedium(int index, int value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setMediumLE
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. 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 3is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setInt
Buffer setInt(int index, int value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setIntLE
Buffer setIntLE(int index, int value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setLong
Buffer setLong(int index, long value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setLongLE
Buffer setLongLE(int index, long value)
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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setChar
Buffer setChar(int index, int value)
Sets the specified 2-byte UTF-16 character at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 2is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setFloat
Buffer setFloat(int index, float value)
Sets the specified 32-bit floating-point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 4is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setDouble
Buffer setDouble(int index, double value)
Sets the specified 64-bit floating-point number at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.value- the value.- Returns:
- itself.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0orindex + 8is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, Buffer src)
Transfers the specified source buffer's data to this buffer starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.readableBytesis greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, Buffer src, int length)
Transfers the specified source buffer's data to this buffer starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, ifindex + lengthis greater thanthis.capacity, or iflengthis greater thansrc.readableBytesjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, Buffer src, int srcIndex, int length)
Transfers the specified source buffer's data to this buffer starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, byte[] src)
Transfers the specified source array's data to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.src- the source array.- Returns:
- itself.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.lengthis greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, byte[] src, int srcIndex, int length)
Transfers the specified source array's data to this buffer starting at the specified 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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0, if the specifiedsrcIndexis less than0, ifindex + lengthis greater thanthis.capacity, or ifsrcIndex + lengthis greater thansrc.lengthjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
Buffer setBytes(int index, java.nio.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. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- absolute (@code index) in this buffer.src- the source buffer.- Returns:
- itself.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytes
int setBytes(int index, java.io.InputStream src, int length) throws java.io.IOExceptionTransfers a fixed amount from the specified source InputStream'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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityjava.io.IOException- if the InputStream throws an exception while being read from.java.nio.ReadOnlyBufferException- if this buffer is read-only
-
setBytesUntilEndStream
int setBytesUntilEndStream(int index, java.io.InputStream src, int chunkSize) throws java.io.IOExceptionTransfers all the specified source InputStream'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:
java.lang.IndexOutOfBoundsException- if the specifiedindexis less than0or ifindex + src.remaining()is greater thanthis.capacityjava.io.IOException- if the InputStream throws an exception while being read from.java.nio.ReadOnlyBufferException- if this buffer is read-only
-
readBoolean
boolean readBoolean()
Gets a boolean at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a boolean.
- Throws:
java.lang.IndexOutOfBoundsException- ifthis.readableBytesis less than1
-
readByte
byte readByte()
Gets a byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a byte.
- Throws:
java.lang.IndexOutOfBoundsException- ifthis.readableBytesis less than1
-
readUnsignedByte
short readUnsignedByte()
Gets an unsigned byte at the currentreaderIndexand increases thereaderIndexby1in this buffer.- Returns:
- a byte.
- Throws:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IndexOutOfBoundsException- ifthis.readableBytesis less than3
-
readInt
int readInt()
Gets a 32-bit integer at the currentreaderIndexand increases thereaderIndexby4in this buffer.- Returns:
- a int.
- Throws:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IndexOutOfBoundsException- ifthis.readableBytesis less than4
-
readLong
long readLong()
Gets a 64-bit integer at the currentreaderIndexand increases thereaderIndexby8in this buffer.- Returns:
- a long.
- Throws:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IndexOutOfBoundsException- ifthis.readableBytesis less than8
-
readSlice
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).- Parameters:
length- the size of the new slice- Returns:
- the newly created slice
- Throws:
java.lang.IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
readBytes
Buffer 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). The returned buffer'sreaderIndexandwriterIndexare0andlengthrespectively.- Parameters:
length- the number of bytes to transfer- Returns:
- the newly created buffer which contains the transferred bytes
- Throws:
java.lang.IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
readBytes
Buffer readBytes(Buffer dst)
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:
java.lang.IndexOutOfBoundsException- ifdst.writableBytesis greater thanthis.readableBytes
-
readBytes
Buffer readBytes(Buffer dst, int length)
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:
java.lang.IndexOutOfBoundsException- iflengthis greater thanthis.readableBytesor iflengthis greater thandst.writableBytes
-
readBytes
Buffer readBytes(Buffer 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).- Parameters:
dst- the destination buffer.dstIndex- the first index of the destinationlength- the number of bytes to transfer- Returns:
- self.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifieddstIndexis less than0, iflengthis greater thanthis.readableBytes, or ifdstIndex + lengthis greater thandst.capacity
-
readBytes
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).- Parameters:
dst- the destination array.- Returns:
- self.
- Throws:
java.lang.IndexOutOfBoundsException- ifdst.lengthis greater thanthis.readableBytes
-
readBytes
Buffer 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).- Parameters:
dst- the destination array.dstIndex- the first index of the destinationlength- the number of bytes to transfer- Returns:
- self.
- Throws:
java.lang.IndexOutOfBoundsException- if the specifieddstIndexis less than0, iflengthis greater thanthis.readableBytes, or ifdstIndex + lengthis greater thandst.length
-
readBytes
Buffer readBytes(java.nio.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.- Parameters:
dst- the destination buffer.- Returns:
- self.
- Throws:
java.lang.IndexOutOfBoundsException- ifdst.remaining()is less thanthis.readableBytes
-
skipBytes
Buffer skipBytes(int length)
Increases the currentreaderIndexby the specifiedlengthin this buffer.- Parameters:
length- number of bytes.- Returns:
- self.
- Throws:
java.lang.IndexOutOfBoundsException- iflengthis greater thanthis.readableBytes
-
writeBoolean
Buffer writeBoolean(boolean value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeByte
Buffer writeByte(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeShort
Buffer writeShort(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeShortLE
Buffer writeShortLE(int value)
Sets the specified 16-bit short integer in the Little Endian Byte Order at the 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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeMedium
Buffer writeMedium(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeMediumLE
Buffer writeMediumLE(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeInt
Buffer writeInt(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeIntLE
Buffer writeIntLE(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeLong
Buffer writeLong(long value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeLongLE
Buffer writeLongLE(long value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeChar
Buffer writeChar(int value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeFloat
Buffer writeFloat(float value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeDouble
Buffer writeDouble(double value)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(Buffer src)
Transfers the specified source buffer's data to this buffer starting at the 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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(Buffer src, int length)
Transfers the specified source buffer's data to this buffer starting at the 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:
java.lang.IndexOutOfBoundsException- iflengthis greater thensrc.readableBytesjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(Buffer src, int srcIndex, int length)
Transfers the specified source buffer's data to this buffer starting at the 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:
java.lang.IndexOutOfBoundsException- if the specifiedsrcIndexis less than0, or ifsrcIndex + lengthis greater thansrc.capacityjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(byte[] src)
Transfers the specified source array's data to this buffer starting at the 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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(byte[] src, int srcIndex, int length)
Transfers the specified source array's data to this buffer starting at the 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:
java.lang.IndexOutOfBoundsException- if the specifiedsrcIndexis less than0, or ifsrcIndex + lengthis greater thansrc.lengthjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
Buffer writeBytes(java.nio.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. 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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytes
int writeBytes(java.io.InputStream src, int length) throws java.io.IOExceptionTransfers ta 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:
java.io.IOException- if theInputStreamthrows an exception while being read from.java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeBytesUntilEndStream
int writeBytesUntilEndStream(java.io.InputStream src, int chunkSize) throws java.io.IOExceptionTransfers 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:
java.io.IOException- if theInputStreamthrows an exception while being read from.java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeAscii
Buffer writeAscii(java.lang.CharSequence seq)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeUtf8
Buffer writeUtf8(java.lang.CharSequence seq)
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:
java.nio.ReadOnlyBufferException- if this buffer is read-only
-
writeUtf8
Buffer writeUtf8(java.lang.CharSequence seq, int ensureWritable)
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:
java.nio.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:
java.lang.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:
java.lang.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
Buffer copy(int index, int length)
Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not 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
Buffer slice(int index, int length)
Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes. This method does not 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(),toNioBuffer(int, int),toNioBuffers(),toNioBuffers(int, int)
-
toNioBuffer
java.nio.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:
java.lang.UnsupportedOperationException- if this buffer cannot create aByteBufferthat shares the content with itself- See Also:
nioBufferCount(),toNioBuffers(),toNioBuffers(int, int)
-
toNioBuffer
java.nio.ByteBuffer toNioBuffer(int index, int length)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:
java.lang.UnsupportedOperationException- if this buffer cannot create aByteBufferthat shares the content with itself- See Also:
nioBufferCount(),toNioBuffers(),toNioBuffers(int, int)
-
toNioBuffers
java.nio.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:
java.lang.UnsupportedOperationException- if this buffer cannot create aByteBufferthat shares the content with itself- See Also:
nioBufferCount(),toNioBuffer(),toNioBuffer(int, int)
-
toNioBuffers
java.nio.ByteBuffer[] 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. 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:
java.lang.UnsupportedOperationException- if this buffer cannot create aByteBufferthat shares the content with itself- See Also:
nioBufferCount(),toNioBuffer(),toNioBuffer(int, int)
-
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
-
array
byte[] array()
Returns the backing byte array of this buffer.- Returns:
- byte array.
- Throws:
java.lang.UnsupportedOperationException- if there no accessible backing byte arrayjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
arrayOffset
int arrayOffset()
Returns the offset of the first byte within the backing byte array of this buffer.- Returns:
- the offset in the array.
- Throws:
java.lang.UnsupportedOperationException- if there no accessible backing byte arrayjava.nio.ReadOnlyBufferException- if this buffer is read-only
-
forEachByte
int forEachByte(ByteProcessor processor)
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
int forEachByte(int index, int length, ByteProcessor processor)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
int forEachByteDesc(ByteProcessor processor)
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
int forEachByteDesc(int index, int length, ByteProcessor processor)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.- Overrides:
hashCodein classjava.lang.Object
-
equals
boolean equals(java.lang.Object obj)
Determines if the content of the specified buffer is identical to the content of this array. 'Identical' here means:- the size of the contents of the two buffers are same and
- every single byte of the content of the two buffers are same.
readerIndex()norwriterIndex(). This method also returnsfalsefornulland an object which is not an instance ofBuffertype.- Overrides:
equalsin classjava.lang.Object
-
toString
java.lang.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().- Overrides:
toStringin classjava.lang.Object
-
toString
java.lang.String toString(java.nio.charset.Charset charset)
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:
java.nio.charset.UnsupportedCharsetException- if the specified character set name is not supported by the current VM
-
toString
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. This method does not modifyreaderIndexorwriterIndexof this buffer.- Parameters:
index- the start index.length- the length.charset- the charset to use.- Returns:
- the string.
-
asOutputStream
static java.io.OutputStream asOutputStream(Buffer buffer)
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.
-
-