public class AsyncReaderRecorder extends Object implements Runnable
Reader and then executed on a
Thread or an Executor. The
recorder will then autonomously record the input of the given Reader into an
internal buffer. Another thread may then consume the buffer in parts, or as a
whole.| Constructor and Description |
|---|
AsyncReaderRecorder(Reader reader)
Creates a new recorder, recording the given Reader.
|
| Modifier and Type | Method and Description |
|---|---|
String |
consumeAll()
Consumes and returns the whole buffer at once.
|
String |
consumeAllAfterCurrentInput()
Consumes and returns the whole buffer after the current reading is
complete.
|
Optional<String> |
consumeAmount(int amount)
Consumes and returns a fixed amount of characters from the buffer.
|
Optional<String> |
consumeToNextDelimiter(String delimiter)
Consumes and returns the buffer up to the point where the delimiter first
occurs.
|
String |
getBuffer() |
int |
getBufferedAmount() |
IOException |
getException() |
boolean |
hasExceptionOccurred() |
boolean |
hasStreamEnded() |
void |
run()
Records the reader into the buffer.
|
public AsyncReaderRecorder(Reader reader)
reader - the reader to be recorded.public void run()
public boolean hasStreamEnded()
public boolean hasExceptionOccurred()
public IOException getException()
public String getBuffer() throws IOException
IOExceptionpublic int getBufferedAmount()
throws IOException
IOExceptionpublic String consumeAll() throws IOException
IOException - if an IOException has occurred since the last
consumption.public String consumeAllAfterCurrentInput() throws IOException, InterruptedException
consumeAll() in
cases where the input is some kind of message based communication,
because the whole current message will be included into the buffer before
consuming it.
Note: Only one consumption method should be called at once.IOException - if an IOException has occurred since the last
consumption or occurs while waiting.InterruptedException - if the current thread was interrupted while
waiting for the current input to end.public Optional<String> consumeToNextDelimiter(String delimiter) throws IOException, InterruptedException
delimiter - the delimiter up to which to consume.IOException - if an IOException has occurred since the last
consumption or occurs while waiting.InterruptedException - if the current thread was interrupted while
waiting for the delimiter to be recorded.public Optional<String> consumeAmount(int amount) throws IOException, InterruptedException
amount - the amount of characters to consume.IOException - if an IOException has occurred since the last
consumption or occurs while waiting.InterruptedException - if the current thread was interrupted while
waiting for more characters to be recorded.Copyright © 2019. All rights reserved.