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.jetbrains.webdemo.executors.JunitExecutor.java

@Override
public void testStarted(Description description) {
    currentTestRunInfo = new TestRunInfo();
    currentTestRunInfo.className = description.getClassName();
    currentTestRunInfo.methodName = description.getMethodName();

    JunitExecutor.output.add(currentTestRunInfo);
    testOutputStream = new ByteArrayOutputStream();
    errorStream = new ErrorStream(testOutputStream);
    outStream = new OutStream(testOutputStream);
    System.setOut(new PrintStream(outStream));
    System.setErr(new PrintStream(errorStream));
    startTime = System.currentTimeMillis();
}

From source file:org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator.java

private void toggleLogs(boolean targetState) {
    if (Context.getAdministrationService()
            .getGlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME).equals("true")) {
        if (targetState == RestConstants.SWAGGER_LOGS_OFF) {
            // turn off the log4j loggers
            List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
            loggers.add(LogManager.getRootLogger());
            for (Logger logger : loggers) {
                originalLevels.put(logger.hashCode(), logger.getLevel());
                logger.setLevel(Level.OFF);
            }// www .j a va 2  s  .  c o  m

            // silence stderr and stdout
            originalErr = System.err;
            System.setErr(new PrintStream(new OutputStream() {

                public void write(int b) {
                    // noop
                }
            }));

            originalOut = System.out;
            System.setOut(new PrintStream(new OutputStream() {

                public void write(int b) {
                    // noop
                }
            }));
        } else if (targetState == RestConstants.SWAGGER_LOGS_ON) {
            List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
            loggers.add(LogManager.getRootLogger());
            for (Logger logger : loggers) {
                logger.setLevel(originalLevels.get(logger.hashCode()));
            }

            System.setErr(originalErr);
            System.setOut(originalOut);
        }
    }
}

From source file:lejos.pc.charting.LogChartFrame.java

/** Default constructor
 */// w  ww . j  av  a  2 s  .  com
