public class ByteRingBuffer extends java.lang.Object implements ByteCollector
If the buffer overflows you can only retrieve the latest getLimit() bytes.
| Modifier and Type | Field and Description |
|---|---|
(package private) static int |
INITIAL_LIMIT
Initial limit: 1 MiB.
|
| Constructor and Description |
|---|
ByteRingBuffer(int limit)
Create a ring buffer with the given size.
|
ByteRingBuffer(int limit,
int initialLimit)
Create a ring buffer with the given size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(byte[] bytes,
int offset,
int length)
Append the given byte array part to this buffer.
|
void |
append(int value)
Append one byte
|
void |
clear()
Clear all data.
|
int |
getLimit()
Get the limit of this ring buffer.
|
long |
getNumberOfCollectedBytes()
Get the total number of bytes appended to this buffer.
|
int |
size()
Get the number of valid bytes cached in this buffer.
|
byte[] |
toByteArray()
Create a byte array with the bytes in this buffer.
|
ByteIndexable |
toByteIndexable()
Get a stable byte indexable from this buffer.
|
ByteIndexable |
view()
Get a byte indexable view of this ring buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitappendstatic final int INITIAL_LIMIT
public ByteRingBuffer(int limit)
limit - size limit of this bufferByteRingBuffer(int limit,
int initialLimit)
limit - size limit of this bufferinitialLimit - initial limitpublic int getLimit()
public int size()
public void append(int value)
append in interface ByteCollectorvalue - byte value. Accepts integer for convenience, but will cast the given value to byte.public void append(@NotNull byte[] bytes, int offset, int length)
append in interface ByteCollectorbytes - basic byte arrayoffset - start offset of the bytes to appendlength - number of bytes to appendjava.lang.IndexOutOfBoundsException - if the parameters define a part which is at least partially outside the bytes@NotNull public byte[] toByteArray()
@NotNull public ByteIndexable view()
This is more efficient than copying all bytes in toByteArray(), especially if only a few bytes of a larger content are of interest. But the price is high: any change to this buffer can break the returned view. So this is best used on a finished buffer.
toByteIndexable(),
toByteArray()@NotNull public ByteIndexable toByteIndexable()
Compared to view() the returned indexable
is decoupled from this buffer, with the price
of a copy of the bytes. Compared to the result of
ByteIndexable.viewArray(ringBuffer.toByteArray())
this method provides an already frozen
byte indexable.toByteArray(),
view()public void clear()
the total number of bytes handled by this buffer.clear in interface ByteCollectorpublic long getNumberOfCollectedBytes()
getNumberOfCollectedBytes in interface ByteCollector