public class AsyncByteStreamReader 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. If there aren't, it schedules a future to do that.
The stream bytes are read into a ByteRingBuffer
.
Note: The caller is responsible for opening and closing the stream as needed.
EOFInputStream
,
WhenReady
,
AsyncAgent
,
ByteRingBuffer
Constructor and Description |
---|
AsyncByteStreamReader(EOFInputStream inputStream,
ByteRingBuffer byteRingBuffer,
AsyncOptions asyncOptions)
Constructs a new AsyncByteStreamReader instance to read from the given InputStream
into the given
ByteRingBuffer . |
Modifier and Type | Method and Description |
---|---|
protected void |
action()
"action" function that reads bytes from the stream and writes them to the ring buffer.
|
protected boolean |
done()
|
ByteRingBuffer |
getByteRingBuffer()
Returns the attached ring buffer where bytes will be written.
|
EOFInputStream |
getInputStream()
Returns the underlying InputStream.
|
boolean |
isEOF()
Checks whether this reader has reached EOF of the stream.
|
protected boolean |
ready()
"ready" predicate that returns true when bytes can be read from the stream and written to the ring buffer without blocking.
|
applyAsync, isIdle, setIdle, setIdleAndThrow, startApplyLoopAsync
public AsyncByteStreamReader(EOFInputStream inputStream, ByteRingBuffer byteRingBuffer, AsyncOptions asyncOptions)
ByteRingBuffer
.inputStream
- An EOFInputStream to read from.byteRingBuffer
- A ByteRingBuffer
to write to.asyncOptions
- AsyncOptions
that will control all async operations on this instance.public EOFInputStream getInputStream()
public ByteRingBuffer getByteRingBuffer()
public boolean isEOF()
protected boolean ready()
ready
in class AsyncAgent
AsyncAgent.action()
.protected boolean done()
AsyncAgent
WhenReady.startApplyLoopAsync(java.util.function.Predicate<S>, java.util.function.Predicate<S>, java.util.function.Function<S, R>, S)
.done
in class AsyncAgent
protected void action()
action
in class AsyncAgent