public class RingDirectBuffer extends Object
| Constructor and Description |
|---|
RingDirectBuffer()
使用默认容量构造一个环形缓冲区
|
RingDirectBuffer(ByteBuffer byteBuffer)
使用指定容量构造一个环形缓冲区
|
RingDirectBuffer(int capacity)
使用指定容量构造一个环形缓冲区
|
| Modifier and Type | Method and Description |
|---|---|
int |
avaliable()
缓冲区可写空间
|
void |
clear()
清理缓冲区
|
void |
compact() |
int |
get(byte[] bytes,
int offset,
int length)
读取所有缓冲区的数据
不影响读写位置
|
int |
get(ByteBuffer byteBuffer)
读取所有缓冲区的数据
不影响读写位置
|
byte |
get(int offset)
获得基于索引位置的数据
|
long |
getAddress()
获得环形缓冲区的基地址
|
ByteBuffer |
getByteBuffer()
获得一个只读的 ByteBuffer 类型的数据
|
int |
getCapacity()
获得容量
|
int |
getReadPositon()
获得读指针位置
|
int |
getWritePositon()
获得写指针位置
|
int |
indexOf(byte[] mark)
查找特定 byte 标识的位置
byte 标识数组第一个字节的索引位置
|
Boolean |
isEmpty()
缓冲区空判断
|
Boolean |
isFull()
缓冲区满判断
|
boolean |
isReleased() |
byte |
read()
读取一个 byte
|
int |
read(byte[] bytes,
int offset,
int length)
读取缓冲区的数据
|
int |
read(ByteBuffer byteBuffer)
读取缓冲区的数据
|
String |
readLine()
读取一行
|
void |
release()
释放内存中的数据
|
int |
remaining()
缓冲区可读数据量
|
void |
resetAddress() |
void |
saveToFile(String filePath,
long length)
保存到文件
|
boolean |
skip(int offset)
读指针跳过特定的偏移量
|
boolean |
startWith(byte[] mark) |
byte[] |
toArray()
读取所有缓冲区的数据
不影响读写位置
|
String |
toString() |
boolean |
tryExpansion(int dataSize)
重新分配内存空间的大小
|
boolean |
waitData(byte[] mark,
int timeout,
Runnable supplier)
从头部开始判断是否收到期望的数据
|
boolean |
waitData(int length,
int timeout,
Runnable supplier)
等待期望的数据长度
|
void |
write(byte b)
写入一个 byte
|
int |
write(byte[] bytes,
int offset,
int length)
写入一个 byte[] 数据
|
int |
write(ByteBuffer byteBuffer)
写入一个 byteBuffer
|
public RingDirectBuffer()
public RingDirectBuffer(int capacity)
capacity - 分配的容量public RingDirectBuffer(ByteBuffer byteBuffer)
byteBuffer - ByteBuffer 对象public long getAddress()
public int getReadPositon()
public int getWritePositon()
public int getCapacity()
public boolean skip(int offset)
offset - 偏移量public Boolean isEmpty()
public Boolean isFull()
public void clear()
public byte get(int offset)
offset - 偏移量public int get(ByteBuffer byteBuffer)
byteBuffer - ByteBuffer 对象public int get(byte[] bytes,
int offset,
int length)
bytes - 用于读取数据的 byte 数组offset - 偏移量length - 数据长度public byte[] toArray()
public void write(byte b)
b - byte 数据public int write(byte[] bytes,
int offset,
int length)
bytes - byte[] 对象offset - 针对 byte[] 的偏移量length - 写入数据的长度public int write(ByteBuffer byteBuffer)
byteBuffer - ByteBuffer 对象public int remaining()
public int avaliable()
public byte read()
public int read(ByteBuffer byteBuffer)
byteBuffer - ByteBuffer 对象public int read(byte[] bytes,
int offset,
int length)
bytes - 用于读取数据的 byte 数组offset - 偏移量length - 读取数据的长度public ByteBuffer getByteBuffer()
public void compact()
public int indexOf(byte[] mark)
mark - byte 标识数组public boolean startWith(byte[] mark)
public boolean waitData(int length,
int timeout,
Runnable supplier)
length - 期望的数据长度timeout - 超时时间,单位: 毫秒supplier - 每次等待数据所做的操作public boolean waitData(byte[] mark,
int timeout,
Runnable supplier)
mark - 期望出现的数据timeout - 超时时间,单位: 毫秒supplier - 每次等待数据所做的操作public String readLine()
public void saveToFile(String filePath, long length) throws IOException
filePath - 文件路径length - 需要保存的长度IOException - Io 异常public boolean isReleased()
public void release()
public boolean tryExpansion(int dataSize)
throws LargerThanMaxSizeException
dataSize - 重新分配的空间大小LargerThanMaxSizeException - 通道容量不足的一场public void resetAddress()
Copyright © 2020 Voovan. All rights reserved.