@@ -25,8 +25,6 @@ import java.io.OutputStream;
* Copies standard output and error of subprocesses to standard output and
* Copies standard output and error of subprocesses to standard output and
* error of the parent process.
* error of the parent process.
*
*
* TODO: standard input of the subprocess is not implemented.
*
* @author thomas.haas@softwired-inc.com
* @author thomas.haas@softwired-inc.com
* @since Ant 1.2
* @since Ant 1.2
*/
*/
@@ -40,6 +38,12 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
private OutputStream err;
private OutputStream err;
private InputStream input;
private InputStream input;
/**
* Construct a new <CODE>PumpStreamHandler</CODE>.
* @param out the output <CODE>OutputStream</CODE>.
* @param err the error <CODE>OutputStream</CODE>.
* @param in the input <CODE>InputStream</CODE>.
*/
public PumpStreamHandler(OutputStream out, OutputStream err,
public PumpStreamHandler(OutputStream out, OutputStream err,
InputStream input) {
InputStream input) {
this.out = out;
this.out = out;
@@ -47,29 +51,55 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
this.input = input;
this.input = input;
}
}
/**
* Construct a new <CODE>PumpStreamHandler</CODE>.
* @param out the output <CODE>OutputStream</CODE>.
* @param err the error <CODE>OutputStream</CODE>.
*/
public PumpStreamHandler(OutputStream out, OutputStream err) {
public PumpStreamHandler(OutputStream out, OutputStream err) {
this(out, err, null);
this(out, err, null);
}
}
/**
* Construct a new <CODE>PumpStreamHandler</CODE>.
* @param outAndErr the output/error <CODE>OutputStream</CODE>.
*/
public PumpStreamHandler(OutputStream outAndErr) {
public PumpStreamHandler(OutputStream outAndErr) {
this(outAndErr, outAndErr);
this(outAndErr, outAndErr);
}
}
/**
* Construct a new <CODE>PumpStreamHandler</CODE>.
*/
public PumpStreamHandler() {
public PumpStreamHandler() {
this(System.out, System.err);
this(System.out, System.err);
}
}
/**
* Set the <CODE>InputStream</CODE> from which to read the
* standard output of the process.
* @param is the <CODE>InputStream</CODE>.
*/
public void setProcessOutputStream(InputStream is) {
public void setProcessOutputStream(InputStream is) {
createProcessOutputPump(is, out);
createProcessOutputPump(is, out);
}
}
/**
* Set the <CODE>InputStream</CODE> from which to read the
* standard error of the process.
* @param is the <CODE>InputStream</CODE>.
*/
public void setProcessErrorStream(InputStream is) {
public void setProcessErrorStream(InputStream is) {
if (err != null) {
if (err != null) {
createProcessErrorPump(is, err);
createProcessErrorPump(is, err);
}
}
}
}
/**
* Set the <CODE>OutputStream</CODE> by means of which
* input can be sent to the process.
* @param os the <CODE>OutputStream</CODE>.
*/
public void setProcessInputStream(OutputStream os) {
public void setProcessInputStream(OutputStream os) {
if (input != null) {
if (input != null) {
inputThread = createPump(input, os, true);
inputThread = createPump(input, os, true);
@@ -82,6 +112,9 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
}
}
}
}
/**
* Start the <CODE>Thread</CODE>s.
*/
public void start() {
public void start() {
outputThread.start();
outputThread.start();
errorThread.start();
errorThread.start();
@@ -90,6 +123,9 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
}
}
}
}
/**
* Stop pumping the streams.
*/
public void stop() {
public void stop() {
try {
try {
outputThread.join();
outputThread.join();
@@ -122,23 +158,40 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
}
}
}
}
/**
* Get the error stream.
* @return <CODE>OutputStream</CODE>.
*/
protected OutputStream getErr() {
protected OutputStream getErr() {
return err;
return err;
}
}
/**
* Get the output stream.
* @return <CODE>OutputStream</CODE>.
*/
protected OutputStream getOut() {
protected OutputStream getOut() {
return out;
return out;
}
}
/**
* Create the pump to handle process output.
* @param is the <CODE>InputStream</CODE>.
* @param os the <CODE>OutputStream</CODE>.
*/
protected void createProcessOutputPump(InputStream is, OutputStream os) {
protected void createProcessOutputPump(InputStream is, OutputStream os) {
outputThread = createPump(is, os);
outputThread = createPump(is, os);
}
}
/**
* Create the pump to handle error output.
* @param is the <CODE>InputStream</CODE>.
* @param os the <CODE>OutputStream</CODE>.
*/
protected void createProcessErrorPump(InputStream is, OutputStream os) {
protected void createProcessErrorPump(InputStream is, OutputStream os) {
errorThread = createPump(is, os);
errorThread = createPump(is, os);
}
}
/**
/**
* Creates a stream pumper to copy the given input stream to the
* Creates a stream pumper to copy the given input stream to the
* given output stream.
* given output stream.