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:co.runrightfast.vertx.core.application.RunRightFastVertxApplicationLauncherTest.java

/**
 * Test of run method, of class RunRightFastVertxApplicationLauncher.
 *//*www. j  a v  a2s . co m*/
@Test
public void testConfigOption() throws UnsupportedEncodingException {
    System.out.println(String.format("\n\n%s%s%s%s%s", StringUtils.repeat('*', 10), StringUtils.repeat(' ', 3),
            "testConfigOption -c", StringUtils.repeat(' ', 3), StringUtils.repeat('*', 10)));

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final PrintStream sysout = System.out;
    try {
        System.setOut(new PrintStream(bos));
        RunRightFastVertxApplicationLauncher.run(() -> app, "-c");
        final String configAsString = bos.toString("UTF-8");
        log.info(configAsString);
        final Config config = ConfigFactory.parseString(configAsString);
    } finally {
        System.setOut(sysout);
    }

    System.out.println(String.format("\n\n%s%s%s%s%s", StringUtils.repeat('*', 10), StringUtils.repeat(' ', 3),
            "testConfigOption --config", StringUtils.repeat(' ', 3), StringUtils.repeat('*', 10)));
    RunRightFastVertxApplicationLauncher.run(() -> app, "--config");
}

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testListTaskStatesWithUnknownTag() throws Exception {
    typeLine("taskstates(" + jobId.longValue() + ", 'unknownTag')");

    runCli();/*from   w w w. j  a v a 2  s  .co m*/

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testListTaskStatesWithUnknownTag:");
    System.out.println(out);
    assertTrue(!out.contains("T1#1"));
    assertTrue(!out.contains("Print1#1"));
    assertTrue(!out.contains("Print2#1"));
    assertTrue(!out.contains("T2#1"));
    assertTrue(!out.contains("T1#2"));
    assertTrue(!out.contains("Print1#2"));
    assertTrue(!out.contains("Print2#2"));
    assertTrue(!out.contains("T2#2"));
}

From source file:net.technicpack.launcher.LauncherMain.java

private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) {
    System.out.println("Setting up logging");
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(directories.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();//from   ww w  .  ja  va 2s.c o m
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new BuildLogFormatter(resources.getLauncherBuild()));

    for (Handler h : logger.getHandlers()) {
        logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);
    logger.setUseParentHandlers(false);

    LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png"));
    Console console = new Console(LauncherMain.consoleFrame, resources.getLauncherBuild());

    logger.addHandler(new ConsoleHandler(console));

    System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
    System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            //                if (errorDialog == null) {
            //                    LauncherFrame frame = null;
            //
            //                    try {
            //                        frame = Launcher.getFrame();
            //                    } catch (Exception ex) {
            //                        //This can happen if we have a very early crash- before Launcher initializes
            //                    }
            //
            //                    errorDialog = new ErrorDialog(frame, e);
            //                    errorDialog.setVisible(true);
            //                }
        }
    });
}

From source file:org.eclipse.wb.internal.core.editor.errors.report2.EnvironmentFileReportInfo.java

private static String tryCreateMozilla() {
    if (EnvironmentUtils.IS_LINUX) {
        boolean oldDebug = Device.DEBUG;
        Device.DEBUG = true;/*from  ww w  .  j a  v  a 2s  .c o  m*/
        PrintStream oldOut = System.out;
        Shell shell = null;
        PrintStream newOut = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            newOut = new PrintStream(baos);
            // replace the out since the Mozilla output debug results into stdout.
            System.setOut(newOut);
            shell = new Shell();
            try {
                new Browser(shell, SWT.NONE);
            } catch (Throwable e) {
                DesignerPlugin.log(e);
            }
            return baos.toString();
        } catch (Throwable e1) {
            // ignore
        } finally {
            if (shell != null) {
                shell.dispose();
            }
            System.setOut(oldOut);
            IOUtils.closeQuietly(newOut);
            Device.DEBUG = oldDebug;
        }
    }
    return "";
}

From source file:functionaltests.NodeSourceCommandsFunctTest.java

private void defineNodeSourceAndCheckOutput(String nodeSourceName, String policyParametersString,
        boolean nodesRecoverableParameter, boolean preemptUndeploy) throws Exception {

    System.out.println(LOG_HEADER + " Test definens command");

    if (nodesRecoverableParameter) {
        this.typeLine("definens( '" + nodeSourceName + "', " + initialInfrastructureParametersString + ", "
                + policyParametersString + ", 'TrUe')");
    } else {//from   w  w  w .j a v  a 2  s .  c o  m
        this.typeLine("definens( '" + nodeSourceName + "', " + initialInfrastructureParametersString + ", "
                + policyParametersString + ")");
    }

    this.runCli();

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

    assertThat(out).contains("Node source successfully defined.");
}

From source file:org.jetbrains.webdemo.executors.JunitExecutor.java

