Search in sources :

Example 1 with AppendStdOutEvent

use of com.carrotsearch.ant.tasks.junit4.events.AppendStdOutEvent in project randomizedtesting by randomizedtesting.

the class SlaveMain method redirectStreams.

/**
 * Redirect standard streams so that the output can be passed to listeners.
 */
@SuppressForbidden("legitimate sysstreams.")
private static void redirectStreams(final Serializer serializer, final boolean flushFrequently) {
    final PrintStream origSysOut = System.out;
    final PrintStream origSysErr = System.err;
    // Set warnings stream to System.err.
    warnings = System.err;
    AccessController.doPrivileged(new PrivilegedAction<Void>() {

        @SuppressForbidden("legitimate PrintStream with default charset.")
        @Override
        public Void run() {
            System.setOut(new PrintStream(new BufferedOutputStream(new ChunkedStream() {

                @Override
                public void write(byte[] b, int off, int len) throws IOException {
                    if (multiplexStdStreams) {
                        origSysOut.write(b, off, len);
                    }
                    serializer.serialize(new AppendStdOutEvent(b, off, len));
                    if (flushFrequently)
                        serializer.flush();
                }
            })));
            System.setErr(new PrintStream(new BufferedOutputStream(new ChunkedStream() {

                @Override
                public void write(byte[] b, int off, int len) throws IOException {
                    if (multiplexStdStreams) {
                        origSysErr.write(b, off, len);
                    }
                    serializer.serialize(new AppendStdErrEvent(b, off, len));
                    if (flushFrequently)
                        serializer.flush();
                }
            })));
            return null;
        }
    });
}
Also used : AppendStdErrEvent(com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent) PrintStream(java.io.PrintStream) AppendStdOutEvent(com.carrotsearch.ant.tasks.junit4.events.AppendStdOutEvent) SuppressForbidden(com.carrotsearch.randomizedtesting.annotations.SuppressForbidden) BufferedOutputStream(java.io.BufferedOutputStream) SuppressForbidden(com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)

Aggregations

AppendStdErrEvent (com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent)1 AppendStdOutEvent (com.carrotsearch.ant.tasks.junit4.events.AppendStdOutEvent)1 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 BufferedOutputStream (java.io.BufferedOutputStream)1 PrintStream (java.io.PrintStream)1