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.neo4j.shell.StartClientTest.java

private String runAndCaptureOutput(String[] arguments) {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(buf);
    PrintStream oldOut = System.out;
    System.setOut(out);

    try {/* w  w w  .  j a  v a  2  s .  c  om*/
        StartClient.main(arguments);
        out.close();
        return buf.toString();
    } finally {
        System.setOut(oldOut);
    }
}

From source file:com.cic.datacrawl.ui.Main.java

private static void startupGUI(String[] args) {
    // ??/* www. j  av a2s .  c  o  m*/
    boolean isShowChooseWorkspace = true;

    Main main = new Main(SwingGui.FRAME_TITLE);

    if (isShowChooseWorkspace) {
        ChooseWorkspaceDialog dialog = new ChooseWorkspaceDialog(main.debugGui);
        dialog.setStartupArgs(args);
        dialog.setVisible(true);
    }
    Global global = Global.getInstance();

    main.setExitAction(new IProxy(IProxy.EXIT_ACTION));

    main.attachTo(com.cic.datacrawl.ui.shell.Shell.shellContextFactory);

    main.setScope(global);
    main.setGlobal(global);
    main.pack();

    main.startupBrowser();
    main.maxSize();
    if (!isShowChooseWorkspace) {
        main.setVisible(true);
    }

    if (args.length == 2) {
        args = new String[0];
    }

    global.setIn(main.getIn());
    global.setOut(main.getOut());
    global.setErr(main.getErr());

    System.setIn(main.getIn());
    System.setOut(main.getOut());
    System.setErr(main.getErr());

    com.cic.datacrawl.ui.shell.Shell.setDebugGui(main.debugGui);

    final RhinoDim finalDim = main.dim;
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (InitializerRegister.getInstance().isNotFinished())
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            ((RunOnStartup) ApplicationContext.getInstance().getBean("runOnStartup")).execute(finalDim);
        }
    }).start();
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(60000);
                } catch (InterruptedException e) {
                }
                System.gc();
            }
        }
    }).start();
    // ?
    AutoSaveConfiguration autoSaveRunner = new AutoSaveConfiguration();
    autoSaveRunner.registerSaveRunner(main.debugGui);
    autoSaveRunner.setSleepSecond(3600);
    new Thread(autoSaveRunner).start();

    com.cic.datacrawl.ui.shell.Shell.exec(args, global);
}

From source file:com.stimulus.archiva.domain.FileSystem.java

public void initLogging() {
    //PrintStream stdout = System.out;                                       
    //PrintStream stderr = System.err;                                       
    LoggingOutputStream los;//from  w  ww. j  ava 2  s .c  o m
    los = new com.stimulus.util.LoggingOutputStream(logger);
    System.setOut(new PrintStream(los, true));
    System.setErr(new PrintStream(los, true));
}

From source file:org.owasp.dependencycheck.cli.CliParserTest.java

/**
 * Test of printHelp, of class CliParser.
 *
 * @throws Exception thrown when an exception occurs.
 *///from  ww  w  .ja  v  a2 s .  c o  m
@Test
public void testParse_printHelp() throws Exception {

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

    CliParser instance = new CliParser();
    String[] args = { "-h" };
    instance.parse(args);
    instance.printHelp();
    args[0] = "-ah";
    instance.parse(args);
    instance.printHelp();
    try {
        baos.flush();
        String text = (new String(baos.toByteArray()));
        String[] lines = text.split(System.getProperty("line.separator"));
        Assert.assertTrue(lines[0].startsWith("usage: "));
        Assert.assertTrue((lines.length > 2));
    } catch (IOException ex) {
        System.setOut(out);
        Assert.fail("CliParser.printVersionInfo did not write anything to system.out.");
    } finally {
        System.setOut(out);
    }
}

From source file:edu.vt.middleware.crypt.KeyStoreCliTest.java

/**
 * @param  keyStore  Path to JKS keystore file.
 * @param  storeType  Keystore type. Uses default type if null.
 * @param  cert  Certificate/certificate chain file.
 *
 * @throws  Exception  On test failure.//  ww  w  .j  av a  2  s.  c  o m
 */
