public class AsyncTextStreamReader extends AsyncAgent
EOFInputStream
.
The reader doesn't block as long as the stream correctly reports its available bytes.
The reader reads available bytes from the stream if there are any,
decodes the chars, splits lines, and places complete lines in a StringRingBuffer
that is accessible through getStringRingBuffer()
.
Use AsyncAgent.applyAsync()
or AsyncAgent.startApplyLoopAsync()
to
read lines through getStringRingBuffer()
.
This class is a convenience wrapper around the individual elements of the input stack.
Note: The caller is responsible for opening and closing the stream as needed.
EOFInputStream
,
WhenReady
,
AsyncAgent
,
ByteRingBuffer
,
CharRingBuffer
,
AsyncLineSplitter
Constructor and Description |
---|
AsyncTextStreamReader(EOFInputStream inputStream,
ByteRingBuffer byteRingBuffer,
CharRingBuffer charRingBuffer,
StringRingBuffer stringRingBuffer,
java.util.function.Consumer<StringRingBuffer> onAvailableToRead,
TextStreamAsyncOptions textStreamAsyncOptions)
Constructs a new AsyncTextStreamReader instance to read from the given InputStream.
|
AsyncTextStreamReader(EOFInputStream inputStream,
java.util.function.Consumer<StringRingBuffer> onAvailableToRead,
TextStreamAsyncOptions textStreamAsyncOptions)
Constructs a new AsyncTextStreamReader instance to read from the given InputStream.
|
AsyncTextStreamReader(EOFInputStream inputStream,
TextStreamAsyncOptions textStreamAsyncOptions)
Constructs a new AsyncTextStreamReader instance to read from the given InputStream.
|
Modifier and Type | Method and Description |
---|---|
protected void |
action()
"action" function that gets executed as part of the apply loop.
|
protected boolean |
done()
"done" predicate that returns true when this async agent wants to quit the current async loop.
|
AsyncRingBufferWatcher<StringRingBuffer> |
getAsyncStringRingBufferWatcher()
Returns the underlying
AsyncRingBufferWatcher that watches the StringRingBuffer . |
StringRingBuffer |
getStringRingBuffer()
Returns the underlying
StringRingBuffer where text lines are placed. |
boolean |
isEOF()
Checks whether this text stream reader has reached EOF.
|
protected boolean |
ready()
"ready" predicate that returns true when lines can be read from the string ring buffer.
|
applyAsync, isIdle, setIdle, setIdleAndThrow, startApplyLoopAsync
public AsyncTextStreamReader(EOFInputStream inputStream, TextStreamAsyncOptions textStreamAsyncOptions)
inputStream
- An EOFInputStream to read from.textStreamAsyncOptions
- TextStreamAsyncOptions
that will control all async operations on this instance.public AsyncTextStreamReader(EOFInputStream inputStream, java.util.function.Consumer<StringRingBuffer> onAvailableToRead, TextStreamAsyncOptions textStreamAsyncOptions)
inputStream
- An EOFInputStream to read from.onAvailableToRead
- A callback to invoke when there are text lines available to read from the string ring buffer.textStreamAsyncOptions
- TextStreamAsyncOptions
that will control all async operations on this instance.public AsyncTextStreamReader(EOFInputStream inputStream, ByteRingBuffer byteRingBuffer, CharRingBuffer charRingBuffer, StringRingBuffer stringRingBuffer, java.util.function.Consumer<StringRingBuffer> onAvailableToRead, TextStreamAsyncOptions textStreamAsyncOptions)
inputStream
- An EOFInputStream to read from.byteRingBuffer
- A ByteRingBuffer
to write bytes to. May be null
.
In that case, an implicit ByteRingBuffer
is created.charRingBuffer
- A CharRingBuffer
to decode chars into. May be null
.
In that case, an implicit CharRingBuffer
is created.stringRingBuffer
- A StringRingBuffer
to place lines into. May be null
.
In that case, an implicit StringRingBuffer
is created.onAvailableToRead
- A callback to invoke when there are text lines available to read from the string ring buffer.textStreamAsyncOptions
- TextStreamAsyncOptions
that will control all async operations on this instance.public StringRingBuffer getStringRingBuffer()
StringRingBuffer
where text lines are placed.StringRingBuffer
.public AsyncRingBufferWatcher<StringRingBuffer> getAsyncStringRingBufferWatcher()
AsyncRingBufferWatcher
that watches the StringRingBuffer
.AsyncRingBufferWatcher
, or null if no AsyncRingBufferWatcher
was configured.public boolean isEOF()
protected boolean ready()
ready
in class AsyncAgent
AsyncAgent.action()
.protected boolean done()
done
in class AsyncAgent
protected void action()
action
in class AsyncAgent