/** * Assigns the error PrintStream to a temporary text file. This is to allow a log file * (creativityGAResults.log) to be created which holds log data from running the program, for * later analysis. * * @return a copy of the original System.err PrintStream, for later re-assignment */ static PrintStream divertStandardError() { // Save the current standard input, output, and error streams // for later restoration. PrintStream origErr = System.err; try { File error = new File("creativityGAResults.log"); error.createNewFile(); } catch (Exception e) { e.printStackTrace(origErr); } try { System.setErr(new PrintStream(new FileOutputStream("creativityGAResults.log"))); } catch (Exception e) { e.printStackTrace(origErr); } return origErr; }
/** * Assigns the output PrintStream to a temporary text file. This is because parts of the JMusic * package produce a lot of output to the console which isn't needed and clutters up the console. * * @return a copy of the original System.out PrintStream, for later re-assignment */ static PrintStream divertStandardOutput() { // Save the current standard input, output, and error streams // for later restoration. PrintStream origOut = System.out; try { File output = new File("temp_output.txt"); output.createNewFile(); } catch (Exception e) { e.printStackTrace(origOut); } try { System.setOut(new PrintStream(new FileOutputStream("temp_output.txt"))); } catch (Exception e) { e.printStackTrace(origOut); } return origOut; }