@Test(groups = { "cli", "keystore" }, dataProvider = "trustedcertdata")
public void testImportTrustedCert(final String keyStore, final String storeType, final String cert)
        throws Exception {
    new File(TEST_OUTPUT_DIR).mkdir();

    final PrintStream oldStdOut = System.out;
    final String keyStorePath = TEST_OUTPUT_DIR + keyStore;

    final String testAlias = "testng";
    final OptionData keyStoreOption = new OptionData("keystore", keyStorePath);
    final OptionData storeTypeOption = storeType == null ? null : new OptionData("storetype", storeType);
    final OptionData storePassOption = new OptionData("storepass", "changeit");
    final OptionData aliasOption = new OptionData("alias", testAlias);
    final OptionData[] listOptions = new OptionData[] { new OptionData("list"), keyStoreOption, storeTypeOption,
            storePassOption, };
    final OptionData[] importOptions = new OptionData[] { new OptionData("import"), keyStoreOption,
            storeTypeOption, storePassOption, new OptionData("cert", CERT_DIR_PATH + cert), aliasOption, };
    try {
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outStream));

        logger.info("Importing trusted cert into keystore with command line "
                + CliHelper.toCommandLine(importOptions));
        KeyStoreCli.main(CliHelper.toArgs(importOptions));
        AssertJUnit.assertTrue(new File(keyStorePath).exists());

        // Verify imported entry is present and has correct length
        // when we list contents
        outStream.reset();
        KeyStoreCli.main(CliHelper.toArgs(listOptions));

        final String output = outStream.toString();
        logger.info("Keystore listing output:\n" + output);
        AssertJUnit.assertTrue(output.indexOf(testAlias) != -1);

        outStream.reset();
    } finally {
        // Restore STDOUT
        System.setOut(oldStdOut);
    }
}

From source file:edu.clemson.cs.nestbed.server.Server.java

public Server() throws MalformedURLException, RemoteException {
    System.setOut(
            new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.WARN)), true));
    System.setErr(//ww  w  . ja v a2 s.  c o m
            new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.ERROR)), true));

    log.info("******************************************************\n" + "** NESTbed Server Starting\n"
            + "******************************************************");
    log.info("Version:  " + Version.VERSION);

    ParentClassLoader.setParent(Server.class.getClassLoader());

    // Create the RMI registry
    LocateRegistry.createRegistry(1099);

    moteManager = MoteManagerImpl.getInstance();
    shutdownTrigger = new ShutdownTrigger();
    programSymbolManager = ProgramSymbolManagerImpl.getInstance();
    progProfSymbolManager = ProgramProfilingSymbolManagerImpl.getInstance();
    programManager = ProgramManagerImpl.getInstance();
    moteDepConfigManager = MoteDeploymentConfigurationManagerImpl.getInstance();
    projDepConfigManager = ProjectDeploymentConfigurationManagerImpl.getInstance();
    projectManager = ProjectManagerImpl.getInstance();
    moteTypeManager = MoteTypeManagerImpl.getInstance();
    moteTbAssignManager = MoteTestbedAssignmentManagerImpl.getInstance();
    testbedManger = TestbedManagerImpl.getInstance();
    progMsgSymbolManager = ProgramMessageSymbolManagerImpl.getInstance();
    progProfMsgSymbolMgnr = ProgramProfilingMessageSymbolManagerImpl.getInstance();
    messageManager = MessageManagerImpl.getInstance();
    programDeploymentManager = ProgramDeploymentManagerImpl.getInstance();
    programCompileManager = ProgramCompileManagerImpl.getInstance();
    programWeaverManager = ProgramWeaverManagerImpl.getInstance();
    programProbeManager = ProgramProbeManagerImpl.getInstance();
    nucleusManager = NucleusManagerImpl.getInstance();
    sfManager = SerialForwarderManagerImpl.getInstance();
    motePowerManager = MotePowerManagerImpl.getInstance();

    bindRemoteObjects();
}

From source file:org.apache.flink.graph.drivers.DriverBaseITCase.java

/**
 * Capture the command-line standard output from the driver execution.
 *
 * @param args driver command-line arguments
 * @return standard output from driver execution
 * @throws Exception on error/*  w ww .  j  a  v a 2  s . c o  m*/
 */
