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.apache.hadoop.dfs.TestFsck.java

static String runFsck(Configuration conf, int expectedErrCode, boolean checkErrorCode, String... path)
        throws Exception {
    PrintStream oldOut = System.out;
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    PrintStream newOut = new PrintStream(bStream, true);
    System.setOut(newOut);
    ((Log4JLogger) PermissionChecker.LOG).getLogger().setLevel(Level.ALL);
    int errCode = ToolRunner.run(new DFSck(conf), path);
    if (checkErrorCode)
        assertEquals(expectedErrCode, errCode);
    ((Log4JLogger) PermissionChecker.LOG).getLogger().setLevel(Level.INFO);
    System.setOut(oldOut);//w w w  .  j  a va 2s . c  om
    return bStream.toString();
}

From source file:com.example.PollingReceiverTest.java

@BeforeClass
public static void prepare() {
    assumeThat("PUB/SUB-sample integration tests are disabled. Please use '-Dit.pubsub=true' "
            + "to enable them. ", System.getProperty("it.pubsub"), is("true"));

    systemOut = System.out;//from w w w .ja  v  a 2s  .c o m
    baos = new ByteArrayOutputStream();
    TeeOutputStream out = new TeeOutputStream(systemOut, baos);
    System.setOut(new PrintStream(out));
}

From source file:org.chimi.s4s.config.Log4jConfiguratorTest.java

@Test
public void configure() {
    ByteArrayOutputStream baout = new ByteArrayOutputStream(200);
    PrintStream out = new PrintStream(baout);
    System.setOut(out);

    System.setProperty(Log4jConfigurator.CONFIG_PATH_SYSTEM_PROPERTY,
            "src/test/resources/org/chimi/s4s/config/test-log4j.properties");
    Log4jConfigurator.configure();/*w  w  w  . j  a v  a 2s .c  o  m*/

    baout.reset();

    // SLF4J 
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("");

    assertEquals("INFO - ", new String(baout.toByteArray()).trim());

    baout.reset();

    // JCL 
    Log log = LogFactory.getLog(getClass());
    log.warn("");

    assertEquals("WARN - ", new String(baout.toByteArray()).trim());
}

From source file:corina.logging.CorinaLog.java

public static void init() {
    System.setOut(createPrintStream(STDOUT, false));
    System.setErr(createPrintStream(STDERR, true));
}

From source file:alluxio.cli.fs.command.ChownCommandTest.java

@After
public void cleanupStreams() {
    System.setOut(null);
    System.setErr(null);
}

From source file:org.timer4method.test.Timer4MethodTest.java

@After
public void cleanUpStreams() {
    System.setOut(null);
}

From source file:org.apache.tika.example.SimpleTextExtractorTest.java

@Test
public void testSimpleTextExtractor() throws Exception {
    String message = "This is Tika - Hello, World! This is simple UTF-8 text"
            + " content written in English to test autodetection of"
            + " the character encoding of the input stream.";
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    PrintStream out = System.out;
    System.setOut(new PrintStream(buffer, true, UTF_8.name()));

    File file = new File("target", "test.txt");
    FileUtils.writeStringToFile(file, message, UTF_8);
    SimpleTextExtractor.main(new String[] { file.getPath() });
    file.delete();/*w ww  .j  a  va  2s.c o m*/

    System.setOut(out);

    assertEquals(message, buffer.toString(UTF_8.name()).trim());
}

From source file:javancss.ParseDebugTest.java

@Override
protected Javancss measureTestFile(int testFileId) {
    Logger logger = Logger.getLogger("javancss");
    logger.setLevel(Level.FINEST);

    PrintStream stdout = System.out;
    PrintStream stderr = System.err;

    try {//from w  w  w  .  j  av  a  2  s  . com
        System.setOut(new PrintStream(new NullOutputStream()));
        System.setErr(new PrintStream(new NullOutputStream()));

        return super.measureTestFile(testFileId);
    } finally {
        logger.setLevel(Level.OFF);
        System.setOut(stdout);
        System.setErr(stderr);
    }
}

From source file:com.geewhiz.pacify.commandline.TestShowUsedProperties.java

@Test
public void writeToStdout() 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  v a 2s  .c  o  m*/
        PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline();
        result = pacifyViaCommandline
                .mainInternal(new String[] { "showUsedProperties", "--packagePath=" + packagePath });
    } finally {
        System.setOut(oldStdOut);
    }

    outContent.close();

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

From source file:ape_test.CLITest.java

/**
 * This test just checks to see if the start of the help dialog is printed
 * Since the help dialog will continue to be updated, it's not worth constantly changing this test
 *//*from   ww w  .  ja  v a  2  s .  c  o m*/
public void testHelpDialog() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);

    String[] theArgs = new String[1];
    theArgs[0] = "-h";
    Main.main(theArgs);
    System.setOut(originalOut);
    assertEquals("usage: ape", (os.toString()).substring(0, 10));
}