public class CircularByteBuffer
extends java.lang.Object
CircularBufferInputStream.| Constructor and Description |
|---|
CircularByteBuffer()
Creates a new instance with a reasonable default buffer size (
IOUtils.DEFAULT_BUFFER_SIZE). |
CircularByteBuffer(int size)
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()
IOUtils.DEFAULT_BUFFER_SIZE).public CircularByteBuffer(int size)
size - the size of buffer to createpublic void add(byte value)
read().value - The byte, which is being added to the buffer.java.lang.IllegalStateException - The buffer is full. Use hasSpace(),
or getSpace(), to prevent this exception.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 copyjava.lang.IllegalStateException - The buffer doesn't have sufficient space. Use
getSpace() to prevent this exception.java.lang.IllegalArgumentException - Either of offset, or length is negative.java.lang.NullPointerException - The byte array pBuffer is null.public void clear()
public int getCurrentNumberOfBytes()
public int getSpace()
public boolean hasBytes()
public boolean hasSpace()
hasSpace(1).hasSpace(int),
getSpace()public boolean hasSpace(int count)
count - the byte counthasSpace(),
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+length-1 of byte array pBuffer.java.lang.IllegalArgumentException - Either of pOffset, or length is negative.java.lang.NullPointerException - The byte array pBuffer is null.public byte read()
java.lang.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.java.lang.NullPointerException - The byte array pBuffer is null.java.lang.IllegalArgumentException - Either of pOffset, or length is negative,
or the length of the byte array targetBuffer is too small.java.lang.IllegalStateException - The buffer doesn't hold the given number
of bytes. Use getCurrentNumberOfBytes() to prevent this
exception.Copyright © 2010 - 2023 Adobe. All Rights Reserved