public class CircularByteBuffer extends Object
CircularBufferInputStream
.Constructor and Description |
---|
CircularByteBuffer()
Creates a new instance with a reasonable default buffer size (
IOUtils.DEFAULT_BUFFER_SIZE ). |
CircularByteBuffer(int pSize)
Creates a new instance with the given buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
add(byte value)
Adds a new byte to the buffer, which will eventually be returned by following
invocations of
read() . |
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()
Returns the next byte from the buffer, removing it at the same time, so
that following invocations won't return it again.
|
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(int pSize)
pSize
- the size of buffer to createpublic CircularByteBuffer()
IOUtils.DEFAULT_BUFFER_SIZE
).public byte read()
IllegalStateException
- The buffer is empty. Use hasBytes()
,
or getCurrentNumberOfBytes()
, to prevent this exception.public void read(byte[] targetBuffer, int targetOffset, int length)
targetBuffer
- The byte array, where to add bytes.targetOffset
- The offset, where to store bytes in the byte array.length
- The number of bytes to return.NullPointerException
- The byte array pBuffer
is null.IllegalArgumentException
- Either of pOffset
, or pLength
is negative,
or the length of the byte array pBuffer
is too small.IllegalStateException
- The buffer doesn't hold the given number
of bytes. Use getCurrentNumberOfBytes()
to prevent this
exception.public void add(byte value)
read()
.value
- The byte, which is being added to the buffer.IllegalStateException
- The buffer is full. Use hasSpace()
,
or getSpace()
, to prevent this exception.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()
Jas4pp 1.5 © Java Analysis Studio for Particle Physics