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.taverna.scufl2.wfdesc.TestConvertToWfdesc.java

@After
public void restoreStd() {
    System.setIn(origIn);
    System.setOut(origOut);
    System.setErr(origErr);
}

From source file:org.apache.hadoop.hbase.backup.TestBackupDescribe.java

@Test
public void testBackupDescribeCommand() throws Exception {

    LOG.info("test backup describe on a single table with data: command-line");

    List<TableName> tableList = Lists.newArrayList(table1);
    String backupId = fullTableBackup(tableList);

    LOG.info("backup complete");
    assertTrue(checkSucceeded(backupId));

    BackupInfo info = getBackupAdmin().getBackupInfo(backupId);
    assertTrue(info.getState() == BackupState.COMPLETE);

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

    String[] args = new String[] { "describe", backupId };
    // Run backup
    int ret = ToolRunner.run(conf1, new BackupDriver(), args);
    assertTrue(ret == 0);/*from   w ww. j ava2s.  c o  m*/
    String response = baos.toString();
    assertTrue(response.indexOf(backupId) > 0);
    assertTrue(response.indexOf("COMPLETE") > 0);

    BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
    BackupInfo status = table.readBackupInfo(backupId);
    String desc = status.getShortDescription();
    table.close();
    assertTrue(response.indexOf(desc) >= 0);

}

From source file:org.apache.zeppelin.pig.PigInterpreter.java

@Override
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
    // remember the origial stdout, because we will redirect stdout to capture
    // the pig dump output.
    PrintStream originalStdOut = System.out;
    ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream();
    File tmpFile = null;//from   ww w  . j  a  v a2  s .co m
    try {
        pigServer.setJobName(createJobName(cmd, contextInterpreter));
        tmpFile = PigUtils.createTempPigScript(cmd);
        System.setOut(new PrintStream(bytesOutput));
        // each thread should its own ScriptState & PigStats
        ScriptState.start(pigServer.getPigContext().getExecutionEngine().instantiateScriptState());
        // reset PigStats, otherwise you may get the PigStats of last job in the same thread
        // because PigStats is ThreadLocal variable
        PigStats.start(pigServer.getPigContext().getExecutionEngine().instantiatePigStats());
        PigScriptListener scriptListener = new PigScriptListener();
        ScriptState.get().registerListener(scriptListener);
        listenerMap.put(contextInterpreter.getParagraphId(), scriptListener);
        pigServer.registerScript(tmpFile.getAbsolutePath());
    } catch (IOException e) {
        if (e instanceof FrontendException) {
            FrontendException fe = (FrontendException) e;
            if (!fe.getMessage().contains("Backend error :")) {
                // If the error message contains "Backend error :", that means the exception is from
                // backend.
                LOGGER.error("Fail to run pig script.", e);
                return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
            }
        }
        PigStats stats = PigStats.get();
        if (stats != null) {
            String errorMsg = PigUtils.extactJobStats(stats);
            if (errorMsg != null) {
                LOGGER.error("Fail to run pig script, " + errorMsg);
                return new InterpreterResult(Code.ERROR, errorMsg);
            }
        }
        LOGGER.error("Fail to run pig script.", e);
        return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
    } finally {
        System.setOut(originalStdOut);
        listenerMap.remove(contextInterpreter.getParagraphId());
        if (tmpFile != null) {
            tmpFile.delete();
        }
    }
    StringBuilder outputBuilder = new StringBuilder();
    PigStats stats = PigStats.get();
    if (stats != null && includeJobStats) {
        String jobStats = PigUtils.extactJobStats(stats);
        if (jobStats != null) {
            outputBuilder.append(jobStats);
        }
    }
    outputBuilder.append(bytesOutput.toString());
    return new InterpreterResult(Code.SUCCESS, outputBuilder.toString());
}

From source file:org.nuxeo.automation.scripting.test.TestScriptRunnerInfrastructure.java

@Before
public void setupContext() {
    outStream = System.out;
    System.setOut(new PrintStream(outContent));
}

From source file:org.opendaylight.ovsdb.plugin.shell.PrintCacheTest.java

