public abstract class AbstractByteBuf extends ByteBuf
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractByteBuf(int maxCapacity) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract byte |
_getByte(int index) |
protected abstract int |
_getInt(int index) |
protected abstract int |
_getIntLE(int index) |
protected abstract long |
_getLong(int index) |
protected abstract long |
_getLongLE(int index) |
protected abstract short |
_getShort(int index) |
protected abstract short |
_getShortLE(int index) |
protected abstract int |
_getUnsignedMedium(int index) |
protected abstract int |
_getUnsignedMediumLE(int index) |
protected abstract void |
_setByte(int index, int value) |
protected abstract void |
_setInt(int index, int value) |
protected abstract void |
_setIntLE(int index, int value) |
protected abstract void |
_setLong(int index, long value) |
protected abstract void |
_setLongLE(int index, long value) |
protected abstract void |
_setMedium(int index, int value) |
protected abstract void |
_setMediumLE(int index, int value) |
protected abstract void |
_setShort(int index, int value) |
protected abstract void |
_setShortLE(int index, int value) |
protected void |
adjustMarkers(int decrement) |
ByteBuf |
asReadOnly()
返回此缓冲区的只读版本。
|
int |
bytesBefore(byte value)
定位此缓冲区中第一次出现的指定
value 。
|
int |
bytesBefore(int length, byte value)
定位该缓冲区中第一次出现的指定
value 。
|
int |
bytesBefore(int index, int length, byte value)
定位此缓冲区中第一次出现的指定
value 。
|
protected void |
checkDstIndex(int index, int length, int dstIndex, int dstCapacity) |
protected void |
checkIndex(int index) |
protected void |
checkIndex(int index, int fieldLength) |
protected void |
checkNewCapacity(int newCapacity) |
protected void |
checkReadableBytes(int minimumReadableBytes)
如果此缓冲区的当前
readable bytes小于指定值,则抛出
IndexOutOfBoundsException 。
|
protected void |
checkSrcIndex(int index, int length, int srcIndex, int srcCapacity) |
ByteBuf |
clear()
将此缓冲区的
readerIndex和
writerIndex设置为
0 。
|
int |
compareTo(ByteBuf that)
将指定缓冲区的内容与此缓冲区的内容进行比较。
|
ByteBuf |
copy()
返回此缓冲区可读字节的副本。
|
ByteBuf |
discardReadBytes()
丢弃第0个索引和
readerIndex之间的字节。
|
ByteBuf |
discardSomeReadBytes()
类似于
ByteBuf.discardReadBytes(),只是此方法可能会丢弃部分,全部或者全部读取字节,具体取决于其内部实现方式,以减少潜在的额外内存消耗为代价来降低整体内存带宽消耗。
|
ByteBuf |
duplicate()
返回共享此缓冲区整个区域的缓冲区。
|
protected void |
ensureAccessible()
应该被尝试访问缓冲区内容的每种方法调用,以检查缓冲区是否在之前被释放。
|
ByteBuf |
ensureWritable(int minWritableBytes)
确保
the writable bytes的数量等于或大于指定值。
|
int |
ensureWritable(int minWritableBytes, boolean force)
尝试确保
the writable bytes的数量等于或大于指定的值。
|
boolean |
equals(java.lang.Object o)
确定指定缓冲区的内容是否与此数组的内容相同。
|
int |
forEachByte(ByteProcessor processor)
以指定的
processor按升序对此缓冲区的可读字节进行迭代。
|
int |
forEachByte(int index, int length, ByteProcessor processor)
以指定的
processor按升序对此缓冲区的指定区域进行迭代。
|
int |
forEachByteDesc(ByteProcessor processor)
使用指定的
processor按降序对此缓冲区的可读字节进行迭代。
|
int |
forEachByteDesc(int index, int length, ByteProcessor processor)
以指定的
processor以降序遍历此缓冲区的指定区域。
|
boolean |
getBoolean(int index)
在此缓冲区中获取指定绝对(@code索引)的布尔值。
|
byte |
getByte(int index)
在此缓冲区中的指定绝对
index处获取一个字节。
|
ByteBuf |
getBytes(int index, byte[] dst)
将此缓冲区的数据传送到指定的目标,从指定的绝对
index 。
|
ByteBuf |
getBytes(int index, ByteBuf dst)
将此缓冲区的数据传输到指定的目标,从指定的绝对
index开始,直到目标变为不可写。
|
ByteBuf |
getBytes(int index, ByteBuf dst, int length)
将此缓冲区的数据传输到指定的绝对目标
index开始的目标。
|
char |
getChar(int index)
在此缓冲区的指定绝对
index处获取一个2字节的UTF-16字符。
|
java.lang.CharSequence |
getCharSequence(int index, int length, java.nio.charset.Charset charset)
在给定索引处获得具有给定长度的
CharSequence 。
|
double |
getDouble(int index)
在此缓冲区中的指定绝对
index处获取一个64位浮点数。
|
float |
getFloat(int index)
在此缓冲区中指定的绝对
index处获取一个32位浮点数。
|
int |
getInt(int index)
在此缓冲区中的指定绝对
index处获取一个32位整数。
|
int |
getIntLE(int index)
在具有Little Endian Byte Order的缓冲区中的指定绝对
index处获取一个32位整数。
|
long |
getLong(int index)
在此缓冲区中指定的绝对
index处获取64位长整数。
|
long |
getLongLE(int index)
以小端字节顺序在此缓冲区中的指定绝对
index处获取64位长整数。
|
int |
getMedium(int index)
在此缓冲区中指定的绝对
index处获取一个24位中等整数。
|
int |
getMediumLE(int index)
以Little Endian字节顺序在此缓冲区中的指定绝对
index处获取一个24位中等整数。
|
short |
getShort(int index)
在此缓冲区中指定的绝对
index处获取一个16位短整数。
|
short |
getShortLE(int index)
以小端字节顺序在此缓冲区中的指定绝对
index处获取一个16位短整数。
|
short |
getUnsignedByte(int index)
在此缓冲区中的指定绝对
index处获取一个无符号字节。
|
long |
getUnsignedInt(int index)
在此缓冲区中指定的绝对
index处获取一个无符号的32位整数。
|
long |
getUnsignedIntLE(int index)
以小
index字节顺序在此缓冲区中的指定绝对
index处获取无符号的32位整数。
|
int |
getUnsignedMedium(int index)
在此缓冲区中指定的绝对
index处获取一个无符号的24位中等整数。
|
int |
getUnsignedMediumLE(int index)
以小端字节顺序在此缓冲区中的指定绝对
index处获取无符号的24位中等整数。
|
int |
getUnsignedShort(int index)
在此缓冲区中指定的绝对
index处获取一个无符号的16位短整数。
|
int |
getUnsignedShortLE(int index)
以小端字节顺序在此缓冲区中的指定绝对
index处获取一个无符号的16位短整数。
|
int |
hashCode()
返回从此缓冲区的内容计算出来的哈希码。
|
int |
indexOf(int fromIndex, int toIndex, byte value)
在此缓冲区中找到指定
value的第一个匹配项。
|
boolean |
isReadable()
当且仅当
(this.writerIndex - this.readerIndex)大于
true时,返回
0 。
|
boolean |
isReadable(int numBytes)
当且仅当此缓冲区包含等于或多于指定数量的元素时返回
true 。
|
boolean |
isReadOnly()
当且仅当此缓冲区为只读时返回
true 。
|
boolean |
isWritable()
返回
true当且仅当
(this.capacity - this.writerIndex)大于
0 。
|
boolean |
isWritable(int numBytes)
当且仅当此缓冲区有足够空间允许写入指定数量的元素时返回
true 。
|
ByteBuf |
markReaderIndex()
在此缓冲区中标记当前的
readerIndex 。
|
ByteBuf |
markWriterIndex()
在此缓冲区中标记当前的
writerIndex 。
|
int |
maxCapacity()
返回此缓冲区允许的最大容量。
|
protected void |
maxCapacity(int maxCapacity) |
int |
maxWritableBytes()
返回可写入的最大字节数,等于
(this.maxCapacity - this.writerIndex) 。
|
protected SwappedByteBuf |
newSwappedByteBuf()
为此 ByteBuf实例创建一个新的SwappedByteBuf 。
|
java.nio.ByteBuffer |
nioBuffer()
以NIO
ByteBuffer公开此缓冲区的可读字节。
|
java.nio.ByteBuffer[] |
nioBuffers()
以NIO
ByteBuffer的形式公开此缓冲区的可读字节。
|
ByteBuf |
order(java.nio.ByteOrder endianness)
返回指定
endianness的缓冲区,该缓冲区共享此缓冲区的整个区域,索引和标记。
|
int |
readableBytes()
返回等于
(this.writerIndex - this.readerIndex)的可读字节数。
|
boolean |
readBoolean()
在当前
readerIndex处获取一个布尔值,并在此缓冲区
readerIndex
1增加
readerIndex 。
|
byte |
readByte()
获取当前
readerIndex一个字节,并在此缓冲区
readerIndex
1增加
readerIndex 。
|
ByteBuf |
readBytes(byte[] dst)
将此缓冲区的数据传输到指定的目标,从当前的
readerIndex开始,并将
readerIndex增加
readerIndex所传输的字节数(=
dst.length )。
|
ByteBuf |
readBytes(byte[] dst, int dstIndex, int length)
传输此缓冲区的数据到指定的目标并从当前
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
|
ByteBuf |
readBytes(ByteBuf dst)
将此缓冲区的数据传输到从当前
readerIndex开始的指定目标,直到目标变为不可写入,并将传输字节数增加
readerIndex 。
|
ByteBuf |
readBytes(java.nio.ByteBuffer dst)
将此缓冲区的数据传输到从当前
readerIndex开始的指定目标,直到目标的位置达到其限制,并将
readerIndex增加
readerIndex所传输的字节数。
|
ByteBuf |
readBytes(ByteBuf dst, int length)
传输此缓冲区的数据到指定的目标并从当前
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
|
ByteBuf |
readBytes(ByteBuf dst, int dstIndex, int length)
传输此缓冲区的数据到指定的目标并从当前
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
|
int |
readBytes(java.nio.channels.FileChannel out, long position, int length)
将此缓冲区的数据从当前的
readerIndex到指定的通道,从给定的文件位置开始。
|
int |
readBytes(java.nio.channels.GatheringByteChannel out, int length)
将此缓冲区的数据传输到当前
readerIndex开始的指定流。
|
ByteBuf |
readBytes(int length)
传输此缓冲区的数据到一个新创建的缓冲器并从当前
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
|
ByteBuf |
readBytes(java.io.OutputStream out, int length)
将此缓冲区的数据传输到当前
readerIndex开始的指定流。
|
char |
readChar()
在当前的
readerIndex处获取一个2字节的UTF-16字符,并在此缓冲区
readerIndex
2增加
readerIndex 。
|
java.lang.CharSequence |
readCharSequence(int length, java.nio.charset.Charset charset)
在当前
readerIndex处获得具有给定长度的
CharSequence ,并将给定长度增加
readerIndex 。
|
double |
readDouble()
在当前的
readerIndex处获取64位浮点数,并在此缓冲区
readerIndex
8增加
readerIndex 。
|
int |
readerIndex()
返回此缓冲区的
readerIndex 。
|
ByteBuf |
readerIndex(int readerIndex)
设置此缓冲区的
readerIndex 。
|
float |
readFloat()
在当前的
readerIndex处获取一个32位浮点数,
4此缓冲区中的
readerIndex增加
readerIndex 。
|
int |
readInt()
在当前的
readerIndex处获得32位整数,并在此缓冲区
readerIndex
4增加
readerIndex 。
|
int |
readIntLE()
获取当前的32位整数
readerIndex在Little Endian字节序,并增加了
readerIndex通过
4在该缓冲液。
|
long |
readLong()
在当前
readerIndex处获取64位整数,并在此缓冲区
readerIndex
8增加
readerIndex 。
|
long |
readLongLE()
在当前
readerIndex中以Little Endian字节顺序获取一个64位整数,并在此缓冲区
readerIndex
8增加
readerIndex 。
|
int |
readMedium()
在当前
readerIndex处获取24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
|
int |
readMediumLE()
在当前
readerIndex以Little Endian字节顺序获取24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
|
ByteBuf |
readRetainedSlice(int length)
返回此缓冲区的子区域并从当前的一个新的保留切片
readerIndex并增加了
readerIndex由新的切片(=大小
length )。
|
short |
readShort()
在当前
readerIndex处获取16位短整数,并在此缓冲区
readerIndex
2增加
readerIndex 。
|
short |
readShortLE()
在当前
readerIndex以Little Endian字节顺序获取一个16位短整数,并在此缓冲区
readerIndex
2增加
readerIndex 。
|
ByteBuf |
readSlice(int length)
返回此缓冲区的子区域并从当前的新的片
readerIndex并增加了
readerIndex由新的切片(=大小
length )。
|
short |
readUnsignedByte()
获取当前无符号字节
readerIndex并增加了
readerIndex通过
1在该缓冲液。
|
long |
readUnsignedInt()
在当前的
readerIndex处获取一个无符号的32位整数,并在此缓冲区
readerIndex
4增加
readerIndex 。
|
long |
readUnsignedIntLE()
获取当前无符号的32位整数
readerIndex在Little Endian字节序,并增加了
readerIndex通过
4在该缓冲液。
|
int |
readUnsignedMedium()
在当前
readerIndex处获取一个无符号的24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
|
int |
readUnsignedMediumLE()
获取当前
readerIndex中Little Endian字节顺序的无符号24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
|
int |
readUnsignedShort()
获取当前的16位无符号短整型
readerIndex并增加了
readerIndex通过
2在该缓冲液。
|
int |
readUnsignedShortLE()
获取当前的16位无符号短整型
readerIndex在Little Endian字节序,并增加了
readerIndex通过
2在缓冲区中。
|
ByteBuf |
resetReaderIndex()
将当前
readerIndex重新定位到此缓冲区中标记为
readerIndex 。
|
ByteBuf |
resetWriterIndex()
将当前
writerIndex重新定位到此缓冲区中标记为
writerIndex 。
|
ByteBuf |
retainedDuplicate()
返回共享此缓冲区整个区域的保留缓冲区。
|
ByteBuf |
retainedSlice()
返回此缓冲区可读字节的保留片段。
|
ByteBuf |
retainedSlice(int index, int length)
返回此缓冲区的子区域的保留切片。
|
ByteBuf |
setBoolean(int index, boolean value)
在此缓冲区中的指定绝对
index处设置指定的布尔值。
|
ByteBuf |
setByte(int index, int value)
在此缓冲区中的指定绝对
index处设置指定的字节。
|
ByteBuf |
setBytes(int index, byte[] src)
将指定的源数组的数据传输到此缓冲区,从指定的绝对
index 。
|
ByteBuf |
setBytes(int index, ByteBuf src)
将指定的源缓冲区的数据从指定的绝对
index开始传输到此缓冲区,直到源缓冲区变得不可读。
|
ByteBuf |
setBytes(int index, ByteBuf src, int length)
将指定的源缓冲区的数据从指定的绝对
index开始传输到此缓冲区。
|
ByteBuf |
setChar(int index, int value)
在此缓冲区的指定绝对
index处设置指定的2字节UTF-16字符。
|
int |
setCharSequence(int index, java.lang.CharSequence sequence, java.nio.charset.Charset charset)
将指定
CharSequence在当前
writerIndex并增加了
writerIndex由写入的字节。
|
ByteBuf |
setDouble(int index, double value)
在此缓冲区的指定绝对
index处设置指定的64位浮点数。
|
ByteBuf |
setFloat(int index, float value)
在此缓冲区中指定的绝对
index处设置指定的32位浮点数。
|
ByteBuf |
setIndex(int readerIndex, int writerIndex)
readerIndex设置此缓冲区的
readerIndex和
writerIndex 。
|
ByteBuf |
setInt(int index, int value)
在此缓冲区中指定的绝对
index处设置指定的32位整数。
|
ByteBuf |
setIntLE(int index, int value)
使用Little Endian字节顺序在此缓冲区中的指定绝对
index处设置指定的32位整数。
|
ByteBuf |
setLong(int index, long value)
在此缓冲区中的指定绝对
index处设置指定的64位长整数。
|
ByteBuf |
setLongLE(int index, long value)
以小端字节顺序在此缓冲区中的指定绝对
index处设置指定的64位长整数。
|
ByteBuf |
setMedium(int index, int value)
在此缓冲区中的指定绝对
index处设置指定的24位中等整数。
|
ByteBuf |
setMediumLE(int index, int value)
以小端字节顺序在此缓冲区中的指定绝对
index处设置指定的24位中等整数。
|
ByteBuf |
setShort(int index, int value)
在此缓冲区中的指定绝对
index处设置指定的16位短整数。
|
ByteBuf |
setShortLE(int index, int value)
在此缓冲区中的指定绝对
index使用Little Endian字节顺序设置指定的16位短整数。
|
ByteBuf |
setZero(int index, int length)
用
NUL (0x00)填充该缓冲区,以指定的绝对
index 。
|
ByteBuf |
skipBytes(int length)
在此缓冲区中,按指定的
length增加当前
readerIndex 。
|
ByteBuf |
slice()
返回此缓冲区可读字节的一部分。
|
ByteBuf |
slice(int index, int length)
返回此缓冲区的子区域的一部分。
|
java.lang.String |
toString()
返回此缓冲区的字符串表示形式。
|
java.lang.String |
toString(java.nio.charset.Charset charset)
将此缓冲区的可读字节解码为具有指定字符集名称的字符串。
|
java.lang.String |
toString(int index, int length, java.nio.charset.Charset charset)
将此缓冲区的子区域解码为具有指定字符集的字符串。
|
int |
writableBytes()
返回等于
(this.capacity - this.writerIndex)的可写入字节数。
|
ByteBuf |
writeBoolean(boolean value)
在当前
writerIndex处设置指定的布尔值,并在此缓冲区
writerIndex
1增加
writerIndex 。
|
ByteBuf |
writeByte(int value)
在当前的
writerIndex处设置指定的字节,并在此缓冲区
writerIndex
1增加
writerIndex 。
|
ByteBuf |
writeBytes(byte[] src)
指定的源阵列的数据传送到该缓冲液并从当前
writerIndex并增加了
writerIndex由传输的字节(=数量
src.length )。
|
ByteBuf |
writeBytes(byte[] src, int srcIndex, int length)
指定的源阵列的数据传送到该缓冲液并从当前
writerIndex并增加了
writerIndex由传输的字节(=数量
length )。
|
ByteBuf |
writeBytes(ByteBuf src)
将指定源缓冲区的数据从当前的
writerIndex开始传输到此缓冲区,直到源缓冲区变得不可读,并将传输字节数增加
writerIndex 。
|
ByteBuf |
writeBytes(java.nio.ByteBuffer src)
将指定源缓冲区的数据从当前
writerIndex开始传输到此缓冲区,直到源缓冲区的位置达到其限制,并将传输字节数增加
writerIndex 。
|
ByteBuf |
writeBytes(ByteBuf src, int length)
指定的源缓冲区的数据传送到该缓冲液并从当前
writerIndex并增加了
writerIndex由传输的字节(=数量
length )。
|
ByteBuf |
writeBytes(ByteBuf src, int srcIndex, int length)
指定的源缓冲区的数据传送到该缓冲液并从当前
writerIndex并增加了
writerIndex由传输的字节(=数量
length )。
|
int |
writeBytes(java.nio.channels.FileChannel in, long position, int length)
将从给定文件位置开始的指定通道的内容传输到此缓冲区,从当前的
writerIndex开始,并将
writerIndex增加
writerIndex 。
|
int |
writeBytes(java.io.InputStream in, int length)
将指定流的内容从当前的
writerIndex开始传送到此缓冲区,并将传送的字节数增加到
writerIndex 。
|
int |
writeBytes(java.nio.channels.ScatteringByteChannel in, int length)
将指定通道的内容从当前的
writerIndex开始传送到此缓冲区,并将传送的字节数增加到
writerIndex 。
|
ByteBuf |
writeChar(int value)
在当前的
writerIndex处设置指定的2字节UTF-16字符,并在此缓冲区
writerIndex
2增加
writerIndex 。
|
int |
writeCharSequence(java.lang.CharSequence sequence, java.nio.charset.Charset charset)
将指定
CharSequence在当前
writerIndex并增加了
writerIndex由写入的字节。
|
ByteBuf |
writeDouble(double value)
在当前
writerIndex处设置指定的64位浮点数,并在此缓冲区
writerIndex
8增加
writerIndex 。
|
ByteBuf |
writeFloat(float value)
在当前的
writerIndex处设置指定的32位浮点数并在此缓冲区
writerIndex
4增加
writerIndex 。
|
ByteBuf |
writeInt(int value)
在当前
writerIndex处设置指定的32位整数,并在此缓冲区
writerIndex
4增加
writerIndex 。
|
ByteBuf |
writeIntLE(int value)
以小端字节顺序在当前
writerIndex处设置指定的32位整数,并在此缓冲区
writerIndex
4增加
writerIndex 。
|
ByteBuf |
writeLong(long value)
在当前
writerIndex处设置指定的64位长整数,并在此缓冲区
writerIndex
8增加
writerIndex 。
|
ByteBuf |
writeLongLE(long value)
以小端字节顺序在当前
writerIndex处设置指定的64位长整数,并在此缓冲区
writerIndex
8增加
writerIndex 。
|
ByteBuf |
writeMedium(int value)
在当前的
writerIndex处设置指定的24位中等整数,并在此缓冲区
writerIndex
3增加
writerIndex 。
|
ByteBuf |
writeMediumLE(int value)
以小端字节顺序在当前
writerIndex中设置指定的24位中等整数,并在此缓冲区
writerIndex
3增加
writerIndex 。
|
int |
writerIndex()
返回此缓冲区的
writerIndex 。
|
ByteBuf |
writerIndex(int writerIndex)
设置此缓冲区的
writerIndex 。
|
ByteBuf |
writeShort(int value)
在当前的
writerIndex处设置指定的16位短整数,并在此缓冲区
writerIndex
2增加
writerIndex 。
|
ByteBuf |
writeShortLE(int value)
在当前
writerIndex处设置Little Endian Byte Order中指定的16位短整数,并在此缓冲区
writerIndex
2增加
writerIndex 。
|
ByteBuf |
writeZero(int length)
填充这个缓冲器与
NUL (0x00)并从当前
writerIndex并增加了
writerIndex由指定的
length 。
|
alloc, array, arrayOffset, capacity, capacity, copy, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getDoubleLE, getFloatLE, hasArray, hasMemoryAddress, internalNioBuffer, isDirect, memoryAddress, nioBuffer, nioBufferCount, nioBuffers, order, readDoubleLE, readFloatLE, retain, retain, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setDoubleLE, setFloatLE, touch, touch, unwrap, writeDoubleLE, writeFloatLEclone, finalize, getClass, notify, notifyAll, wait, wait, waitrefCnt, release, releasepublic boolean isReadOnly()
ByteBuf
true 。
isReadOnly
ByteBuf
public ByteBuf asReadOnly()
ByteBuf
asReadOnly在课程
ByteBuf
public int maxCapacity()
ByteBuf
ByteBuf.capacity(int)或ByteBuf.ensureWritable(int)将此缓冲区的容量增加到最大容量以外 ,那么这些方法将引发IllegalArgumentException 。
maxCapacity
ByteBuf
protected final void maxCapacity(int maxCapacity)
public int readerIndex()
ByteBuf
readerIndex 。
readerIndex在课程
ByteBuf
public ByteBuf readerIndex(int readerIndex)
ByteBuf
readerIndex 。
readerIndex的
ByteBuf
public int writerIndex()
ByteBuf
writerIndex 。
writerIndex
ByteBuf
public ByteBuf writerIndex(int writerIndex)
ByteBuf
writerIndex 。
writerIndex
ByteBuf
public ByteBuf setIndex(int readerIndex, int writerIndex)
ByteBuf
readerIndex设置此缓冲区的readerIndex和writerIndex 。
当您不得不担心ByteBuf.readerIndex(int)和ByteBuf.writerIndex(int)方法的调用顺序时,此方法非常有用。
例如,以下代码将失败:
// Create a buffer whose readerIndex, writerIndex and capacity are
// 0, 0 and 8 respectively.
ByteBuf buf = Unpooled.buffer(8);
// IndexOutOfBoundsException is thrown because the specified
// readerIndex (2) cannot be greater than the current writerIndex (0).
buf.readerIndex(2);
buf.writerIndex(4);
以下代码也将失败:
// Create a buffer whose readerIndex, writerIndex and capacity are
// 0, 8 and 8 respectively.
ByteBuf buf = Unpooled.wrappedBuffer(new byte[8]);
// readerIndex becomes 8.
buf.readLong();
// IndexOutOfBoundsException is thrown because the specified
// writerIndex (4) cannot be less than the current readerIndex (8).
buf.writerIndex(4);
buf.readerIndex(2);
相比之下,只要指定的索引满足基本约束,该方法就保证它永远不会抛出IndexOutOfBoundsException ,无论缓冲区的当前索引值是什么:
// No matter what the current state of the buffer is, the following
// call always succeeds as long as the capacity of the buffer is not
// less than 4.
buf.setIndex(2, 4);
public ByteBuf clear()
ByteBuf
readerIndex和writerIndex设置为0 。
该方法与setIndex(0, 0)相同。
请注意,此方法的行为与NIO缓冲区的行为不同,后者将limit设置为limit的capacity 。
public boolean isReadable()
ByteBuf
true当且仅当
(this.writerIndex - this.readerIndex)大于
0 。
isReadable在课程
ByteBuf
public boolean isReadable(int numBytes)
ByteBuf
true 。
isReadable在课程
ByteBuf
public boolean isWritable()
ByteBuf
(this.capacity - this.writerIndex)大于
true时,返回
0 。
isWritable在课程
ByteBuf
public boolean isWritable(int numBytes)
ByteBuf
true 。
isWritable在课堂
ByteBuf
public int readableBytes()
ByteBuf
(this.writerIndex - this.readerIndex)的可读字节数。
readableBytes
ByteBuf
public int writableBytes()
ByteBuf
(this.capacity - this.writerIndex)的可写字节数。
writableBytes的
ByteBuf
public int maxWritableBytes()
ByteBuf
(this.maxCapacity - this.writerIndex) 。
maxWritableBytes
ByteBuf
public ByteBuf markReaderIndex()
ByteBuf
readerIndex 。
您可以重新定位当前readerIndex到标记readerIndex通过调用ByteBuf.resetReaderIndex() 。
标记的readerIndex的初始值是0 。
markReaderIndex在课程
ByteBuf
public ByteBuf resetReaderIndex()
ByteBuf
readerIndex重新定位到此缓冲区中标记为
readerIndex 。
resetReaderIndex在课堂上
ByteBuf
public ByteBuf markWriterIndex()
ByteBuf
writerIndex 。
您可以重新定位当前writerIndex到标记writerIndex通过调用ByteBuf.resetWriterIndex() 。
标记的初始值writerIndex是0 。
markWriterIndex在课程
ByteBuf
public ByteBuf resetWriterIndex()
ByteBuf
writerIndex重新定位到此缓冲区中标记为
writerIndex 。
resetWriterIndex在课程
ByteBuf
public ByteBuf discardReadBytes()
ByteBuf
readerIndex之间的字节。
它移动之间的字节readerIndex和writerIndex至第0索引,并且设置readerIndex和writerIndex至0和oldWriterIndex - oldReaderIndex分别。
请参阅班级文件以获得更详细的解释。
discardReadBytes在课堂上
ByteBuf
public ByteBuf discardSomeReadBytes()
ByteBuf
ByteBuf.discardReadBytes(),不同之
处在于此方法可能会根据其内部实施情况丢弃部分,全部或者全部读取字节,以减少潜在的额外内存消耗为代价的整体内存带宽消耗。
discardSomeReadBytes
ByteBuf
protected final void adjustMarkers(int decrement)
public ByteBuf ensureWritable(int minWritableBytes)
ByteBuf
ensureWritable
ByteBuf
minWritableBytes - 可写入字节的预期最小数量
public int ensureWritable(int minWritableBytes,
boolean force)
ByteBuf
ByteBuf.ensureWritable(int)不同,此方法不引发异常但返回代码。
ensureWritable ,上课
ByteBuf
minWritableBytes - 可写入字节的预期最小数量
force - 当ByteBuf.writerIndex() + minWritableBytes > ByteBuf.maxCapacity() :
true - 缓冲区的容量扩展到ByteBuf.maxCapacity() false - 缓冲区的容量不变 0如果缓冲区有足够的可写字节,并且其容量不变。
1如果缓冲区没有足够的字节,并且其容量不变。
2如果缓冲区有足够的可写字节,并且其容量已增加。
3如果缓冲区没有足够的字节,但其容量已增加到其最大值。
public ByteBuf order(java.nio.ByteOrder endianness)
ByteBuf
endianness的缓冲区,该缓冲区共享此缓冲区的整个区域,索引和标记。
修改返回的缓冲区或此缓冲区的内容,索引或标记会影响彼此的内容,索引和标记。
如果指定的endianness与此缓冲区的字节顺序相同,则此方法可返回this 。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected SwappedByteBuf newSwappedByteBuf()
ByteBuf实例创建一个新的SwappedByteBuf 。
public byte getByte(int index)
ByteBuf
index处获取一个字节。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract byte _getByte(int index)
public boolean getBoolean(int index)
ByteBuf
readerIndex或writerIndex 。
getBoolean在课堂
ByteBuf
public short getUnsignedByte(int index)
ByteBuf
index处获取无符号字节。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedByte
ByteBuf
public short getShort(int index)
ByteBuf
index处获取一个16位短整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract short _getShort(int index)
public short getShortLE(int index)
ByteBuf
index处获取16位短整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getShortLE在课程
ByteBuf
protected abstract short _getShortLE(int index)
public int getUnsignedShort(int index)
ByteBuf
index处获取一个无符号的16位短整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedShort
ByteBuf
public int getUnsignedShortLE(int index)
ByteBuf
index处获取一个无符号的16位短整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedShortLE
ByteBuf
public int getUnsignedMedium(int index)
ByteBuf
index处获取一个无符号的24位中等整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedMedium
ByteBuf
protected abstract int _getUnsignedMedium(int index)
public int getUnsignedMediumLE(int index)
ByteBuf
index处获取无符号的24位中等整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedMediumLE的
ByteBuf
protected abstract int _getUnsignedMediumLE(int index)
public int getMedium(int index)
ByteBuf
index处获取一个24位中等整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public int getMediumLE(int index)
ByteBuf
index处获取24位中等整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getMediumLE类
ByteBuf
public int getInt(int index)
ByteBuf
index处获取一个32位整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract int _getInt(int index)
public int getIntLE(int index)
ByteBuf
index处获取一个32位整数,其index字节顺序。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract int _getIntLE(int index)
public long getUnsignedInt(int index)
ByteBuf
index处获取一个无符号的32位整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedInt ,上课
ByteBuf
public long getUnsignedIntLE(int index)
ByteBuf
index处获取一个无符号的32位整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
getUnsignedIntLE在课堂上
ByteBuf
public long getLong(int index)
ByteBuf
index处获取64位长整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract long _getLong(int index)
public long getLongLE(int index)
ByteBuf
index处获取64位长整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract long _getLongLE(int index)
public char getChar(int index)
ByteBuf
index处获取一个2字节的UTF-16字符。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public float getFloat(int index)
ByteBuf
index处获取一个32位浮点数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public double getDouble(int index)
ByteBuf
index处获取一个64位浮点数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf getBytes(int index, byte[] dst)
ByteBuf
index 。
此方法不会修改此缓冲区的readerIndex或writerIndex
public ByteBuf getBytes(int index, ByteBuf dst)
ByteBuf
index开始index直到目标位置变为不可写入。
该方法与ByteBuf.getBytes(int, ByteBuf, int, int)基本相同,不同之writerIndex于此方法通过传输字节数增加目标的writerIndex ,而ByteBuf.getBytes(int, ByteBuf, int, int)则不增加。
此方法不会修改源缓冲区的readerIndex或writerIndex (即this )。
public ByteBuf getBytes(int index, ByteBuf dst, int length)
ByteBuf
index 。
此方法与ByteBuf.getBytes(int, ByteBuf, int, int)基本相同,不同之writerIndex于此方法通过传输字节数增加目标的writerIndex ,而ByteBuf.getBytes(int, ByteBuf, int, int)则不增加。
此方法不会修改源缓冲区的readerIndex或writerIndex (即this )。
public java.lang.CharSequence getCharSequence(int index,
int length,
java.nio.charset.Charset charset)
ByteBuf
CharSequence 。
getCharSequence在课程
ByteBuf
length - 阅读的长度
charset - 应该使用
public java.lang.CharSequence readCharSequence(int length,
java.nio.charset.Charset charset)
ByteBuf
readerIndex处获得给定长度的
CharSequence ,并将给定长度增加
readerIndex 。
readCharSequence的
ByteBuf
length - 要读取的长度
charset - 应该使用
public ByteBuf setByte(int index, int value)
ByteBuf
index处设置指定的字节。
指定值的24个高位被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setByte(int index,
int value) public ByteBuf setBoolean(int index, boolean value)
ByteBuf
index处设置指定的布尔值。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
setBoolean类
ByteBuf
public ByteBuf setShort(int index, int value)
ByteBuf
index处设置指定的16位短整数。
指定值的16个高位被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setShort(int index,
int value) public ByteBuf setShortLE(int index, int value)
ByteBuf
index处设置指定的16位短整数,并使用Little Endian Byte Order。
指定值的16个高位被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
setShortLE在课堂上
ByteBuf
protected abstract void _setShortLE(int index,
int value) public ByteBuf setChar(int index, int value)
ByteBuf
index处设置指定的2字节UTF-16字符。
指定值的16个高位被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf setMedium(int index, int value)
ByteBuf
index处设置指定的24位中等整数。
请注意,最高有效字节在指定值中被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setMedium(int index,
int value) public ByteBuf setMediumLE(int index, int value)
ByteBuf
index处设置指定的24位中等整数。
请注意,最高有效字节在指定值中被忽略。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
setMediumLE在课堂
ByteBuf
protected abstract void _setMediumLE(int index,
int value) public ByteBuf setInt(int index, int value)
ByteBuf
index处设置指定的32位整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setInt(int index,
int value) public ByteBuf setIntLE(int index, int value)
ByteBuf
index处设置指定的32位整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setIntLE(int index,
int value) public ByteBuf setFloat(int index, float value)
ByteBuf
index处设置指定的32位浮点数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf setLong(int index, long value)
ByteBuf
index处设置指定的64位长整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setLong(int index,
long value) public ByteBuf setLongLE(int index, long value)
ByteBuf
index处设置指定的64位长整数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
protected abstract void _setLongLE(int index,
long value) public ByteBuf setDouble(int index, double value)
ByteBuf
index处设置指定的64位浮点数。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf setBytes(int index, byte[] src)
ByteBuf
index 。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf setBytes(int index, ByteBuf src)
ByteBuf
index开始传输到此缓冲区,直到源缓冲区变得不可读。
此方法与ByteBuf.setBytes(int, ByteBuf, int, int)基本相同,不同之readerIndex于此方法将源缓冲区的readerIndex增加了传输字节数,而ByteBuf.setBytes(int, ByteBuf, int, int)则不增加。
此方法不会修改源缓冲区的readerIndex或writerIndex (即this )。
public ByteBuf setBytes(int index, ByteBuf src, int length)
ByteBuf
index 。
此方法与ByteBuf.setBytes(int, ByteBuf, int, int)基本相同,不同之readerIndex于此方法将源缓冲区的readerIndex增加了传输字节数,而ByteBuf.setBytes(int, ByteBuf, int, int)则不增加。
此方法不会修改源缓冲区的readerIndex或writerIndex (即this )。
public ByteBuf setZero(int index, int length)
ByteBuf
index开始填充此缓冲区。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public int setCharSequence(int index,
java.lang.CharSequence sequence,
java.nio.charset.Charset charset)
ByteBuf
CharSequence在当前
writerIndex并增加了
writerIndex由写入的字节。
setCharSequence ,上课
ByteBuf
index - 应在其上写入序列
sequence - 写
charset - 应该使用。
public byte readByte()
ByteBuf
readerIndex处获取一个字节,并在此缓冲区
readerIndex
1增加
readerIndex 。
public boolean readBoolean()
ByteBuf
readerIndex的布尔值,并在此缓冲区
readerIndex
1增加
readerIndex 。
readBoolean ,上课
ByteBuf
public short readUnsignedByte()
ByteBuf
readerIndex的无符号字节,并在此缓冲区
readerIndex
1增加
readerIndex 。
readUnsignedByte
ByteBuf
public short readShort()
ByteBuf
readerIndex并增加了
readerIndex通过
2在该缓冲液。
public short readShortLE()
ByteBuf
readerIndex在Little Endian字节序,并增加了
readerIndex通过
2在缓冲区中。
readShortLE在课堂
ByteBuf
public int readUnsignedShort()
ByteBuf
readerIndex并增加了
readerIndex通过
2在该缓冲液。
readUnsignedShort在课程
ByteBuf
public int readUnsignedShortLE()
ByteBuf
readerIndex在Little Endian字节序,并增加了
readerIndex通过
2在缓冲区中。
readUnsignedShortLE
ByteBuf
public int readMedium()
ByteBuf
readerIndex处获取24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
readMedium在课堂
ByteBuf
public int readMediumLE()
ByteBuf
readerIndex以Little Endian字节顺序获取一个24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
readMediumLE在课堂
ByteBuf
public int readUnsignedMedium()
ByteBuf
readerIndex处获取一个无符号的24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
readUnsignedMedium在课程
ByteBuf
public int readUnsignedMediumLE()
ByteBuf
readerIndex中以Little Endian Byte顺序获取一个无符号的24位中等整数,并在此缓冲区
readerIndex
3增加
readerIndex 。
readUnsignedMediumLE
ByteBuf
public int readInt()
ByteBuf
readerIndex并增加了
readerIndex通过
4在该缓冲液。
public int readIntLE()
ByteBuf
readerIndex在Little Endian字节序,并增加了
readerIndex通过
4在该缓冲液。
public long readUnsignedInt()
ByteBuf
readerIndex处获取一个无符号的32位整数,并在此缓冲区
readerIndex
4增加
readerIndex 。
readUnsignedInt的
ByteBuf
public long readUnsignedIntLE()
ByteBuf
readerIndex以Little Endian字节顺序获取一个无符号的32位整数,并在此缓冲区
readerIndex
4增加
readerIndex 。
readUnsignedIntLE ,课时
ByteBuf
public long readLong()
ByteBuf
readerIndex处获取64位整数,并在此缓冲区
readerIndex
8增加
readerIndex 。
public long readLongLE()
ByteBuf
readerIndex在Little Endian字节序,并增加了
readerIndex通过
8在该缓冲液。
readLongLE
ByteBuf
public char readChar()
ByteBuf
readerIndex并增加了
readerIndex通过
2在该缓冲液。
public float readFloat()
ByteBuf
readerIndex处获得一个32位浮点数,并在此缓冲区
readerIndex
4增加
readerIndex 。
public double readDouble()
ByteBuf
readerIndex处获取一个64位浮点数,并在此缓冲区
readerIndex
8增加
readerIndex 。
readDouble在课堂
ByteBuf
public ByteBuf readBytes(int length)
ByteBuf
readerIndex并增加了readerIndex由传输的字节(=数量length )。
返回缓冲区的readerIndex和writerIndex是0和length分别。
public ByteBuf readSlice(int length)
ByteBuf
readerIndex开始返回此缓冲区子区域的一个新切片,并将该readerIndex的大小增加readerIndex (= length )。
另外请注意,此方法不会调用ByteBuf.retain() ,因此引用计数不会增加。
public ByteBuf readRetainedSlice(int length)
ByteBuf
readerIndex并增加了readerIndex由新的切片(=大小length )。
请注意,与ByteBuf.readSlice(int)不同,此方法返回retained缓冲区。 此方法的行为与readSlice(...).retain()类似,只不过此方法可能会返回一个生成较少垃圾的缓冲区实现。
readRetainedSlice在课堂上
ByteBuf
length - 新切片的大小
public ByteBuf readBytes(byte[] dst, int dstIndex, int length)
ByteBuf
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
public ByteBuf readBytes(byte[] dst)
ByteBuf
readerIndex并增加了
readerIndex由传输的字节(=数量
dst.length )。
public ByteBuf readBytes(ByteBuf dst)
ByteBuf
readerIndex开始,直到目标变为不可写,并将传输字节数增加readerIndex 。
此方法与ByteBuf.readBytes(ByteBuf, int, int)基本相同,不同之writerIndex于此方法通过传输字节数增加目标的writerIndex ,而ByteBuf.readBytes(ByteBuf, int, int)则不增加。
public ByteBuf readBytes(ByteBuf dst, int length)
ByteBuf
readerIndex并增加了readerIndex由传输的字节(=数量length )。
此方法与ByteBuf.readBytes(ByteBuf, int, int)基本相同,不同之writerIndex于此方法通过传输的字节数(= length )增加目标的writerIndex ,而ByteBuf.readBytes(ByteBuf, int, int)则不增加。
public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length)
ByteBuf
readerIndex并增加了
readerIndex由传输的字节(=数量
length )。
public ByteBuf readBytes(java.nio.ByteBuffer dst)
ByteBuf
readerIndex开始的指定目标,直到目标的位置达到其限制,并将
readerIndex增加
readerIndex传输的字节数。
public int readBytes(java.nio.channels.GatheringByteChannel out,
int length)
throws java.io.IOException
ByteBuf
readerIndex开始的指定流。
public int readBytes(java.nio.channels.FileChannel out,
long position,
int length)
throws java.io.IOException
ByteBuf
readerIndex到指定通道,从给定的文件位置开始。
此方法不会修改频道的位置。
public ByteBuf readBytes(java.io.OutputStream out, int length) throws java.io.IOException
ByteBuf
readerIndex开始的指定流。
public ByteBuf writeBoolean(boolean value)
ByteBuf
writerIndex处设置指定的布尔值,并在此缓冲区
writerIndex
1增加
writerIndex 。
writeBoolean在课堂
ByteBuf
public ByteBuf writeByte(int value)
ByteBuf
writerIndex处设置指定的字节,并在此缓冲区writerIndex 1增加writerIndex 。
指定值的24个高位被忽略。
public ByteBuf writeShort(int value)
ByteBuf
writerIndex处设置指定的16位短整数,并在此缓冲区writerIndex 2增加writerIndex 。
指定值的16个高位被忽略。
writeShort在课程
ByteBuf
public ByteBuf writeShortLE(int value)
ByteBuf
writerIndex处设置Little Endian Byte Order中指定的16位短整数,并在此缓冲区writerIndex 2增加writerIndex 。
指定值的16个高位被忽略。
writeShortLE的
ByteBuf
public ByteBuf writeMedium(int value)
ByteBuf
writerIndex中设置指定的24位中等整数,并在此缓冲区
writerIndex
3增加
writerIndex 。
writeMedium在课堂
ByteBuf
public ByteBuf writeMediumLE(int value)
ByteBuf
writerIndex处设置指定的24位中等整数,并在此缓冲区
writerIndex
3增加
writerIndex 。
writeMediumLE在课程
ByteBuf
public ByteBuf writeInt(int value)
ByteBuf
writerIndex处设置指定的32位整数,并在此缓冲区
writerIndex
4增加
writerIndex 。
public ByteBuf writeIntLE(int value)
ByteBuf
writerIndex处设置指定的32位整数,并在此缓冲区
writerIndex
4增加
writerIndex 。
writeIntLE在
ByteBuf
public ByteBuf writeLong(long value)
ByteBuf
writerIndex处设置指定的64位长整数,并在此缓冲区
writerIndex
8增加
writerIndex 。
public ByteBuf writeLongLE(long value)
ByteBuf
writerIndex处设置指定的64位长整数,并在此缓冲区
writerIndex
8增加
writerIndex 。
writeLongLE
ByteBuf
public ByteBuf writeChar(int value)
ByteBuf
writerIndex处设置指定的2字节UTF-16字符,并在此缓冲区writerIndex 2增加writerIndex 。
指定值的16个高位被忽略。
public ByteBuf writeFloat(float value)
ByteBuf
writerIndex处设置指定的32位浮点数,并在此缓冲区
writerIndex
4增加
writerIndex 。
writeFloat
ByteBuf
public ByteBuf writeDouble(double value)
ByteBuf
writerIndex处设置指定的64位浮点数,并在此缓冲区
writerIndex
8增加
writerIndex 。
writeDouble在课堂
ByteBuf
public ByteBuf writeBytes(byte[] src, int srcIndex, int length)
ByteBuf
writerIndex并增加了
writerIndex由传输的字节(=数量
length )。
writeBytes的
ByteBuf
srcIndex - 来源的第一个索引
length - 要传输的字节数
public ByteBuf writeBytes(byte[] src)
ByteBuf
writerIndex并增加了
writerIndex由传输的字节(=数量
src.length )。
writeBytes在课堂上
ByteBuf
public ByteBuf writeBytes(ByteBuf src)
ByteBuf
writerIndex开始传输到此缓冲区,直到源缓冲区变得不可读,并将传输字节数增加writerIndex 。
该方法与ByteBuf.writeBytes(ByteBuf, int, int)基本相同,不同之readerIndex于此方法将源缓冲区的readerIndex增加了传输字节数,而ByteBuf.writeBytes(ByteBuf, int, int)则不增加。
writeBytes在课堂上
ByteBuf
public ByteBuf writeBytes(ByteBuf src, int length)
ByteBuf
writerIndex并增加了writerIndex由传输的字节(=数量length )。
此方法与ByteBuf.writeBytes(ByteBuf, int, int)基本相同,不同之readerIndex于此方法将源缓冲区的readerIndex增加了传输字节数(= length ),而ByteBuf.writeBytes(ByteBuf, int, int)则不增加。
writeBytes在课堂
ByteBuf
length - 要传输的字节数
public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length)
ByteBuf
writerIndex并增加了
writerIndex由传输的字节(=数量
length )。
writeBytes类
ByteBuf
srcIndex - 来源的第一个索引
length - 要传输的字节数
public ByteBuf writeBytes(java.nio.ByteBuffer src)
ByteBuf
writerIndex开始传输到此缓冲区,直到源缓冲区的位置达到其限制,并将传输字节数增加
writerIndex 。
writeBytes
ByteBuf
public int writeBytes(java.io.InputStream in,
int length)
throws java.io.IOException
ByteBuf
writerIndex开始传送到此缓冲区,并将传送的字节数增加到
writerIndex 。
writeBytes的
ByteBuf
length - 要传输的字节数
java.io.IOException - 如果指定的流在I / O期间抛出异常
public int writeBytes(java.nio.channels.ScatteringByteChannel in,
int length)
throws java.io.IOException
ByteBuf
writerIndex开始传送到此缓冲区,并将传送的字节数增加到
writerIndex 。
writeBytes
ByteBuf
length - 传输的最大字节数
java.io.IOException - 如果指定的通道在I / O期间引发异常
public int writeBytes(java.nio.channels.FileChannel in,
long position,
int length)
throws java.io.IOException
ByteBuf
writerIndex开始,并将writerIndex增加writerIndex 。
此方法不会修改频道的位置。
writeBytes类
ByteBuf
position - 传输开始的文件位置
length - 传输的最大字节数
java.io.IOException - 如果指定的通道在I / O期间引发异常
public ByteBuf writeZero(int length)
ByteBuf
writerIndex并增加了
writerIndex由指定的
length 。
public int writeCharSequence(java.lang.CharSequence sequence,
java.nio.charset.Charset charset)
ByteBuf
CharSequence在当前writerIndex并增加了writerIndex由写入的字节。
在这个缓冲区中。
writeCharSequence在课程
ByteBuf
sequence - 写
charset - 应该使用
public ByteBuf copy()
ByteBuf
buf.copy(buf.readerIndex(), buf.readableBytes())相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public ByteBuf duplicate()
ByteBuf
readerIndex或writerIndex 。
读者和作家的标记不会重复。 另外请注意,此方法不会调用ByteBuf.retain() ,因此引用计数不会增加。
duplicate在课堂上
ByteBuf
ByteBuf.slice()返回的缓冲区的缓冲区。
然而,这个缓冲区将共享底层缓冲区的容量,因此如果需要的话允许访问所有的底层内容。
public ByteBuf retainedDuplicate()
ByteBuf
buf.slice(0, buf.capacity())相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
请注意,与ByteBuf.slice(int, int)不同,此方法返回retained缓冲区。 此方法的行为与duplicate().retain()类似,只是此方法可能会返回一个生成较少垃圾的缓冲区实现。
retainedDuplicate在课程
ByteBuf
public ByteBuf slice()
ByteBuf
buf.slice(buf.readerIndex(), buf.readableBytes())相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
另外请注意,此方法不会调用ByteBuf.retain() ,因此引用计数不会增加。
public ByteBuf retainedSlice()
ByteBuf
buf.slice(buf.readerIndex(), buf.readableBytes())相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
请注意,与ByteBuf.slice()不同,此方法返回retained缓冲区。 此方法的行为与slice().retain()类似,只是此方法可能会返回一个生成较少垃圾的缓冲区实现。
retainedSlice
ByteBuf
public ByteBuf slice(int index, int length)
ByteBuf
readerIndex或writerIndex 。
另外请注意,此方法不会调用ByteBuf.retain() ,因此引用计数不会增加。
public ByteBuf retainedSlice(int index, int length)
ByteBuf
readerIndex或writerIndex 。
请注意,与ByteBuf.slice(int, int)不同,此方法返回retained缓冲区。 此方法的行为与slice(...).retain()类似,只不过此方法可能会返回一个生成较少垃圾的缓冲区实现。
retainedSlice在课堂
ByteBuf
public java.nio.ByteBuffer nioBuffer()
ByteBuf
ByteBuffer 。
返回的缓冲区共享或包含此缓冲区的复制内容,同时更改返回的NIO缓冲区的位置和限制不会影响此缓冲区的索引和标记。
该方法与buf.nioBuffer(buf.readerIndex(), buf.readableBytes())相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
请注意,如果此缓冲区是动态缓冲区并且它调整了其容量,则返回的NIO缓冲区将不会看到此缓冲区的更改。
nioBuffer
ByteBuf
ByteBuf.nioBufferCount() ,
ByteBuf.nioBuffers() ,
ByteBuf.nioBuffers(int, int)
public java.nio.ByteBuffer[] nioBuffers()
ByteBuf
ByteBuffer的形式公开此缓冲区的可读字节。
返回的缓冲区共享或包含此缓冲区的复制内容,同时更改返回的NIO缓冲区的位置和限制不会影响此缓冲区的索引和标记。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
请注意,如果此缓冲区是动态缓冲区并且它调整了其容量,则返回的NIO缓冲区将不会看到此缓冲区的更改。
nioBuffers在课程
ByteBuf
ByteBuf.nioBufferCount() ,
ByteBuf.nioBuffer() ,
ByteBuf.nioBuffer(int, int)
public java.lang.String toString(java.nio.charset.Charset charset)
ByteBuf
buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)相同。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public java.lang.String toString(int index,
int length,
java.nio.charset.Charset charset)
ByteBuf
readerIndex或writerIndex 。
public int indexOf(int fromIndex,
int toIndex,
byte value)
ByteBuf
value 。
搜索从指定的fromIndex (含)到指定的toIndex ( toIndex )。
如果fromIndex大于toIndex ,则搜索按相反顺序执行。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
public int bytesBefore(byte value)
ByteBuf
value 。
搜索从当前的readerIndex (含)至当前的writerIndex ( writerIndex )。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
bytesBefore在课程
ByteBuf
readerIndex与第一个匹配项之间的字节数(如果找到)。
-1否则。
public int bytesBefore(int length,
byte value)
ByteBuf
value 。
搜索从当前的readerIndex (含)开始并持续指定的length 。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
bytesBefore
ByteBuf
readerIndex与第一个匹配项之间的字节数(如果找到)。
-1否则。
public int bytesBefore(int index,
int length,
byte value)
ByteBuf
value 。
搜索从指定的index (含)开始并持续指定的length 。
此方法不会修改此缓冲区的readerIndex或writerIndex 。
bytesBefore在课程
ByteBuf
index与第一个匹配项之间的字节数(如果找到)。
否则-1 。
public int forEachByte(ByteProcessor processor)
ByteBuf
processor按升序对此缓冲区的可读字节进行迭代。
forEachByte
ByteBuf
-1如果处理器迭代到或超出可读字节的末尾。
上次访问的索引如果ByteProcessor.process(byte)返回false 。
public int forEachByte(int index,
int length,
ByteProcessor processor)
ByteBuf
processor按升序迭代该缓冲区的指定区域。
(即index , (index + 1) ,.. (index + length - 1) )
forEachByte在课程
ByteBuf
-1如果处理器迭代到或超出指定区域的末尾。
上次访问的索引如果ByteProcessor.process(byte)返回false 。
public int forEachByteDesc(ByteProcessor processor)
ByteBuf
processor降序遍历此缓冲区的可读字节。
forEachByteDesc
ByteBuf
-1如果处理器迭代到或超出可读字节的开始位置。
最后访问的索引如果ByteProcessor.process(byte)返回false 。
public int forEachByteDesc(int index,
int length,
ByteProcessor processor)
ByteBuf
processor以降序遍历此缓冲区的指定区域。
(即(index + length - 1) , (index + length - 2) ,... index )
forEachByteDesc在课程
ByteBuf
-1如果处理器迭代到或超出指定区域的开始位置。
上次访问的索引如果ByteProcessor.process(byte)返回false 。
public int hashCode()
ByteBuf
public boolean equals(java.lang.Object o)
ByteBuf
ByteBuf.readerIndex()和ByteBuf.writerIndex() 。
此方法还会为null返回false ,并返回一个不是ByteBuf类型实例的对象 。
public int compareTo(ByteBuf that)
ByteBuf
strcmp , memcmp和String.compareTo(String) 。
public java.lang.String toString()
ByteBuf
ByteBuf.readerIndex() , ByteBuf.writerIndex()和ByteBuf.capacity() 。
protected final void checkIndex(int index)
protected final void checkIndex(int index,
int fieldLength) protected final void checkSrcIndex(int index,
int length,
int srcIndex,
int srcCapacity) protected final void checkDstIndex(int index,
int length,
int dstIndex,
int dstCapacity) protected final void checkReadableBytes(int minimumReadableBytes)
protected final void checkNewCapacity(int newCapacity)
protected final void ensureAccessible()
Copyright © 2008–2018 The Netty Project. All rights reserved.