public class TextLineRingBuffer extends java.lang.Object implements ByteCollector
This is especially useful for collecting text output.
If the buffer overflows you can only retrieve the latest getLimit() lines.
Modifier and Type | Field and Description |
---|---|
(package private) static int |
INITIAL_LIMIT
Initial limit: 64 Mi-lines.
|
Constructor and Description |
---|
TextLineRingBuffer(int limit,
java.nio.charset.Charset charset)
Create a ring buffer with the given size.
|
TextLineRingBuffer(int limit,
java.nio.charset.Charset charset,
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.
|
boolean |
isEmpty()
Is the text line ring buffer empty.
|
int |
size()
Get the number of valid lines cached in this buffer.
|
java.lang.String[] |
toLineArray()
Get the lines of this ring buffer as an array of strings.
|
Indexable<java.lang.String> |
toLineIndexable()
Get the lines of this ring buffer as an indexable of strings.
|
java.util.List<java.lang.String> |
toLineList()
Get the lines of this ring buffer as a list of strings.
|
java.lang.String |
toString()
Get the lines of this line buffer as a concatenated string.
|
Indexable<java.lang.String> |
viewLines()
Get a temporary view of the lines in this ring buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
append
static final int INITIAL_LIMIT
public TextLineRingBuffer(int limit, @NotNull java.nio.charset.Charset charset)
limit
- size limit of this text line buffercharset
- charset used to convert bytes into stringsTextLineRingBuffer(int limit, @NotNull java.nio.charset.Charset charset, int initialLimit)
limit
- size limit of this buffercharset
- charset for decoding text from bytesinitialLimit
- initial limitpublic int getLimit()
public int size()
cache limit
.public boolean isEmpty()
public void append(int value)
append
in interface ByteCollector
value
- 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 ByteCollector
bytes
- 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
public void clear()
the total number of bytes handled by this buffer
.clear
in interface ByteCollector
@NotNull public Indexable<java.lang.String> viewLines()
toLineIndexable()
,
toLineList()
, and toString()
is
that no data is copied.@NotNull public Indexable<java.lang.String> toLineIndexable()
@NotNull public java.util.List<java.lang.String> toLineList()
@NotNull public java.lang.String[] toLineArray()
@NotNull public java.lang.String toString()
toString
in class java.lang.Object
public long getNumberOfCollectedBytes()
getNumberOfCollectedBytes
in interface ByteCollector