Package org.dellroad.stuff.io
Class AsyncInputStream
java.lang.Object
org.dellroad.stuff.io.AsyncInputStream
Performs asynchonous reads on an
InputStream
and notifies of input events.
Reads are performed in a dedicated background thread, from which the configured listener is notified.
The background thread runs until this instance is closed, EOF or an exception is detected
on the input, or a listener callback method throws an exception. A null listener may be supplied; in which case
this class will just sink the InputStream
.
Instances of this class are thread-safe. The close()
method may be safely invoked re-entrantly from the
listener callback methods.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback interface required byAsyncInputStream
. -
Field Summary
-
Constructor Summary
ConstructorDescriptionAsyncInputStream
(InputStream input, String name, AsyncInputStream.Listener listener) Constructor. -
Method Summary
-
Field Details
-
log
-
-
Constructor Details
-
AsyncInputStream
Constructor.If
listener
is null, this instance effectively reads and discards all of the input in a background thread.- Parameters:
input
- underlying input streamname
- name for this instance; used to create the name of the background threadlistener
- callback object for input events, or null for none- Throws:
IllegalArgumentException
- if any parameter is null
-
-
Method Details
-
close
public void close()Close this instance.Does nothing if already closed.
-