@Override
public void testFinished(Description description) {
    System.out.flush();//from www  . j av  a2s.com
    System.err.flush();

    TestRunInfo testRunInfo = JunitExecutor.output.get(JunitExecutor.output.size() - 1);
    testRunInfo.executionTime = System.currentTimeMillis() - startTime;
    testRunInfo.output = testOutputStream.toString().replaceAll("</errStream><errStream>", "")
            .replaceAll("</outStream><outStream>", "");

    System.setOut(ignoreStream);
}

From source file:org.eclipse.virgo.medic.impl.LogController.java

public void logStop() {
    System.setProperty(PROPERTY_LOGBACK_CONTEXT_SELECTOR, DEFAULT_CONTEXT_SELECTOR);

    DelegatingContextSelector.setDelegate(null);

    if (this.sysOut != null) {
        System.setOut(this.sysOut);
    }/*from w  w  w. j a  v a2  s. c o m*/

    if (this.sysErr != null) {
        System.setErr(this.sysErr);
    }

    SLF4JBridgeHandler.uninstall();
    enableJulConsoleLogger();
}

From source file:mil.dod.th.ose.junit4xmltestrunner.ant.XMLJUnitResultFormatter.java

/**
 * The whole test suite ended./* w w  w.  j  av a2  s .c o  m*/
 * 
 * @param results
 *      Results of the testing
 * @throws IOException
 *      Thrown if unable to write results to output stream 
 */
public void endTestSuite(final Result results) throws IOException {
    System.setOut(m_OldStdOut);
    System.setErr(m_OldStdErr);

    Logging.log(LogService.LOG_INFO, "%n############%n%s%ntests ran: %d, failures: %d%n############",
            m_RootElement.getAttribute(ATTR_NAME), results.getRunCount(), results.getFailureCount());

    setSystemOutput();
    setSystemError();

    m_RootElement.setAttribute(ATTR_TESTS, "" + results.getRunCount());
    m_RootElement.setAttribute(ATTR_FAILURES, "" + m_Failures);
    m_RootElement.setAttribute(ATTR_ERRORS, "" + m_Errors);
    m_RootElement.setAttribute(ATTR_TIME, "" + (results.getRunTime() / ONE_SECOND));
    if (m_Out != null) {
        Writer wri = null;
        try {
            wri = new BufferedWriter(new OutputStreamWriter(m_Out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            (new DOMElementWriter()).write(m_RootElement, wri, 0, "  ");
        } finally {
            if (wri != null) {
                try {
                    wri.flush();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (m_Out != System.out && m_Out != System.err) {
                wri.close();
            }
        }
    }
}

From source file:org.codice.ddf.catalog.pubsub.command.ListCommandTest.java

/**
 * Test subscriptions:list command with no args. Should return no registered subscriptions.
 *
 * @throws Exception//from  w  w w.  ja  va 2  s  .  c  o m
 */
@Test
public void testListNoArgsNoSubscriptionsFound() throws Exception {
    ListCommand listCommand = new ListCommand();

    BundleContext bundleContext = mock(BundleContext.class);
    listCommand.setBundleContext(bundleContext);
    when(bundleContext.getServiceReferences(eq(SubscriptionsCommand.SERVICE_PID), anyString()))
            .thenReturn(new ServiceReference[] {});

    PrintStream realSystemOut = System.out;

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    System.setOut(new PrintStream(buffer));

    // when
    listCommand.execute();

    /* cleanup */
    System.setOut(realSystemOut);

    // then
    assertThat(buffer.toString(), startsWith(ListCommand.RED_CONSOLE_COLOR
            + ListCommand.NO_SUBSCRIPTIONS_FOUND_MSG + ListCommand.DEFAULT_CONSOLE_COLOR));

    buffer.close();
}

From source file:org.apache.rocketmq.tools.command.message.ConsumeMessageCommandTest.java

@Test
public void testExecuteByConditionWhenPullMessageByQueueGotException()
        throws IllegalAccessException, InterruptedException, RemotingException, MQClientException,
        MQBrokerException, NoSuchFieldException, SubCommandException {
    DefaultMQPullConsumer defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    when(defaultMQPullConsumer.pull(any(MessageQueue.class), anyString(), anyLong(), anyInt()))
            .thenThrow(Exception.class);
    Field producerField = ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer");
    producerField.setAccessible(true);//from www . j ava  2  s  . co  m
    producerField.set(consumeMessageCommand, defaultMQPullConsumer);

    PrintStream out = System.out;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bos));
    Options options = ServerUtil.buildCommandlineOptions(new Options());

    String[] subargs = new String[] { "-t mytopic", "-b localhost", "-i 0", "-n localhost:9876" };
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(), subargs,
            consumeMessageCommand.buildCommandlineOptions(options), new PosixParser());
    consumeMessageCommand.execute(commandLine, options, null);

    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(!s.contains("Consume ok"));
}