commons-file/src/main/java/info/monitorenter/util/ExceptionUtil.java
public static InputStream captureSystemErrForDebuggingPurposesOnly(
      final boolean teeToOriginalSysErr) throws IOException {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut);
    OutputStream out = pipeOut;

    if (teeToOriginalSysErr) {
      out = new MultiplexingOutputStream(System.err, pipeOut);
    }
    PrintStream streamOut = new PrintStream(out);

    System.setErr(streamOut);
    return pipeIn;
  }
public static InputStream captureSystemErrForDebuggingPurposesOnly(
      final boolean teeToOriginalSysErr) throws IOException {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut);
    OutputStream out = pipeOut;

    if (teeToOriginalSysErr) {
      out = new MultiplexingOutputStream(System.err, pipeOut);
    }
    PrintStream streamOut = new PrintStream(out);

    System.setErr(streamOut);
    return pipeIn;
  }
Returns an input stream that contains what will written in this Application to
{@link System#err}.
<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#err}.
<p>
Prefer using {@link #findMatchInSystemErr(String)} to avoid deadlocks.
<p>

@param teeToOriginalSysErr
if true, all writes to the newly installed {@link System#err} 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#err}.
@throws java.io.IOException
if something goes wrong.