org.apache.tools.ant.taskdefs

Class PumpStreamHandler

public class PumpStreamHandler extends Object implements ExecuteStreamHandler

Copies standard output and error of subprocesses to standard output and error of the parent process.

Since: Ant 1.2

Nested Class Summary
protected static classPumpStreamHandler.ThreadWithPumper
Specialized subclass that allows access to the running StreamPumper.
Constructor Summary
PumpStreamHandler(OutputStream out, OutputStream err, InputStream input)
Construct a new PumpStreamHandler.
PumpStreamHandler(OutputStream out, OutputStream err)
Construct a new PumpStreamHandler.
PumpStreamHandler(OutputStream outAndErr)
Construct a new PumpStreamHandler.
PumpStreamHandler()
Construct a new PumpStreamHandler.
Method Summary
protected voidcreateProcessErrorPump(InputStream is, OutputStream os)
Create the pump to handle error output.
protected voidcreateProcessOutputPump(InputStream is, OutputStream os)
Create 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 voidfinish(Thread t)
Waits for a thread to finish while trying to make it finish quicker by stopping the pumper (if the thread is a ThreadWithPumper instance) or interrupting the thread.
protected OutputStreamgetErr()
Get the error stream.
protected OutputStreamgetOut()
Get the output stream.
voidsetProcessErrorStream(InputStream is)
Set the InputStream from which to read the standard error of the process.
voidsetProcessInputStream(OutputStream os)
Set the OutputStream by means of which input can be sent to the process.
voidsetProcessOutputStream(InputStream is)
Set the InputStream from which to read the standard output of the process.
voidstart()
Start the Threads.
voidstop()
Stop pumping the streams.

Constructor Detail

PumpStreamHandler

public PumpStreamHandler(OutputStream out, OutputStream err, InputStream input)
Construct a new PumpStreamHandler.

Parameters: out the output OutputStream. err the error OutputStream. input the input InputStream.

PumpStreamHandler

public PumpStreamHandler(OutputStream out, OutputStream err)
Construct a new PumpStreamHandler.

Parameters: out the output OutputStream. err the error OutputStream.

PumpStreamHandler

public PumpStreamHandler(OutputStream outAndErr)
Construct a new PumpStreamHandler.

Parameters: outAndErr the output/error OutputStream.

PumpStreamHandler

public PumpStreamHandler()
Construct a new PumpStreamHandler.

Method Detail

createProcessErrorPump

protected void createProcessErrorPump(InputStream is, OutputStream os)
Create the pump to handle error output.

Parameters: is the input stream to copy from. os the output stream to copy to.

createProcessOutputPump

protected void createProcessOutputPump(InputStream is, OutputStream os)
Create the pump to handle process output.

Parameters: is the InputStream. os the OutputStream.

createPump

protected Thread createPump(InputStream is, OutputStream os)
Creates 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 to.

Returns: a thread object that does the pumping.

createPump

protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted)
Creates 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 to. closeWhenExhausted if true close the inputstream.

Returns: a thread object that does the pumping, subclasses should return an instance of ThreadWithPumper.

finish

protected final void finish(Thread t)
Waits for a thread to finish while trying to make it finish quicker by stopping the pumper (if the thread is a ThreadWithPumper instance) or interrupting the thread.

Since: Ant 1.8.0

getErr

protected OutputStream getErr()
Get the error stream.

Returns: OutputStream.

getOut

protected OutputStream getOut()
Get the output stream.

Returns: OutputStream.

setProcessErrorStream

public void setProcessErrorStream(InputStream is)
Set the InputStream from which to read the standard error of the process.

Parameters: is the InputStream.

setProcessInputStream

public void setProcessInputStream(OutputStream os)
Set the OutputStream by means of which input can be sent to the process.

Parameters: os the OutputStream.

setProcessOutputStream

public void setProcessOutputStream(InputStream is)
Set the InputStream from which to read the standard output of the process.

Parameters: is the InputStream.

start

public void start()
Start the Threads.

stop

public void stop()
Stop pumping the streams.