public class ByteArrayRingBuffer extends Object
Constructor and Description |
---|
ByteArrayRingBuffer(int maxBytes)
Creates a ring buffer that holds at most |maxBytes| of data.
|
Modifier and Type | Method and Description |
---|---|
boolean |
appendBuffer(byte[] newData)
Adds |newData| to the ring buffer.
|
byte[] |
getBuffer(int i)
Returns the |i|-th element of the ring.
|
int |
getNumBuffers()
Returns the number of elements present in the ring.
|
void |
resize(int maxBytes)
Resize the buffer, removing existing data if necessary.
|
public ByteArrayRingBuffer(int maxBytes)
maxBytes
- upper bound on the amount of data to holdpublic boolean appendBuffer(byte[] newData)
Note: will fail if |newData| itself exceeds the size limit for this buffer. Will first remove all existing entries in this case. (This guarantees that the ring buffer always represents a contiguous sequence of data.)
newData
- data to be added to the ringpublic byte[] getBuffer(int i)
i
- public int getNumBuffers()
public void resize(int maxBytes)
maxBytes
- upper bound on the amount of data to hold