commons-file/src/main/java/info/monitorenter/util/ExceptionUtil.java
public static InputStream captureSystemOutForDebuggingPurposesOnly(
      final boolean teeToOriginalSysOut) throws IOException {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut);
    OutputStream out = pipeOut;
    if (teeToOriginalSysOut) {
      out = new MultiplexingOutputStream(System.out, pipeOut);
    }
    PrintStream streamOut = new PrintStream(out);
    System.setOut(streamOut);
    return pipeIn;
  }
public static InputStream captureSystemOutForDebuggingPurposesOnly(
      final boolean teeToOriginalSysOut) throws IOException {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut);
    OutputStream out = pipeOut;
    if (teeToOriginalSysOut) {
      out = new MultiplexingOutputStream(System.out, pipeOut);
    }
    PrintStream streamOut = new PrintStream(out);
    System.setOut(streamOut);
    return pipeIn;
  }
Returns an input stream that contains what will written in this Application to
{@link System#out}.
<p>
<b>Caution</b>
If you do not consume the bytes to read from the result you may block the whole application. Do
only use this for debugging purposes or end to end test code!
<p>
Attempting to read from the result in the same thread that called here is not recommended as it
may deadlock the thread. Also the thread reading from the stream result should not write
anything to {@link System#out}.
<p>
Prefer using {@link #findMatchInSystemOut(String)} to avoid deadlocks.
<p>

@param teeToOriginalSysOut
if true, all writes to the newly installed {@link System#out} will also sent to the
original one (thus be visible on the console if the original one was untouched
before).
@return an input stream that contains what will written in this Application to
{@link System#out}.
@throws java.io.IOException
if something goes wrong.