private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); @Before public void setUpStreams() { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); } @After public void cleanUpStreams() { System.setOut(null); System.setErr(null); }
/** * Restores System.out and System.err to their original values */ protected static void restoreSystemStreams(){ System.setOut(realSysOut); System.setErr(realSysErr); }
public void terminate() { if (System.err != ORIGINAL_ERR) { System.setErr(ORIGINAL_ERR); } }
public void stop() { if (System.err != ORIGINAL_ERR) { System.setErr(ORIGINAL_ERR); } }
@Override PrintStream replace( PrintStream replacement ) { PrintStream old = java.lang.System.err; java.lang.System.setErr( replacement ); return old; } };
public void stop() { if (System.out != originalOutputPrintStream) { System.setOut(originalOutputPrintStream); } if (System.err != originalErrorPrintStream) { System.setErr(originalErrorPrintStream); } }
private static void restoreStdOutAndStdErr() { System.setOut(stdOut); System.setErr(stdErr); }
private static void redirectStdOutAndErr() { try { PrintStream out = new PrintStream(new FileOutputStream(getOutFile(), true), true); System.setErr(out); System.setOut(out); } catch (FileNotFoundException ignore) { // cannot redirect out and err to file, so we don't log("Unable to redirect stdout/stderr to file " + getOutFile() + ". Will continue without redirecting stdout/stderr."); ignore.printStackTrace(); } }
public void start() { error.reset(); System.setErr(new PrintStream(error)); }
public void record() { os = new PrintStream(output); err = new PrintStream(error); System.setOut(os); System.setErr(err); }
private static void replaceStdOutAndStdErr() { stdOut = System.out; stdErr = System.err; buffer = new ByteArrayOutputStream(); PrintStream capture = new PrintStream(buffer); System.setOut(capture); System.setErr(capture); }
@After public void tearDown() { if (System.out != originalSystemOut) { System.out.close(); } if (System.err != originalSystemErr) { System.err.close(); } System.setOut(originalSystemOut); System.setErr(originalSystemErr); }
@Before public void setUp() { System.setOut(new PrintStream(arrayOutputStream)); System.setErr(new PrintStream(arrayErrorStream)); }
protected static void resetStreamsAndSendOutput() { System.setOut(ORIGINAL_STDOUT); System.setErr(ORIGINAL_STDERR); System.setIn(ORIGINAL_STDIN); LOG.info("Sending stdout content through logger: \n\n{}\n\n", outContent.toString()); LOG.info("Sending stderr content through logger: \n\n{}\n\n", errContent.toString()); }
@Before public void setUp() { System.setOut(new PrintStream(arrayOutputStream)); System.setErr(new PrintStream(arrayErrorStream)); }
@Before public void redirectStreams() { this.out = System.out; this.err = System.err; OutputStream discards = new OutputStream() { @Override public void write(int b) {} }; System.setOut(new PrintStream(discards)); System.setErr(new PrintStream(discards)); }
@After public void tearDown() { if (System.out != originalSystemOut) { System.out.close(); } if (System.err != originalSystemErr) { System.err.close(); } System.setOut(originalSystemOut); System.setErr(originalSystemErr); }
@After public void tearDown() throws IOException { System.setOut(System.out); System.setErr(System.err); mySnapDir.setWritable(true); FileUtils.deleteDirectory(mySnapDir); }
@After public void tearDown() throws Exception { System.setErr(originalErr); System.setOut(originalOut); }
@Before public void setUp() throws IOException { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); File snapDir = new File(testData, "invalidsnap"); mySnapDir = ClientBase.createTmpDir(); FileUtils.copyDirectory(snapDir, mySnapDir); }