@Test
public void testDoExecute() throws Exception {
    // Read in schema and create the DatabaseSchema
    InputStream resourceAsStream = PrintCacheTest.class.getResourceAsStream("test_schema.json");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(resourceAsStream);
    DatabaseSchema schema = DatabaseSchema.fromJson("some", jsonNode.get("result"));
    assertNotNull(schema);//from   w w w .j  a v  a  2s .  c o m
    assertEquals(Version.fromString("6.12.0"), schema.getVersion());

    // Add params to PrintCache
    PrintCache printCacheTest = new PrintCache();
    Field cNField = printCacheTest.getClass().getDeclaredField("nodeName");
    cNField.setAccessible(true);
    cNField.set(printCacheTest, NODESTRING);
    InventoryServiceImpl inventoryService = new InventoryServiceImpl();
    inventoryService.init();
    printCacheTest.setOvsdbInventory(inventoryService);

    // Test that an empty cache prints nothing
    // Capture the output from PrintCache and compare it to what is expected
    PrintStream originalBaos = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    printCacheTest.doExecute();
    assertEquals("PrintCache output does not match expected output:", "", baos.toString());

    // Add some data to the bridges row in the Open_vSwitch table
    GenericTableSchema ovsTable = schema.table(OPENVSWITCH, GenericTableSchema.class);
    ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn(BRIDGES, UUID.class);
    Column column = new Column(bridges, new UUID(BRIDGE).toString());
    Row row = new Row(ovsTable);
    row.addColumn(BRIDGES, column);

    NodeId nodeId = new NodeId(NODESTRING);
    NodeKey nodeKey = new NodeKey(nodeId);
    Node node = new NodeBuilder().setId(nodeId).setKey(nodeKey).build();
    inventoryService.updateRow(node, OvsVswitchdSchemaConstants.DATABASE_NAME, OPENVSWITCH,
            new UUID("1").toString(), row);

    // Test that a populated cache is printed correctly
    // Capture the output from PrintCache and compare it to what is expected
    printCacheTest.doExecute();
    System.setOut(originalBaos);
    assertEquals("PrintCache output does not match expected output:", CACHE, baos.toString());
}

From source file:com.github.tomakehurst.wiremock.StandaloneAcceptanceTest.java

@After
public void stopServerRunner() {
    runner.stop();
    if (otherServer != null) {
        otherServer.stop();
    }
    System.setOut(stdOut);
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticLogger.java

private void captureStdOut() {
    try {//  ww  w.  j  a  v  a 2s  . c om
        stdOutFile = new File(logDirectory, stdOutFilePath);
        stdOutStream = new FileOutputStream(stdOutFile);
        final TeeOutputStream myOut = new TeeOutputStream(System.out, stdOutStream);
        final PrintStream ps = new PrintStream(myOut, true); // true - auto-flush after println
        System.setOut(ps);

        logger.info("Writing sysout to file: " + stdOutFile.getCanonicalPath());

    } catch (final Exception e) {
        logger.info("Failed to capture sysout.", e);
    }
}

From source file:dev.agustin.serializer.MainWindow.java

private void setOutputStreamToScreen() {
    PrintStream str = new PrintStream(consoleOutput, true);
    System.setOut(str);
    System.setErr(str);
}

From source file:de.langmi.spring.batch.examples.basics.purejava.jobruns.PureJavaJobRunTest.java

@After
public void tearDown() {
    // reset JVM standard
    System.setOut(oldSysOut);
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static void initLog() throws Exception {
    String logDir = ConfigManager.getInstance().get(null, "output_dir", ".");
    File logDirFile = new File(logDir);
    if (!logDirFile.exists()) {
        logDirFile.mkdirs();/*from   w w  w  . j ava 2 s . com*/
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss.SSS");
    String date = df.format(new Date());

    String stdoutLogFile = new File(logDir, "stdout_" + date + ".log").getAbsolutePath();
    LogOutputStream stdout = new LogOutputStream(stdoutLogFile, System.out);
    System.setOut(new PrintStream(stdout, true));

    String stderrLogFile = new File(logDir, "stderr_" + date + ".log").getAbsolutePath();
    LogOutputStream stderr = new LogOutputStream(stderrLogFile, System.err);
    System.setErr(new PrintStream(stderr, true));

}