Class PumpStreamHandler
java.lang.Object
org.zeroturnaround.exec.stream.PumpStreamHandler
- All Implemented Interfaces:
ExecuteStreamHandler
Copies standard output and error of subprocesses to standard output and error
of the parent process. If output or error stream are set to null, any feedback
from that stream will be lost.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OutputStreamprotected Threadprotected final InputStreamprotected InputStreamPumperprotected Threadprivate static final org.slf4j.Loggerprotected final OutputStreamprotected Thread -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a newPumpStreamHandler.PumpStreamHandler(OutputStream outAndErr) Construct a newPumpStreamHandler.PumpStreamHandler(OutputStream out, OutputStream err) Construct a newPumpStreamHandler.PumpStreamHandler(OutputStream out, OutputStream err, InputStream input) Construct a newPumpStreamHandler. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreate the pump to handle error output.protected voidCreate the pump to handle process output.protected ThreadcreatePump(InputStream is, OutputStream os) Creates a stream pumper to copy the given input stream to the given output stream.protected ThreadcreatePump(InputStream is, OutputStream os, boolean closeWhenExhausted) Creates a stream pumper to copy the given input stream to the given output stream.protected ThreadcreatePump(InputStream is, OutputStream os, boolean closeWhenExhausted, boolean flushImmediately) Creates a stream pumper to copy the given input stream to the given output stream.protected ThreadCreates a stream pumper to copy the given input stream to the given output stream.voidflush()getErr()Get the error stream.getInput()Get the input stream.getOut()Get the output stream.protected ThreadOverride this to customize how the background task is created.voidSet theInputStreamfrom which to read the standard error of the process.voidSet theOutputStreamby means of which input can be sent to the process.voidSet theInputStreamfrom which to read the standard output of the process.voidstart()Start theThreads.voidstop()Stop pumping the streams.protected RunnableOverride this to customize how the background task is created.
-
Field Details
-
log
private static final org.slf4j.Logger log -
outputThread
-
errorThread
-
inputThread
-
out
-
err
-
input
-
inputStreamPumper
-
-
Constructor Details
-
PumpStreamHandler
public PumpStreamHandler()Construct a newPumpStreamHandler. -
PumpStreamHandler
Construct a newPumpStreamHandler.- Parameters:
outAndErr- the output/errorOutputStream.
-
PumpStreamHandler
Construct a newPumpStreamHandler.- Parameters:
out- the outputOutputStream.err- the errorOutputStream.
-
PumpStreamHandler
Construct a newPumpStreamHandler.- Parameters:
out- the outputOutputStream.err- the errorOutputStream.input- the inputInputStream.
-
-
Method Details
-
setProcessOutputStream
Set theInputStreamfrom which to read the standard output of the process.- Specified by:
setProcessOutputStreamin interfaceExecuteStreamHandler- Parameters:
is- theInputStream.
-
setProcessErrorStream
Set theInputStreamfrom which to read the standard error of the process.- Specified by:
setProcessErrorStreamin interfaceExecuteStreamHandler- Parameters:
is- theInputStream.
-
setProcessInputStream
Set theOutputStreamby means of which input can be sent to the process.- Specified by:
setProcessInputStreamin interfaceExecuteStreamHandler- Parameters:
os- theOutputStream.
-
start
-
stop
-
flush
public void flush() -
getOut
-
getErr
-
getInput
-
createProcessOutputPump
Create the pump to handle process output.- Parameters:
is- theInputStream.os- theOutputStream.
-
createProcessErrorPump
Create the pump to handle error output.- Parameters:
is- theInputStream.os- theOutputStream.
-
createPump
Creates a stream pumper to copy the given input stream to the given output stream.- Parameters:
is- the input stream to copy fromos- the output stream to copy into- Returns:
- the stream pumper thread
-
createPump
Creates a stream pumper to copy the given input stream to the given output stream.- Parameters:
is- the input stream to copy fromos- the output stream to copy intocloseWhenExhausted- close the output stream when the input stream is exhausted- Returns:
- the stream pumper thread
-
createPump
protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted, boolean flushImmediately) Creates a stream pumper to copy the given input stream to the given output stream.- Parameters:
is- the input stream to copy fromos- the output stream to copy intocloseWhenExhausted- close the output stream when the input stream is exhaustedflushImmediately- flush the output stream whenever data was written to it- Returns:
- the stream pumper thread
-
createSystemInPump
Creates a stream pumper to copy the given input stream to the given output stream.- Parameters:
is- the System.in input stream to copy fromos- the output stream to copy into- Returns:
- the stream pumper thread
-
newThread
-
wrapTask
-