* @param defaultPrintStream if not null, this utility will always write to this stream. Typically this is System.out
* @return the single PrintStream that wraps all the input streams for writing and comparison.
* @since 4.2
*/
public static PrintStream getPrintStream(OutputStream resultsOutput, BufferedReader expectedResultsInput, PrintStream defaultPrintStream) {
PrintStream out = null;
if (defaultPrintStream == null) {
defaultPrintStream = new PrintStream(new OutputStream () {
public void write(int b) throws IOException {}
});
}
if (resultsOutput == null && expectedResultsInput == null) {
out = defaultPrintStream;
} else if (resultsOutput == null && expectedResultsInput != null) {
out = new ComparingPrintStream(defaultPrintStream, expectedResultsInput);
} else if (resultsOutput!= null && expectedResultsInput == null) {
PrintStream filePrintStream = new PrintStream(resultsOutput);
out = new MuxingPrintStream(new PrintStream[] {defaultPrintStream, filePrintStream});
} else {
PrintStream filePrintStream = new PrintStream(resultsOutput);
out = new ComparingPrintStream(new MuxingPrintStream(new PrintStream[] {defaultPrintStream, filePrintStream}), expectedResultsInput);
}
return out;
}