Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:org.g_node.micro.commons.RDFServiceTest.java

/**
 * Reset Out stream to the console and remove all created
 * folders and files after the tests are done.
 * @throws Exception//from  w ww  .  j  a v a 2  s . c  om
 */
@After
public void tearDown() throws Exception {

    System.setOut(this.stdout);

    if (Files.exists(this.testFileFolder)) {
        FileUtils.deleteDirectory(this.testFileFolder.toFile());
    }
}

From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java

/**
 * Fully disable any output via <tt>System.out</tt>.
 * Can be useful to disable possible output of third-party libraries.
 *///from  ww  w  . j  a v a 2  s . c  om
public static void disableStandardOutput() {
    System.setOut(new PrintStream(new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            // no operations
        }
    }));
}

From source file:org.datacleaner.cli.MainTest.java

private void useAsSystemOut(StringWriter stringWriter) {
    OutputStream out = new OutputStream() {
        @Override/*w  w w . j  a v  a 2s  .c o  m*/
        public void write(int b) throws IOException {
            _stringWriter.write(b);
        }
    };
    System.setOut(new PrintStream(out));
}

From source file:com.palantir.atlasdb.cli.runner.AbstractTestRunner.java

@Override
public String run(boolean failOnNonZeroExit, boolean singleLine) {
    PrintStream ps = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    try {//  w  w  w  .j  a v a2  s. com
        int ret = cmd.execute(services);
        if (ret != 0 && failOnNonZeroExit) {
            throw new RuntimeException("CLI returned with nonzero exit code");
        }
    } finally {
        System.setOut(ps);
    }
    return singleLine ? baos.toString().replace("\n", " ").replace("\r", " ") : baos.toString();
}

From source file:com.yahoo.validatar.OutputCaptor.java

public static void redirectToStandard() {
    System.setOut(OUT);
    System.setErr(ERR);
}

From source file:org.apache.tika.parser.mock.MockParserTest.java

@Test
public void testExample() throws Exception {
    Metadata m = new Metadata();
    PrintStream out = System.out;
    PrintStream err = System.err;
    ByteArrayOutputStream outBos = new ByteArrayOutputStream();
    ByteArrayOutputStream errBos = new ByteArrayOutputStream();
    PrintStream tmpOut = new PrintStream(outBos, true, UTF_8.toString());
    PrintStream tmpErr = new PrintStream(errBos, true, UTF_8.toString());
    System.setOut(tmpOut);
    System.setErr(tmpErr);//from  w  w w. j a  v a  2  s  . c  o m
    try {
        assertThrowable("example.xml", m, IOException.class, "not another IOException");
        assertMockParser(m);
    } finally {
        System.setOut(out);
        System.setErr(err);
    }
    String outString = new String(outBos.toByteArray(), UTF_8);
    assertContains("writing to System.out", outString);

    String errString = new String(errBos.toByteArray(), UTF_8);
    assertContains("writing to System.err", errString);

}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGeneratorSlowTest.java

/**
 * Cleans up System.out and System.err print streams after each test
 */
@After
public void cleanUpStreams() {
    System.setOut(null);
    System.setErr(null);
}

From source file:org.datacleaner.cli.MainTest.java

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    System.setOut(_originalSysOut);
}

From source file:org.apache.oozie.tools.TestOozieSharelibCLI.java

/**
 * Test help command/*from  www . j  a  va 2 s . co m*/
 */
public void testHelp() throws Exception {
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    PrintStream oldPrintStream = System.out;
    System.setOut(new PrintStream(data));
    try {
        String[] argsHelp = { "help" };
        assertEquals(0, execOozieSharelibCLICommands(argsHelp));
        String helpMessage = data.toString();
        assertTrue(helpMessage.contains(
                "oozie-setup.sh create <OPTIONS> : create a new timestamped version of oozie sharelib"));
        assertTrue(
                helpMessage.contains("oozie-setup.sh upgrade <OPTIONS> : [deprecated][use command \"create\" "
                        + "to create new version]   upgrade oozie sharelib "));
        assertTrue(helpMessage.contains(" oozie-setup.sh help"));
        assertTrue(
                helpMessage.contains("-concurrency <arg>   Number of threads to be used for copy operations."));
    } finally {
        System.setOut(oldPrintStream);
    }

}

From source file:org.apache.tika.cli.TikaCLIBatchIT.java

@Before
public void setup() throws Exception {
    builder = new ProcessBuilder();
    builder.directory(new File("target"));
    tempOutputDir = Files.createTempDirectory("tika-cli-test-batch-");
    ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
    outContent = new ByteArrayOutputStream();
    out = System.out;/*from  ww  w  .  j  a va2 s .  co m*/
    err = System.err;

    PrintStream outWriter = new PrintStream(outContent, true, UTF_8.name());
    PrintStream errWriter = new PrintStream(errBuffer, true, UTF_8.name());

    System.setOut(outWriter);
    System.setErr(errWriter);
    testInputDirForCommandLine = testResourcesDir.toAbsolutePath().toString() + File.separator + "test-data";
    tempOutputDirForCommandLine = tempOutputDir.toAbsolutePath().toString();
}