public class AutoByteBuffer extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
AutoByteBuffer.ByteBufferException |
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
BUFFER_SIZE
默认的长度
|
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
allWriteBytesArray()
获取已写入的数据
|
byte[] |
array()
获取未处理byte[],就是获取原始数组的意思
|
int |
capacity()
当前容量,当写入数据超过当前容量后会自动扩容
|
AutoByteBuffer |
clear()
清空数据,重置指针
|
String |
decodeString(AutoByteBuffer src,
int readerIndex,
int len,
Charset charset)
指定解析成string
|
void |
discardReadBytes()
删除已读部分,保留未读部分
读下标初始为0,写下标为未读长度
|
AutoByteBuffer |
duplicate()
复制自身
|
byte[] |
getBytes(int start,
int length)
获取指定的数组
|
boolean |
hasArray()
数组是否有长度
|
boolean |
hasRemaining()
当前是否有可读数据
|
static AutoByteBuffer |
newByteBuffer()
获取一个新的实例
|
static AutoByteBuffer |
newByteBuffer(int capacity)
获取一个新的实例
|
int |
read()
读取一个数据到byte,从readIndex位置开始,每读取一个,指针+1,类似byteBuffer的get方法
|
byte |
read(int index)
读取制定下标的一个byte。
|
int |
readableBytes()
当前可读长度,writerIndex - readerIndex
|
byte[] |
readableBytesArray()
获取剩余未读数据
|
byte |
readByte()
读取数据到byte,1 byte,从readIndex位置开始
|
int |
readBytes(AutoByteBuffer b)
读取数据到另一个ByteBuffer
|
int |
readBytes(byte[] bytes)
读取数据到bytes,从readIndex位置开始
|
int |
readBytes(byte[] bytes,
int offset,
int length)
读取数据到bytes,写入从offset到offset+length的区域
|
int |
readerIndex()
读取指针位置
|
AutoByteBuffer |
readerIndex(int position)
重置读指针位置,相当于指定下次开始读取的下标
如果大于写入位置,则可读位置重置为写入位置,readableBytes()结果则为0
|
int |
readInt()
读取integer值,读4 byte转换为integer,从readIndex位置开始
|
AutoByteBuffer |
readRetainedSlice(int len)
读取指定长度的数据,返回AutoByteBuffer
|
short |
readUnsignedByte()
读取无符号byte
|
AutoByteBuffer |
reset()
清理指针标记,数组内容保留,下次写入会被覆盖,除了array()获取原始数组外无法得到旧数据
|
AutoByteBuffer |
skipBytes(int length)
获取长度下标
|
String |
toString() |
String |
toString(int index,
int length,
Charset charset)
解析成string
|
int |
writableBytes()
当前剩余可写入数据长度,每次触发扩容后都不一样
|
AutoByteBuffer |
write(int b)
写入int值的byte转换结果,即丢弃高位
|
AutoByteBuffer |
writeByte(byte b)
写入Byte数据,1 byte,类似byteBuffer的put
|
AutoByteBuffer |
writeBytes(AutoByteBuffer b)
写入一个ByteBuffer可读数据
|
AutoByteBuffer |
writeBytes(AutoByteBuffer b,
int dataLength)
写入一个ByteBuffer可读数据的部分长度
|
AutoByteBuffer |
writeBytes(byte[] b)
写入数组
|
AutoByteBuffer |
writeBytes(byte[] b,
int len)
写入数组,并指定写入长度
|
AutoByteBuffer |
writeBytes(byte[] src,
int srcIndex,
int len)
写入一个数组,指定位置
|
AutoByteBuffer |
writeInt(int b)
写入integer数据,4 byte
|
int |
writerIndex()
写入指针位置
|
AutoByteBuffer |
writeShort(int value)
写入一个short
|
public static final int BUFFER_SIZE
public static AutoByteBuffer newByteBuffer()
public static AutoByteBuffer newByteBuffer(int capacity)
capacity - 长度public AutoByteBuffer readerIndex(int position)
position - 下标public byte[] array()
public AutoByteBuffer clear()
public AutoByteBuffer reset()
public byte[] readableBytesArray()
public byte[] allWriteBytesArray()
public void discardReadBytes()
public int readerIndex()
public int writerIndex()
public int readableBytes()
public boolean hasRemaining()
public boolean hasArray()
public int writableBytes()
public int capacity()
public int read()
throws AutoByteBuffer.ByteBufferException
AutoByteBuffer.ByteBufferException - 抛出异常public byte read(int index)
throws AutoByteBuffer.ByteBufferException
index - AutoByteBuffer.ByteBufferExceptionpublic byte readByte()
throws AutoByteBuffer.ByteBufferException
AutoByteBuffer.ByteBufferException - 抛出异常public short readUnsignedByte()
throws AutoByteBuffer.ByteBufferException
public int readInt()
throws AutoByteBuffer.ByteBufferException
AutoByteBuffer.ByteBufferException - 抛出异常public int readBytes(byte[] bytes)
throws AutoByteBuffer.ByteBufferException
bytes - 数组AutoByteBuffer.ByteBufferException - 抛出异常public int readBytes(byte[] bytes,
int offset,
int length)
throws AutoByteBuffer.ByteBufferException
bytes - 数组offset - 下标length - 长度AutoByteBuffer.ByteBufferException - 抛出异常public int readBytes(AutoByteBuffer b)
b - 数组public AutoByteBuffer readRetainedSlice(int len) throws AutoByteBuffer.ByteBufferException
len - AutoByteBuffer.ByteBufferExceptionpublic AutoByteBuffer writeByte(byte b)
b - 字节public AutoByteBuffer write(int b)
b - 整数字节public AutoByteBuffer writeInt(int b)
b - 整数字节public AutoByteBuffer writeShort(int value)
value - public AutoByteBuffer writeBytes(byte[] b)
b - 写入数据public AutoByteBuffer writeBytes(byte[] b, int len)
b - 数据len - 写入长度public AutoByteBuffer writeBytes(byte[] src, int srcIndex, int len)
src - 来源数组srcIndex - 来源数组开始位置len - 来源数组写入长度public AutoByteBuffer writeBytes(AutoByteBuffer b)
b - 写入数据public AutoByteBuffer writeBytes(AutoByteBuffer b, int dataLength)
b - 数据dataLength - 写入长度public AutoByteBuffer duplicate()
public String toString(int index, int length, Charset charset)
index - length - charset - public byte[] getBytes(int start,
int length)
start - length - public AutoByteBuffer skipBytes(int length)
length - public String decodeString(AutoByteBuffer src, int readerIndex, int len, Charset charset)
src - readerIndex - len - charset - Copyright © 2021. All rights reserved.