public class CircularByteBuffer extends Object
Constructor and Description |
---|
CircularByteBuffer()
默认缓冲大小的构造(
NioUtil.DEFAULT_BUFFER_SIZE ) |
CircularByteBuffer(int pSize)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
add(byte value)
增加byte到buffer中
|
void |
add(byte[] targetBuffer,
int offset,
int length)
Adds the given bytes to the buffer.
|
void |
clear()
Removes all bytes from the buffer.
|
int |
getCurrentNumberOfBytes()
Returns the number of bytes, that are currently present in the buffer.
|
int |
getSpace()
Returns the number of bytes, that can currently be added to the buffer.
|
boolean |
hasBytes()
Returns, whether the buffer is currently holding, at least, a single byte.
|
boolean |
hasSpace()
Returns, whether there is currently room for a single byte in the buffer.
|
boolean |
hasSpace(int count)
Returns, whether there is currently room for the given number of bytes in the buffer.
|
boolean |
peek(byte[] sourceBuffer,
int offset,
int length)
Returns, whether the next bytes in the buffer are exactly those, given by
sourceBuffer , offset , and length . |
byte |
read()
从buffer中读取下一个byte,同时移除这个bytes。
|
void |
read(byte[] targetBuffer,
int targetOffset,
int length)
Returns the given number of bytes from the buffer by storing them in
the given byte array at the given offset.
|
public CircularByteBuffer()
NioUtil.DEFAULT_BUFFER_SIZE
)public CircularByteBuffer(int pSize)
pSize
- 缓冲大小public byte read()
IllegalStateException
- buffer为空抛出,使用hasBytes()
,或 getCurrentNumberOfBytes()
判断public void read(byte[] targetBuffer, int targetOffset, int length)
targetBuffer
- 目标bytestargetOffset
- 目标数组开始位置length
- 读取长度NullPointerException
- 提供的数组为null
IllegalArgumentException
- targetOffset
或length
为负数或targetBuffer
太小IllegalStateException
- buffer中的byte不足,使用getCurrentNumberOfBytes()
判断。public void add(byte value)
value
- The byteIllegalStateException
- buffer已满. 用hasSpace()
或getSpace()
判断。public boolean peek(byte[] sourceBuffer, int offset, int length)
sourceBuffer
, offset
, and length
. No bytes are being
removed from the buffer. If the result is true, then the following invocations
of read()
are guaranteed to return exactly those bytes.sourceBuffer
- the buffer to compare againstoffset
- start offsetlength
- length to compareread()
will return the
bytes at offsets pOffset
+0, pOffset
+1, ...,
pOffset
+pLength
-1 of byte array pBuffer
.IllegalArgumentException
- Either of pOffset
, or pLength
is negative.NullPointerException
- The byte array pBuffer
is null.public void add(byte[] targetBuffer, int offset, int length)
add(byte)
for the bytes at offsets offset+0
, offset+1
, ...,
offset+length-1
of byte array targetBuffer
.targetBuffer
- the buffer to copyoffset
- start offsetlength
- length to copyIllegalStateException
- The buffer doesn't have sufficient space. Use
getSpace()
to prevent this exception.IllegalArgumentException
- Either of pOffset
, or pLength
is negative.NullPointerException
- The byte array pBuffer
is null.public boolean hasSpace()
hasSpace(1)
.hasSpace(int)
,
getSpace()
public boolean hasSpace(int count)
count
- the byte counthasSpace()
,
getSpace()
public boolean hasBytes()
public int getSpace()
public int getCurrentNumberOfBytes()
public void clear()
Copyright © 2025. All rights reserved.