private String getSystemOutput(String[] args) throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    // Configure object reuse mode
    switch (mode) {
    case CLUSTER:
    case COLLECTION:
        args = ArrayUtils.add(args, "--__disable_object_reuse");
        break;

    case CLUSTER_OBJECT_REUSE:
        // object reuse is enabled by default when executing drivers
        break;

    default:
        throw new FlinkRuntimeException("Unknown execution mode " + mode);
    }

    // Redirect stdout
    PrintStream stdout = System.out;
    System.setOut(new PrintStream(output));

    Runner.main(args);

    // Restore stdout
    System.setOut(stdout);

    return output.toString();
}

From source file:ca.uhn.hl7v2.llp.tests.MinLowerLayerProtocolTest.java

/**
 * Testing subclass LogCharacterReceived() method
 *//* ww w  .  ja  v  a 2s.  co m*/
public void testLogCharacterReceived() {
    int c = 'A';

    // Set properties to generate a status message
    System.setProperty("ca.uhn.hl7v2.llp.tests.logBytesRead", "TRUE");
    System.setProperty("ca.uhn.hl7v2.util.tests.tests.status.out", "");

    minLowerLayerProtocol = new MinLowerLayerProtocol();

    // redirect System.out
    ByteArrayOutputStream statusMsgStream = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(statusMsgStream);
    PrintStream oldOut = System.out;
    System.setOut(ps);

    MinLowerLayerProtocol.logCharacterReceived(c);

    // reset System.out
    System.setOut(oldOut);
    // trim to remove \n at end of logging message
    String statusMessage = statusMsgStream.toString().trim();

    assertEquals("Should have character logging message", "Char received: " + c + " (" + (char) c + ")",
            statusMessage);
}

From source file:functionaltests.NodeSourceCommandsFunctTest.java

private void deployNodeSourceAndCheckOutput(String nodeSourceName, int expectedNumberOfNodes) {
    String out;//from  ww  w  .  jav  a  2s  . c om
    System.out.println(LOG_HEADER + " Test deployns command");

    this.clearAndTypeLine("deployns( '" + nodeSourceName + "')");
    this.runCli();

    out = this.capturedOutput.toString();
    System.setOut(this.stdOut);
    System.out.println(out);

    assertThat(out).contains("Node source successfully deployed.");

    this.checkOccurrencesOfNodeSourceInNodeSourceList(nodeSourceName);
    this.checkOccurrencesOfNodeSourceInNodesList(nodeSourceName, expectedNumberOfNodes);
}

From source file:org.apache.eagle.alert.metric.MetricSystemTest.java

@Test
public void testConsoleSink() throws IOException {
    PrintStream console = System.out;
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bytes));

    ConsoleSink sink = new ConsoleSink();
    MetricRegistry registry = new MetricRegistry();
    JvmAttributeGaugeSet jvm = Mockito.mock(JvmAttributeGaugeSet.class);
    Map<String, Metric> metrics = new HashMap<>();
    metrics.put("name", (Gauge) () -> "testname");
    metrics.put("uptime", (Gauge) () -> "testuptime");
    metrics.put("vendor", (Gauge) () -> "testvendor");
    Mockito.when(jvm.getMetrics()).thenReturn(metrics);
    registry.registerAll(jvm);//  w w w  .  ja va 2  s.com
    File file = genConsoleSinkConfig();
    Config config = ConfigFactory.parseFile(file);
    sink.prepare(config, registry);
    sink.report();
    sink.stop();
    String result = bytes.toString();
    result = result.substring(result.indexOf(END_LINE) + END_LINE.length());//remove first line
    Assert.assertEquals("" + END_LINE + ""
            + "-- Gauges ----------------------------------------------------------------------" + END_LINE + ""
            + "name" + END_LINE + "" + "             value = testname" + END_LINE + "" + "uptime" + END_LINE
            + "" + "             value = testuptime" + END_LINE + "" + "vendor" + END_LINE + ""
            + "             value = testvendor" + END_LINE + "" + "" + END_LINE + "" + "" + END_LINE + "",
            result);
    System.setOut(console);
}