Package org.apache.commons.exec
Class PumpStreamHandler
java.lang.Object
org.apache.commons.exec.PumpStreamHandler
- All Implemented Interfaces:
- ExecuteStreamHandler
Copies standard output and error of sub-processes 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.
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a newPumpStreamHandler.PumpStreamHandler(OutputStream allOutputStream) Constructs a newPumpStreamHandler.PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream) Constructs a newPumpStreamHandler.PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream, InputStream inputStream) Constructs a newPumpStreamHandler.
- 
Method SummaryModifier 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 OutputStreamgetErr()Gets the error stream.protected OutputStreamgetOut()Gets the output stream.voidSets theInputStreamfrom which to read the standard error of the process.voidSets theOutputStreamby means of which input can be sent to the process.voidSets theInputStreamfrom which to read the standard output of the process.voidsetStopTimeout(long timeout) Deprecated.voidsetStopTimeout(Duration timeout) Sets maximum time to wait until output streams are exhausted whenstop()was called.voidstart()Starts theThreads.voidstop()Stops pumping the streams.protected voidstopThread(Thread thread, long timeoutMillis) Stops a pumper thread.
- 
Constructor Details- 
PumpStreamHandlerpublic PumpStreamHandler()Constructs a newPumpStreamHandler.
- 
PumpStreamHandlerConstructs a newPumpStreamHandler.- Parameters:
- allOutputStream- the output/error- OutputStream. The- OutputStreamimplementation must be thread-safe because the output and error reader threads will concurrently write to it.
 
- 
PumpStreamHandlerConstructs a newPumpStreamHandler.If the same OutputStreaminstance is used for output and error, then it must be thread-safe because the output and error reader threads will concurrently write to it.- Parameters:
- outputStream- the output- OutputStream.
- errorOutputStream- the error- OutputStream.
 
- 
PumpStreamHandlerpublic PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream, InputStream inputStream) Constructs a newPumpStreamHandler.If the same OutputStreaminstance is used for output and error, then it must be thread-safe because the output and error reader threads will concurrently write to it.- Parameters:
- outputStream- the output- OutputStream.
- errorOutputStream- the error- OutputStream.
- inputStream- the input- InputStream.
 
 
- 
- 
Method Details- 
createProcessErrorPumpCreate the pump to handle error output.- Parameters:
- is- the- InputStream.
- os- the- OutputStream.
 
- 
createProcessOutputPumpCreate the pump to handle process output.- Parameters:
- is- the- InputStream.
- os- the- OutputStream.
 
- 
createPumpCreates a stream pumper to copy the given input stream to the given output stream. When the 'os' is an PipedOutputStream we are closing 'os' afterwards to avoid an IOException ("Write end dead").- Parameters:
- is- the input stream to copy from.
- os- the output stream to copy into.
- Returns:
- the stream pumper thread.
 
- 
createPumpCreates a stream pumper to copy the given input stream to the given output stream.- Parameters:
- is- the input stream to copy from.
- os- the output stream to copy into.
- closeWhenExhausted- close the output stream when the input stream is exhausted.
- Returns:
- the stream pumper thread.
 
- 
getErrGets the error stream.- Returns:
- OutputStream.
 
- 
getOutGets the output stream.- Returns:
- OutputStream.
 
- 
setProcessErrorStreamSets theInputStreamfrom which to read the standard error of the process.- Specified by:
- setProcessErrorStreamin interface- ExecuteStreamHandler
- Parameters:
- is- the- InputStream.
 
- 
setProcessInputStreamSets theOutputStreamby means of which input can be sent to the process.- Specified by:
- setProcessInputStreamin interface- ExecuteStreamHandler
- Parameters:
- os- the- OutputStream.
 
- 
setProcessOutputStreamSets theInputStreamfrom which to read the standard output of the process.- Specified by:
- setProcessOutputStreamin interface- ExecuteStreamHandler
- Parameters:
- is- the- InputStream.
 
- 
setStopTimeoutSets maximum time to wait until output streams are exhausted whenstop()was called.- Parameters:
- timeout- timeout or zero to wait forever (default).
- Since:
- 1.4.0
 
- 
setStopTimeoutDeprecated.Sets maximum time to wait until output streams are exhausted whenstop()was called.- Parameters:
- timeout- timeout in milliseconds or zero to wait forever (default).
 
- 
startStarts theThreads.- Specified by:
- startin interface- ExecuteStreamHandler
 
- 
stopStops pumping the streams. When a timeout is specified it is not guaranteed that the pumper threads are cleanly terminated.- Specified by:
- stopin interface- ExecuteStreamHandler
- Throws:
- IOException- thrown when an I/O exception occurs.
 
- 
stopThreadStops a pumper thread. The implementation actually waits longer than specified in 'timeout' to detect if the timeout was indeed exceeded. If the timeout was exceeded an IOException is created to be thrown to the caller.- Parameters:
- thread- the thread to be stopped.
- timeoutMillis- the time in ms to wait to join.
 
 
- 
setStopTimeout(Duration).