public static PrintStream redirectOutput(File newOutput) throws IOException { FileOutputStream newFileStream = null; try { newFileStream = new FileOutputStream(newOutput, true); } catch (FileNotFoundException e) { throw new IOException("File not found: " + newOutput, e); } final PrintStream newPrintStream = new PrintStream(new BufferedOutputStream(newFileStream, 128), true); if (!DISABLE_OUTPUT_REDIRECTION) { System.setOut(newPrintStream); if (System.err instanceof TeePrintStream) { ((TeePrintStream) System.err).getTeeOutputStream().setBranchOutputStream(new BufferedOutputStream(newFileStream, 128)); } else { System.setErr(newPrintStream); } if (!pureMode) { redirectCOutput(newOutput.getPath()); } } return newPrintStream; }
public static PrintStream redirectOutput(File newOutput, boolean setOut) throws IOException { FileOutputStream newFileStream = null; try { newFileStream = new FileOutputStream(newOutput, true); } catch (FileNotFoundException e) { throw new IOException("File not found: " + newOutput, e); } final PrintStream newPrintStream = new PrintStream(new BufferedOutputStream(newFileStream, 128), true); if (ENABLE_OUTPUT_REDIRECTION && !DISABLE_OUTPUT_REDIRECTION && setOut) { System.setOut(newPrintStream); if (System.err instanceof TeePrintStream) { ((TeePrintStream) System.err).getTeeOutputStream().setBranchOutputStream(new BufferedOutputStream(newFileStream, 128)); } else { System.setErr(newPrintStream); } if (!pureMode) { redirectCOutput(newOutput.getPath()); } } assert newPrintStream != null; return newPrintStream; }