List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:org.apache.zookeeper.server.persistence.TxnLogToolkitTest.java
@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); }
From source file:org.apache.sqoop.tool.TestMainframeImportTool.java
@After public void tearDown() { System.setOut(null); }
From source file:net.lightbody.bmp.proxy.jetty.log.LogStream.java
/** Log standard output stream. * If set to true, output to stdout will be directed to an instance * of LogStream and logged. Beware of log loops from logs that write to stdout. */// w ww .ja va2 s.c o m public static void setLogStdOut(boolean log) { if (log) { if (!(System.out instanceof LogStream)) System.setOut(new LogStream.STDOUT()); } else System.setOut(STDOUT_STREAM); }
From source file:MyTest.java
@Test public void test() throws Exception { InputStream input = null;/* w w w . j av a 2 s . c om*/ InputStream expectedOutput = null; int i = 0; do { input = Thread.currentThread().getContextClassLoader().getResourceAsStream("input" + String.valueOf(i)); expectedOutput = Thread.currentThread().getContextClassLoader() .getResourceAsStream("output" + String.valueOf(i)); if (input != null) { System.out.println("Running case #" + String.valueOf(i) + " input:"); System.out.println(IOUtils.toString(Thread.currentThread().getContextClassLoader() .getResourceAsStream("input" + String.valueOf(i)), "US-ASCII")); System.setIn(input); if (expectedOutput != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PrintStream realOutput = new PrintStream(byteArrayOutputStream); PrintStream preservedOut = System.out; System.setOut(realOutput); long start = System.currentTimeMillis(); MySolution.main(null); long end = System.currentTimeMillis(); System.setOut(preservedOut); System.out.println("Output:"); System.out.println(byteArrayOutputStream.toString("US-ASCII")); System.out.println("Time: " + (end - start)); assertEquals(IOUtils.toString(expectedOutput, "US-ASCII"), byteArrayOutputStream.toString("US-ASCII")); } else { MySolution.main(null); } } i++; } while (input != null); }
From source file:org.eclipse.jetty.demo.Main.java
private static void defLogging() throws java.io.IOException { org.eclipse.jetty.util.log.Log.setLog(new org.eclipse.jetty.util.log.StdErrLog()); RolloverFileOutputStream rfos = new RolloverFileOutputStream( System.getProperty("user.dir") + "\\log\\jetty_yyyy_mm_dd.log", true); TeeOutputStream myOut = new TeeOutputStream(System.out, rfos); PrintStream ps = new PrintStream(myOut); System.setOut(ps); System.setErr(ps);/*w ww. j av a2 s. co m*/ }
From source file:org.jiemamy.script.jython.JythonScriptEngineTest.java
/** * exec?/* w w w.j a v a2s . c om*/ * * @throws Exception ???? */ @Test @Ignore public void test01() throws Exception { PrintStream saved = System.out; PrintStream ps = null; ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); ps = new PrintStream(baos); System.setOut(ps); engine.process(null, "print 'Hello!'"); } finally { System.setOut(saved); IOUtils.closeQuietly(ps); } assertThat(baos.toString(CharEncoding.UTF_8), is("Hello!\n")); }
From source file:org.apache.kylin.tool.KylinConfigCLITest.java
@Test public void testGetPrefix() throws IOException { PrintStream o = System.out; File f = File.createTempFile("cfg", ".tmp"); PrintStream tmpOut = new PrintStream(new FileOutputStream(f)); System.setOut(tmpOut); KylinConfigCLI.main(new String[] { "kylin.cube.engine." }); String val = FileUtils.readFileToString(f, Charset.defaultCharset()).trim(); assertEquals("2=org.apache.kylin.engine.mr.MRBatchCubingEngine2" + System.lineSeparator() + "0=org.apache.kylin.engine.mr.MRBatchCubingEngine", val); tmpOut.close();//from w w w . j a v a 2 s . com FileUtils.forceDelete(f); System.setOut(o); }
From source file:edu.rit.flick.util.FlickTest.java
@AfterClass public static void cleanUpStreams() throws IOException { outContent.close();// w ww. ja v a 2s . com errContent.close(); System.setOut(oldOut); System.setErr(oldErr); }
From source file:org.owasp.dependencycheck.cli.CliParserTest.java
/** * Test of parse method, of class CliParser. * * @throws Exception thrown when an exception occurs. *//*from w ww .ja v a2 s . c om*/ @Test public void testParse() throws Exception { String[] args = {}; PrintStream out = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); CliParser instance = new CliParser(); instance.parse(args); Assert.assertFalse(instance.isGetVersion()); Assert.assertFalse(instance.isGetHelp()); Assert.assertFalse(instance.isRunScan()); }
From source file:org.apache.wiki.util.CryptoUtilTest.java
public void testCommandLineNoVerify() throws Exception { // Save old printstream PrintStream oldOut = System.out; // Swallow System out and get command output OutputStream out = new ByteArrayOutputStream(); System.setOut(new PrintStream(out)); // Supply a bogus password CryptoUtil.main(new String[] { "--verify", "password", "{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" }); String output = new String(out.toString()); // Restore old printstream System.setOut(oldOut);/*from w ww . j a v a 2 s . com*/ // Run our tests assertTrue(output.startsWith("false")); }