public class CircularBuffer extends Object
A reusable circular buffer
| Constructor and Description |
|---|
CircularBuffer(int size)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getAvailableDataLength()
Returns the number of slots with valid data
|
int |
getBufferSize()
Returns the buffer capacity
|
boolean |
isEmpty()
Returns if the buffer is empty
|
boolean |
isFull()
Returns if the buffer is full
|
void |
readAll(OutputStream outputStream)
Reads all the available valid data into an
OutputStream |
void |
readChunk(OutputStream outputStream,
int chunkSize)
Reads a chunk of available data into an
OutputStream |
void |
reset()
Resets the buffer.
|
void |
write(byte data)
Writes a byte in the first available slot in the buffer.
|
public CircularBuffer(int size)
Constructor.
size - The size of the buffer. Must be greater than or equal to 1public void write(byte data)
Writes a byte in the first available slot in the buffer. If the buffer is full the oldest data written will be overwritten.
data - The byte to write.public void readAll(OutputStream outputStream) throws IOException
Reads all the available valid data into an OutputStream
outputStream - The OutputStream target of the read.IOException - If the read fails.public void readChunk(OutputStream outputStream, int chunkSize) throws IOException
Reads a chunk of available data into an OutputStream
outputStream - The OutputStream target of the read.chunkSize - The size of the chunk. Must be less than or equal getAvailableDataLength()IOException - If the read fails.public boolean isFull()
Returns if the buffer is full
public boolean isEmpty()
Returns if the buffer is empty
public int getAvailableDataLength()
Returns the number of slots with valid data
public int getBufferSize()
Returns the buffer capacity
public void reset()
Resets the buffer.
Copyright © 2017. All rights reserved.