| java.lang.Object org.cougaar.tools.server.DualStreamBuffer
DualStreamBuffer | final public class DualStreamBuffer implements Serializable,Cloneable(Code) | | This utility-class is a buffer for capturing system-out and
system-error output to a byte[], plus reading the captured
output back with the interleaved write-ordering preserved.
Example usage:
// create streams
DualStreamBuffer dsb = new DualStreamBuffer();
PrintStream pout = new PrintStream(dsb.getOutputStream(true));
PrintStream perr = new PrintStream(dsb.getOutputStream(false));
// use streams as usual
pout.print("example std-out");
perr.print("some error");
pout.print("more std-out");
// replay to standard-out and standard-err
dsb.writeTo(System.out, System.err);
The internal representation has been optimized to make
both appending and the writeTo(*) methods efficient
(memory + time).
NOTE: this class is not internally thread-safe! If
multiple threads need access to the same DualStreamBuffer
instance then they must externally synchronized their
actions. This class does internally support multiple
simultaneous readers if there are zero simultaneous writers.
|
Method Summary | |
public Object | clone() | public InputStream | getInputStream() Get an InputStream for both the
standard-out and standard-error (interleaved in
correct ordering). | public InputStream | getInputStream(boolean isOut) Get an InputStream for just standard-out
or standard-error. | public OutputStream | getOutputStream(boolean isOut)
Get a stream for appending data either
standard-out (isOut == true) or
standard-error (isOut == false). | public void | writeTo(OutputStream os) Write both the standard-out and standard-err
(interleaved in correct ordering) to the given stream. | public void | writeTo(OutputStream os, boolean isOut) Write either the standard-out or standard-error
to the given stream.
Note that the ordering information relative to the
other (out/err) is ignored, which is fine if you only
care about the given (out/err) stream. | public void | writeTo(OutputStream out, OutputStream err) Write the standard-out and (separately) the
standard-error to the given streams.
Each alternation of (out/err) is allowed to complete
its write, which preserves the interleaving. |
DualStreamBuffer | public DualStreamBuffer()(Code) | | |
DualStreamBuffer | public DualStreamBuffer(int size)(Code) | | |
clone | public Object clone()(Code) | | a clone of this DualStreamBuffer instance. |
getOutputStream | public OutputStream getOutputStream(boolean isOut)(Code) | |
Get a stream for appending data either
standard-out (isOut == true) or
standard-error (isOut == false).
|
writeTo | public void writeTo(OutputStream os) throws IOException(Code) | | Write both the standard-out and standard-err
(interleaved in correct ordering) to the given stream.
This is equivalent to fully reading a
getInputStream(), but is more efficient.
|
writeTo | public void writeTo(OutputStream os, boolean isOut) throws IOException(Code) | | Write either the standard-out or standard-error
to the given stream.
Note that the ordering information relative to the
other (out/err) is ignored, which is fine if you only
care about the given (out/err) stream. See
writeTo(Stream,Stream) for an alternative.
This is equivalent to fully reading a
getInputStream(boolean), but is more efficient.
|
writeTo | public void writeTo(OutputStream out, OutputStream err) throws IOException(Code) | | Write the standard-out and (separately) the
standard-error to the given streams.
Each alternation of (out/err) is allowed to complete
its write, which preserves the interleaving. This is
handy when you need to display both streams in the
correct order.
|
|
|