public class PumpStreamHandler extends java.lang.Object implements ExecuteStreamHandler
Modifier and Type | Field and Description |
---|---|
private java.io.IOException |
caught
the last exception being caught
|
private java.io.OutputStream |
err |
private java.lang.Thread |
errorThread |
private java.io.InputStream |
input |
private InputStreamPumper |
inputStreamPumper |
private java.lang.Thread |
inputThread |
private java.io.OutputStream |
out |
private java.lang.Thread |
outputThread |
private static long |
STOP_TIMEOUT_ADDITION |
private long |
stopTimeout
the timeout in ms the implementation waits when stopping the pumper threads
|
Constructor and Description |
---|
PumpStreamHandler()
Construct a new
PumpStreamHandler . |
PumpStreamHandler(java.io.OutputStream outAndErr)
Construct a new
PumpStreamHandler . |
PumpStreamHandler(java.io.OutputStream out,
java.io.OutputStream err)
Construct a new
PumpStreamHandler . |
PumpStreamHandler(java.io.OutputStream out,
java.io.OutputStream err,
java.io.InputStream input)
Construct a new
PumpStreamHandler . |
Modifier and Type | Method and Description |
---|---|
protected void |
createProcessErrorPump(java.io.InputStream is,
java.io.OutputStream os)
Create the pump to handle error output.
|
protected void |
createProcessOutputPump(java.io.InputStream is,
java.io.OutputStream os)
Create the pump to handle process output.
|
protected java.lang.Thread |
createPump(java.io.InputStream is,
java.io.OutputStream os)
Creates a stream pumper to copy the given input stream to the given
output stream.
|
protected java.lang.Thread |
createPump(java.io.InputStream is,
java.io.OutputStream os,
boolean closeWhenExhausted)
Creates a stream pumper to copy the given input stream to the given
output stream.
|
private java.lang.Thread |
createSystemInPump(java.io.InputStream is,
java.io.OutputStream os)
Creates a stream pumper to copy the given input stream to the given
output stream.
|
protected java.io.OutputStream |
getErr()
Get the error stream.
|
protected java.io.OutputStream |
getOut()
Get the output stream.
|
void |
setProcessErrorStream(java.io.InputStream is)
Set the
InputStream from which to read the standard error
of the process. |
void |
setProcessInputStream(java.io.OutputStream os)
Set the
OutputStream by means of which input can be sent
to the process. |
void |
setProcessOutputStream(java.io.InputStream is)
Set the
InputStream from which to read the standard output
of the process. |
void |
setStopTimeout(long timeout)
Set maximum time to wait until output streams are exchausted
when
stop() was called. |
void |
start()
Start the
Thread s. |
void |
stop()
Stop pumping the streams.
|
protected void |
stopThread(java.lang.Thread thread,
long timeout)
Stopping a pumper thread.
|
private static final long STOP_TIMEOUT_ADDITION
private java.lang.Thread outputThread
private java.lang.Thread errorThread
private java.lang.Thread inputThread
private final java.io.OutputStream out
private final java.io.OutputStream err
private final java.io.InputStream input
private InputStreamPumper inputStreamPumper
private long stopTimeout
private java.io.IOException caught
public PumpStreamHandler()
PumpStreamHandler
.public PumpStreamHandler(java.io.OutputStream outAndErr)
PumpStreamHandler
.outAndErr
- the output/error OutputStream
.public PumpStreamHandler(java.io.OutputStream out, java.io.OutputStream err)
PumpStreamHandler
.out
- the output OutputStream
.err
- the error OutputStream
.public PumpStreamHandler(java.io.OutputStream out, java.io.OutputStream err, java.io.InputStream input)
PumpStreamHandler
.out
- the output OutputStream
.err
- the error OutputStream
.input
- the input InputStream
.public void setStopTimeout(long timeout)
stop()
was called.timeout
- timeout in milliseconds or zero to wait forever (default)public void setProcessOutputStream(java.io.InputStream is)
InputStream
from which to read the standard output
of the process.setProcessOutputStream
in interface ExecuteStreamHandler
is
- the InputStream
.public void setProcessErrorStream(java.io.InputStream is)
InputStream
from which to read the standard error
of the process.setProcessErrorStream
in interface ExecuteStreamHandler
is
- the InputStream
.public void setProcessInputStream(java.io.OutputStream os)
OutputStream
by means of which input can be sent
to the process.setProcessInputStream
in interface ExecuteStreamHandler
os
- the OutputStream
.public void start()
Thread
s.start
in interface ExecuteStreamHandler
public void stop() throws java.io.IOException
stop
in interface ExecuteStreamHandler
java.io.IOException
- thrown when an I/O exception occurs.protected java.io.OutputStream getErr()
OutputStream
.protected java.io.OutputStream getOut()
OutputStream
.protected void createProcessOutputPump(java.io.InputStream is, java.io.OutputStream os)
is
- the InputStream
.os
- the OutputStream
.protected void createProcessErrorPump(java.io.InputStream is, java.io.OutputStream os)
is
- the InputStream
.os
- the OutputStream
.protected java.lang.Thread createPump(java.io.InputStream is, java.io.OutputStream os)
is
- the input stream to copy fromos
- the output stream to copy intoprotected java.lang.Thread createPump(java.io.InputStream is, java.io.OutputStream os, boolean closeWhenExhausted)
is
- the input stream to copy fromos
- the output stream to copy intocloseWhenExhausted
- close the output stream when the input stream is exhaustedprotected void stopThread(java.lang.Thread thread, long timeout)
thread
- the thread to be stoppedtimeout
- the time in ms to wait to joinprivate java.lang.Thread createSystemInPump(java.io.InputStream is, java.io.OutputStream os)
is
- the System.in input stream to copy fromos
- the output stream to copy into