public class EndOfLineBuffer extends Object
A reusable buffer that is watching for end of line sequences.
Every time the buffer is full or if an end of line is encountered the data (excluded the end of line sequence) will be flushed to an OutputStream.
After an end of line sequence has been found, the buffer is not writable anymore and recycle(byte[], OutputStream) must be call to reuse it.
| Constructor and Description |
|---|
EndOfLineBuffer(int size,
byte[] endOfLineSequence,
OutputStream flushOutputStream)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isEndOfLine()
Returns if an end of line has been encountered.
|
void |
recycle(byte[] endOfLineSequence,
OutputStream flushOutputStream)
Recycles the buffer
|
boolean |
write(byte data)
Writes a byte of data in the buffer.
|
public EndOfLineBuffer(int size,
byte[] endOfLineSequence,
OutputStream flushOutputStream)
Constructor
size - The size of the buffer. Must be greater than the bigger end of line sequenceendOfLineSequence - The end of line sequence. The write(byte) method will return true when the end of line sequence is encounteredflushOutputStream - The OutputStream where to flush the data when the buffer is full. If set to null the buffer can be used to skip bytes until an end of line marker.public void recycle(byte[] endOfLineSequence,
OutputStream flushOutputStream)
Recycles the buffer
endOfLineSequence - The new end of line sequence.flushOutputStream - The new OutputStream where to flush the data when the buffer is full.public boolean write(byte data)
Writes a byte of data in the buffer. If the buffer already encountered an end of line sequence, and exception will be thrown.
data - The byte of data.public boolean isEndOfLine()
Returns if an end of line has been encountered.
Copyright © 2017. All rights reserved.