util
Class Streams.PipeHandler

java.lang.Object
  extended by util.Streams.PipeHandler
Enclosing class:
Streams

public static class Streams.PipeHandler
extends Object

Controller for handling all three streams for a child process asynchronously. Each of stdin, stdout, and stderr can be connected to any suitable stream; the child process's corresponding streams will be connected automatically in a multithreaded, asynchronous manner.


Field Summary
 BufferedInputStream childErr
          The child's standard error stream, which, to the parent, is an input stream.
 BufferedOutputStream childIn
          The child's standard input stream, which, to the parent, is an output stream.
 BufferedInputStream childOut
          The child's standard output stream, which, to the parent, is an input stream.
 BufferedOutputStream parentErr
          An output stream supplied by the parent, to be connected to the child's standard error.
 BufferedInputStream parentIn
          An input stream supplied by the parent, to be connected to the child's standard input.
 BufferedOutputStream parentOut
          An output stream supplied by the parent, to be connected to the child's standard output.
 
Constructor Summary
Streams.PipeHandler(InputStream parentIn, OutputStream childIn, OutputStream parentOut, InputStream childOut, OutputStream parentErr, InputStream childErr)
          Construct a pipe handler.
 
Method Summary
 void finish()
          Stop forwarding data, flushing all output.
 void handle()
          Run the pipe handler, forwarding data along the given connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

childOut

public final BufferedInputStream childOut
The child's standard output stream, which, to the parent, is an input stream.


childErr

public final BufferedInputStream childErr
The child's standard error stream, which, to the parent, is an input stream.


parentIn

public final BufferedInputStream parentIn
An input stream supplied by the parent, to be connected to the child's standard input.


childIn

public final BufferedOutputStream childIn
The child's standard input stream, which, to the parent, is an output stream.


parentOut

public final BufferedOutputStream parentOut
An output stream supplied by the parent, to be connected to the child's standard output.


parentErr

public final BufferedOutputStream parentErr
An output stream supplied by the parent, to be connected to the child's standard error.

Constructor Detail

Streams.PipeHandler

public Streams.PipeHandler(InputStream parentIn,
                           OutputStream childIn,
                           OutputStream parentOut,
                           InputStream childOut,
                           OutputStream parentErr,
                           InputStream childErr)
Construct a pipe handler.

Parameters:
parentIn - The stream to use for input.
childIn - The child's standard input stream.
parentOut - The stream to use for output.
childOut - The child's standard output stream.
parentErr - The stream to use for stderr.
childErr - The child's standard error stream.
Method Detail

handle

public void handle()
            throws IOException
Run the pipe handler, forwarding data along the given connections.

Throws:
IOException - If anything goes wrong with any of the streams.

finish

public void finish()
            throws IOException
Stop forwarding data, flushing all output.

Throws:
IOException - If anything goes wrong.