org.dellroad.stuff.io
Class NullModemOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.dellroad.stuff.io.NullModemOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class NullModemOutputStream
extends FilterOutputStream

Presents an OutputStream interface given a NullModemOutputStream.ReadCallback that can read from an InputStream. A separate thread is created to perform the actual reading.

If data is written beyond what the reader is willing to consume, an IOException is thrown.

Since:
1.0.82

Nested Class Summary
static interface NullModemOutputStream.ReadCallback
          Callback interface used by NullModemOutputStream.
 
Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
NullModemOutputStream(NullModemOutputStream.ReadCallback reader, String name)
          Constructor.
 
Method Summary
protected  void finalize()
          Ensure output stream is closed when this instance is no longer referenced.
protected  PipedOutputStream getPipedOutputStream()
          Get the wrapped stream cast as a PipedOutputStream.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullModemOutputStream

public NullModemOutputStream(NullModemOutputStream.ReadCallback reader,
                             String name)
Constructor.

Parameters:
reader - InputStream reader callback
name - name for this instance; used to create the name of the background thread
Method Detail

getPipedOutputStream

protected PipedOutputStream getPipedOutputStream()
Get the wrapped stream cast as a PipedOutputStream.


finalize

protected void finalize()
                 throws Throwable
Ensure output stream is closed when this instance is no longer referenced.

This ensures the reader thread wakes up (and exits, avoiding a memory leak) when an instance of this class is created but never read from.

Overrides:
finalize in class Object
Throws:
Throwable