bb.util
Class JUnitExecutor.StdStreams

java.lang.Object
  extended by bb.util.JUnitExecutor.StdStreams
Enclosing class:
JUnitExecutor

private static class JUnitExecutor.StdStreams
extends Object

Swaps and unswaps the standard streams (System.out and System.err) for a pair of JUnitExecutor.BufferWithEcho instances.

This class guarantees that the same replacement streams are always used across all calls to swap and unswap. In the context of the containing class, this behavior is required in order to coordinate the use of this class by loadClass and JUnitExecutor.StdStreamSwapper. This class satisfies this guarantee by being entirely static based, since that is an easy way to assure singleton behavior.

This class is multithread safe: every method is synchronized.


Field Summary
private static JUnitExecutor.BufferWithEcho stdErrBuffer
           
private static PrintStream stdErrOriginal
           
private static JUnitExecutor.BufferWithEcho stdOutBuffer
           
private static PrintStream stdOutOriginal
           
 
Constructor Summary
private JUnitExecutor.StdStreams()
          This private constructor suppresses the default (public) constructor, ensuring non-instantiability.
 
Method Summary
private static void swap()
           
private static void unswap(File fileOut, File fileErr)
          First unswaps the standard streams to their original objects, then writes any contents of the JUnitExecutor.BufferWithEcho instances to either the corresponding File args (fileOut and fileErr), if non-null, or else to the original standard stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stdOutOriginal

private static final PrintStream stdOutOriginal

stdErrOriginal

private static final PrintStream stdErrOriginal

stdOutBuffer

private static final JUnitExecutor.BufferWithEcho stdOutBuffer

stdErrBuffer

private static final JUnitExecutor.BufferWithEcho stdErrBuffer
Constructor Detail

JUnitExecutor.StdStreams

private JUnitExecutor.StdStreams()
This private constructor suppresses the default (public) constructor, ensuring non-instantiability.

Method Detail

swap

private static void swap()

unswap

private static void unswap(File fileOut,
                           File fileErr)
                    throws IllegalStateException,
                           Exception
First unswaps the standard streams to their original objects, then writes any contents of the JUnitExecutor.BufferWithEcho instances to either the corresponding File args (fileOut and fileErr), if non-null, or else to the original standard stream.

Throws:
IllegalStateException - if System.out == stdOutOriginal; System.err == stdErrOriginal
Exception - if one or more Throwables are raised during execution; the message will contain the stack traces of each one