org.dellroad.stuff.io
Class AsyncInputStream

java.lang.Object
  extended by org.dellroad.stuff.io.AsyncInputStream

public class AsyncInputStream
extends Object

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.

Instances of this class are thread-safe. The close() method may be safely invoked re-entrantly from the listener callback methods.


Nested Class Summary
static interface AsyncInputStream.Listener
          Callback interface required by AsyncInputStream.
 
Field Summary
protected  Logger log
           
 
Constructor Summary
AsyncInputStream(InputStream input, String name, AsyncInputStream.Listener listener)
          Constructor.
 
Method Summary
 void close()
          Close this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Logger log
Constructor Detail

AsyncInputStream

public AsyncInputStream(InputStream input,
                        String name,
                        AsyncInputStream.Listener listener)
Constructor.

If listener is null, this instance effectively reads and discards all of the input in a background thread.

Parameters:
input - underlying input stream
name - name for this instance; used to create the name of the background thread
listener - callback object for input events, or null for none
Throws:
IllegalArgumentException - if any parameter is null
Method Detail

close

public void close()
Close this instance.

Does nothing if already closed.