public class Pipe extends AbstractPipe
implements a threadable pipe. The idea of this class is to collect information from an input stream in an asynchronous fashion, or send output to a stream asynchronously.
After setting up the Pipe
with an input and an output
stream, it is usually run with something along the lines of
new Thread(pipe).start()As long as input is available from the input stream, the thread will copy it to the output stream.
Typical use of this class would be to collect standard input and standard error of a subprocess.
Constructor and Description |
---|
Pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean closeOnExit,
int bsize)
creates a
Pipe which connects an
InputStream with an OutputStream . |
Pipe(int bsize)
constructs a
Pipe with no input or output yet
specified. |
Modifier and Type | Method and Description |
---|---|
java.io.InputStream |
getIn()
returns the current input stream the pipe is reading.
|
java.io.OutputStream |
getOut()
returns the current output stream the pipe is writing to.
|
getException, run, setIn, setOut
public Pipe(int bsize)
public Pipe(java.io.InputStream in, java.io.OutputStream out, boolean closeOnExit, int bsize)
creates a Pipe
which connects an
InputStream
with an OutputStream
. It will
start copying data, as soon as the run
-method of this
object is called, typically from a new thread. If the input
stream signals EOF, all pending output is flushed. If
closeOnExit
is set, both streams are closed. Then
the run()
method terminates.
In cases of an IOException
, run()
records the exception to be retrieved by AbstractPipe.getException()
,
then closes the streams subject to closeOnExit
and
then terminates.
To have individual control over closing only one of the
streams on exit, use setIn()
and setOut()
.
bsize
- must be greater than 0