org.apache.tools.ant.taskdefs

Class StreamPumper

public class StreamPumper extends Object implements Runnable

Copies all data from an input stream to an output stream.

Since: Ant 1.2

Constructor Summary
StreamPumper(InputStream is, OutputStream os, boolean closeWhenExhausted)
Create a new StreamPumper.
StreamPumper(InputStream is, OutputStream os, boolean closeWhenExhausted, boolean useAvailable)
Create a new StreamPumper.
StreamPumper(InputStream is, OutputStream os)
Create a new StreamPumper.
Method Summary
intgetBufferSize()
Get the size in bytes of the read buffer.
ExceptiongetException()
Get the exception encountered, if any.
booleanisFinished()
Tells whether the end of the stream has been reached.
voidrun()
Copies data from the input stream to the output stream.
voidsetBufferSize(int bufferSize)
Set the size in bytes of the read buffer.
voidwaitFor()
This method blocks until the StreamPumper finishes.

Constructor Detail

StreamPumper

public StreamPumper(InputStream is, OutputStream os, boolean closeWhenExhausted)
Create a new StreamPumper.

Parameters: is input stream to read data from os output stream to write data to. closeWhenExhausted if true, the output stream will be closed when the input is exhausted.

StreamPumper

public StreamPumper(InputStream is, OutputStream os, boolean closeWhenExhausted, boolean useAvailable)
Create a new StreamPumper.

Note: If you set useAvailable to true, you must explicitly invoke stop or interrupt the corresponding Thread when you are done or the run method will never finish on some JVMs (namely those where available returns 0 on a closed stream). Setting it to true may also impact performance negatively. This flag should only be set to true if you intend to stop the pumper before the input stream gets closed.

Parameters: is input stream to read data from os output stream to write data to. closeWhenExhausted if true, the output stream will be closed when the input is exhausted. useAvailable whether the pumper should use java.io.InputStream#available available to determine whether input is ready, thus trying to emulate non-blocking behavior.

Since: Ant 1.8.0

StreamPumper

public StreamPumper(InputStream is, OutputStream os)
Create a new StreamPumper.

Parameters: is input stream to read data from os output stream to write data to.

Method Detail

getBufferSize

public int getBufferSize()
Get the size in bytes of the read buffer.

Returns: the int size of the read buffer.

getException

public Exception getException()
Get the exception encountered, if any.

Returns: the Exception encountered.

isFinished

public boolean isFinished()
Tells whether the end of the stream has been reached.

Returns: true is the stream has been exhausted.

run

public void run()
Copies data from the input stream to the output stream. Terminates as soon as the input stream is closed or an error occurs.

setBufferSize

public void setBufferSize(int bufferSize)
Set the size in bytes of the read buffer.

Parameters: bufferSize the buffer size to use.

Throws: IllegalStateException if the StreamPumper is already running.

waitFor

public void waitFor()
This method blocks until the StreamPumper finishes.

Throws: InterruptedException if interrupted.

See Also: isFinished