public LogChartFrame() {
    try {
        jbInit();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Hooking into System.out..");
    System.setOut(new redirector(System.out));
    System.out.println("creating connectionManager instance");
    this.connectionManager = new LoggerComms();

    String[] thisClass = this.getClass().getName().split("[\\s\\.]");
    THISCLASS = thisClass[thisClass.length - 1];

    // manage Range axis label fields state
    for (int i = 0; i < 4; i++)
        manageAxisLabel(i);
}

From source file:org.commonjava.sjbi.sant.SimpleAntMechanism.java

private void build(final File buildFile, final String[] targets, final SimpleAntResult result) {
    final InputStream origIn = System.in;
    final PrintStream origOut = System.out;
    final PrintStream origErr = System.err;

    final Project project = new Project();

    Throwable error = null;//w w  w  .ja v  a  2 s . co  m
    try {
        project.addBuildListener(new DefaultLogger());
        project.setDefaultInputStream(System.in);

        System.setIn(new DemuxInputStream(project));
        System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
        System.setErr(new PrintStream(new DemuxOutputStream(project, true)));

        project.fireBuildStarted();
        project.init();

        // TODO: Handle properties, via context...?
        // project.setUserProperty(arg, value);

        project.setUserProperty(MagicNames.ANT_FILE, buildFile.getAbsolutePath());
        project.setUserProperty(MagicNames.ANT_FILE_TYPE, MagicNames.ANT_FILE_TYPE_FILE);

        project.setKeepGoingMode(false);

        ProjectHelper.configureProject(project, buildFile);
        project.executeTargets(new Vector<String>(Arrays.asList(targets)));

    } catch (final RuntimeException e) {
        error = e;
        result.addError(new SJBIException("Error occurred in Ant build: %s\nTargets: [%s]\nBuild file: %s", e,
                e.getMessage(), join(targets, ", "), buildFile));
    } catch (final Error e) {
        error = e;
        result.addError(new SJBIException("Error occurred in Ant build: %s\nTargets: [%s]\nBuild file: %s", e,
                e.getMessage(), join(targets, ", "), buildFile));
    } finally {
        project.fireBuildFinished(error);

        System.setIn(origIn);
        System.setOut(origOut);
        System.setErr(origErr);
    }
}

From source file:org.apache.hadoop.gateway.descriptor.xml.XmlGatewayDescriptorImporterTest.java

@Test
public void testXmlGatewayDescriptorLoadInvalid() throws IOException {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<gateway>\n"
            + "  <resource>\n" + "    <filter>\n" + "      <param>";

    Reader reader = new StringReader(xml);
    // Keep the tests quiet.  Ignore the stack trace that ends up being written to System.out.
    Logger logger = Logger.getLogger("org.apache.commons.digester3.Digester");
    Level level = logger.getLevel();
    logger.setLevel(Level.OFF);/*from   w  w w .  j a  v a  2 s.c  o m*/
    PrintStream out = System.out;
    System.setOut(null);
    try {
        GatewayDescriptorFactory.load("xml", reader);
        fail("Should have thrown IOException");
    } catch (IOException e) {
        assertThat(e.getMessage(), containsString("org.xml.sax.SAXParseException"));
    } finally {
        System.setOut(out);
        logger.setLevel(level);
    }
}

From source file:ditl.graphs.test.TestRWP.java

private static void graphsCliToFile(String fmtCmd, String fileName) throws IOException {
    FileOutputStream fos = new FileOutputStream(new File(getStorePath() + "/" + fileName));
    System.setOut(new PrintStream(fos));
    graphsCli(fmtCmd);//from   w w w. j a  va 2  s.co m
    System.setOut(System.out);
}

From source file:com.clematis.jsmodify.JSExecutionTracer.java

public static void postCrawling() {
    try {/* w  w w .  java  2 s  .  c  om*/
        // Add closing bracket
        PrintStream oldOut = System.out;
        System.setOut(output);
        System.out.println(" ");
        System.out.println("}");
        System.setOut(oldOut);

        /* close the output file */
        output.close();

        extraxtTraceObjects();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:flow.visibility.pcap.FlowProcess.java

/** function to create internal frame contain flow details */

public static JInternalFrame FlowInspection() {

    final StringBuilder errbuf = new StringBuilder(); // For any error msgs  
    final String file = "tmp-capture-file.pcap";

    //System.out.printf("Opening file for reading: %s%n", file);  

    /*************************************************************************** 
     * Second we open up the selected file using openOffline call 
     **************************************************************************/
    Pcap pcap = Pcap.openOffline(file, errbuf);

    if (pcap == null) {
        System.err.printf("Error while opening device for capture: " + errbuf.toString());
    }/*  w  ww  .  ja  v  a 2  s. c om*/

    /** create blank internal frame */

    JInternalFrame FlowInspection = new JInternalFrame("Flow Inspection", true, true, true, true);
    FlowInspection.setBounds(601, 0, 600, 660);
    JTextArea textArea2 = new JTextArea(50, 10);
    PrintStream printStream2 = new PrintStream(new CustomOutputStream(textArea2));
    System.setOut(printStream2);
    System.setErr(printStream2);
    JScrollPane scrollPane2 = new JScrollPane(textArea2);
    FlowInspection.add(scrollPane2);

    JPacketHandler<String> jpacketHandler = new JPacketHandler<String>() {

        public void nextPacket(JPacket packet, String user) {
            final JCaptureHeader header = packet.getCaptureHeader();
            System.out.printf("========================= Next Packet ===============================\n");
            System.out.printf("Packet caplen=%d wirelen=%d\n", header.caplen(), header.wirelen());
            System.out.println(packet.toString());

        }
    };

    Pcap pcap3 = Pcap.openOffline(file, errbuf);

    /** Redirect Output into the Frame Text Area */

    FlowInspection.setVisible(true);
    pcap3.loop(Pcap.LOOP_INFINITE, jpacketHandler, null);
    FlowInspection.revalidate();
    pcap3.close();

    return FlowInspection;

}

From source file:org.freeplane.plugin.script.GenericScript.java

@Override
public Object execute(final NodeModel node) {
    try {/*from w  w  w.  j  a va 2s .  c o  m*/
        if (errorsInScript != null && compileTimeStrategy.canUseOldCompiledScript()) {
            throw new ExecuteScriptException(errorsInScript.getMessage(), errorsInScript);
        }
        final ScriptingSecurityManager scriptingSecurityManager = createScriptingSecurityManager();
        final ScriptingPermissions originalScriptingPermissions = new ScriptingPermissions(
                ResourceController.getResourceController().getProperties());
        final FreeplaneSecurityManager securityManager = (FreeplaneSecurityManager) System.getSecurityManager();
        final boolean needToSetFinalSecurityManager = securityManager.needToSetFinalSecurityManager();
        final PrintStream oldOut = System.out;
        try {
            final SimpleScriptContext context = createScriptContext(node);
            if (compilationEnabled && engine instanceof Compilable) {
                compileAndCache((Compilable) engine);
                if (needToSetFinalSecurityManager)
                    securityManager.setFinalSecurityManager(scriptingSecurityManager);
                System.setOut(outStream);
                return compiledScript.eval(context);
            } else {
                if (needToSetFinalSecurityManager)
                    securityManager.setFinalSecurityManager(scriptingSecurityManager);
                System.setOut(outStream);
                return engine.eval(scriptSource.getScript(), context);
            }
        } finally {
            System.setOut(oldOut);
            if (needToSetFinalSecurityManager && securityManager.hasFinalSecurityManager())
                securityManager.removeFinalSecurityManager(scriptingSecurityManager);
            /* restore preferences (and assure that the values are unchanged!). */
            originalScriptingPermissions.restorePermissions();
        }
    } catch (final ScriptException e) {
        handleScriptRuntimeException(e);
        // :fixme: This throw is only reached, if handleScriptRuntimeException
        // does not raise an exception. Should it be here at all?
        // And if: Shouldn't it raise an ExecuteScriptException?
        throw new RuntimeException(e);
    } catch (final Throwable e) {
        if (Controller.getCurrentController().getSelection() != null)
            Controller.getCurrentModeController().getMapController().select(node);
        throw new ExecuteScriptException(e.getMessage(), e);
    }
}

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testListTaskStateWithTag() throws Exception {
    typeLine("taskstates(" + jobId.longValue() + ", 'LOOP-T2-1')");

    runCli();/*from  www .  j a  v  a2  s .co m*/

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testListTaskStateWithTag:");
    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"));
}