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