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:com.geewhiz.pacify.commandline.TestShowUsedProperties.java

@Test
public void writeToStdoutWithPrefix() throws Exception {
    PrintStream oldStdOut = System.out;

    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));

    File testBasePath = new File("target/test-classes/testShowUsedProperties");
    File packagePath = new File(testBasePath, "package");

    int result = 0;
    try {/*  w  w  w  . j a va2s  .  c  om*/
        PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline();

        result = pacifyViaCommandline.mainInternal(
                new String[] { "showUsedProperties", "--packagePath=" + packagePath, "--outputPrefix=###" });
    } finally {
        System.setOut(oldStdOut);
    }

    outContent.close();

    Assert.assertEquals("ShowUsedProperties should not return an error.", 0, result);
    Assert.assertEquals(
            FileUtils.readFileToString(new File(testBasePath + "/expectedResult/resultWithPrefix.txt")),
            outContent.toString());
}

From source file:org.apache.hadoop.util.TestClasspath.java

@Before
public void setUp() {
    assertTrue(FileUtil.fullyDelete(TEST_DIR));
    assertTrue(TEST_DIR.mkdirs());//from w  w  w  .ja  v a  2 s. co  m
    oldStdout = System.out;
    oldStderr = System.err;

    stdout = new ByteArrayOutputStream();
    printStdout = new PrintStream(stdout);
    System.setOut(printStdout);

    stderr = new ByteArrayOutputStream();
    printStderr = new PrintStream(stderr);
    System.setErr(printStderr);
}

From source file:de.langmi.spring.batch.tutorials.helloworld.HelloWorldJobConfigurationManualTest.java

@Before
public void setUpStreams() {
    // catch system out
    System.setOut(new PrintStream(outContent));
}

From source file:org.gradle.util.RedirectStdOutAndErr.java

public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    return new Statement() {
        @Override/*from  ww  w . ja  v a 2 s  .  c o  m*/
        public void evaluate() throws Throwable {
            originalStdOut = System.out;
            originalStdErr = System.err;
            stdOutRouter.setOut(originalStdOut);
            stdErrRouter.setOut(originalStdErr);
            try {
                System.setOut(stdOutPrintStream);
                System.setErr(stdErrPrintStream);
                base.evaluate();
            } finally {
                System.setOut(originalStdOut);
                System.setErr(originalStdErr);
                stdOutRouter = null;
                stdErrRouter = null;
                stdOutPrintStream = null;
                stdErrPrintStream = null;
                stdoutContent = null;
                stderrContent = null;
            }
        }
    };
}

From source file:com.iblsoft.iwxxm.webservice.Main.java

private static void runAsService() throws Exception {
    Configuration configuration = ConfigManager.getConfiguration();

    File logFilePath = new File(configuration.getLogDir(), configuration.getLogFileNamePattern());
    RolloverFileOutputStream os = new RolloverFileOutputStream(logFilePath.getAbsolutePath(), true,
            configuration.getLogRetainInDays(), TimeZone.getTimeZone("UTC"));
    PrintStream logStream = new PrintStream(os);

    Handler handler = createValidationServletHandler(configuration);
    if (configuration.isAccessLogEnabled()) {
        handler = createAccessLogHandler(configuration, handler);
    }/*  w  w w .  ja  v  a2 s . co m*/

    printServiceHelp(configuration);

    Server server = new Server(configuration.getServerPort());
    server.setHandler(handler);

    System.setOut(logStream);
    System.setErr(logStream);
    server.start();
    Log.INSTANCE.info("IBL IWXXM Web Service started [{}]", configuration.getServerPort());

    server.join();
}

From source file:dbs_project.util.Utils.java

public static void revertStreams() {
    System.setOut(oldOut);
    System.setErr(oldErr);
}

From source file:org.g_node.reporter.LKTLogbook.LktCliControllerTest.java

/**
 * Redirect Out stream. Set up temporary folder and minimal RDF file. Setup Logger.
 * @throws Exception/*from   w  w  w . ja v a2 s .c om*/
 */
@Before
public void setUp() throws Exception {
    final String miniTTL = "@prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name \"MainName\"";
    FileUtils.write(this.testRdfFile, miniTTL);

    this.stdout = System.out;
    this.outStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(this.outStream));

    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %m%n")));
}

From source file:org.apache.eagle.service.security.hdfs.rest.MapRNameResolver.java

private String run(String[] cmds) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    mprcmd.run(cmds);/*www. java  2  s . c o m*/
    System.out.flush();
    System.setOut(old);
    return baos.toString().trim();
}

From source file:eu.scape_project.up2ti.output.SimpleKeyValueOutputWriter.java

/**
 * Record method for command line application.
 *
 * @param resultMap Result map where K: recordkey-identificationtype, V:
 * tool identificationtype identificationresult)
 *///from w w  w.  j  av a 2  s  .  c o  m
@Override
public void write(HashMap<String, List<String>> resultMap) {
    Iterator iter = resultMap.keySet().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        List<String> valueList = resultMap.get(key);
        PrintStream pout = null;
        if (outputPathStr != null) {
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(outputPathStr, true);
                pout = new PrintStream(fos);
                System.setOut(pout);
            } catch (FileNotFoundException ex) {
                LOG.error("File not found error", ex);
            }
        }
        for (String value : valueList) {
            System.out.println(key + separator + value);
        }
        if (pout != null) {
            pout.close();
        }
    }
}

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

/**
 * Sets up System.out and System.err print streams before each test
 *///w  w  w . ja  v  a2  s  .c o m
@Before
public void setUpStreams() {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
}