Class AsyncInputStream

java.lang.Object
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. 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.

  • Field Details

    • log

      protected final Logger log
  • Constructor Details

    • 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 Details

    • close

      public void close()
      Close this instance.

      Does nothing if already closed.