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:com.net2plan.gui.GUINet2Plan.java

/**
 * <p>Main method</p>/*w ww  . j  a  v  a2 s .c om*/
 *
 * @param args Command-line parameters (unused)
 * @since 0.2.0
 */
public static void main(String[] args) {
    SystemUtils.configureEnvironment(GUINet2Plan.class, UserInterface.GUI);

    /* Add default canvas systems */
    PluginSystem.addPlugin(ITopologyCanvas.class, JUNGCanvas.class);

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

    try {
        PrintStream out = new PrintStream(ErrorHandling.STREAM, true, StandardCharsets.UTF_8.name());
        System.setOut(out);
        System.setErr(out);

        getInstance().start();
    } catch (Throwable ex) {
        System.setOut(stdout);
        System.setErr(stderr);

        System.out.println("Error loading the graphic environment. Please, try the command line interface.");
        if (!(ex instanceof Net2PlanException) || ErrorHandling.isDebugEnabled())
            ErrorHandling.printStackTrace(ex);

        if (ex instanceof Net2PlanException)
            System.out.println(ex.getMessage());
    }
}

From source file:org.kepler.build.RunTestWorkflows.java

/** Load a workflow or actor and parse the output. */
private void _loadWorkflowOrActor(TestInfo test) throws Exception {

    if (_parseWorkflowMain == null) {
        Class<?> clazz = Class.forName("org.kepler.loader.util.ParseWorkflow");
        _parseWorkflowMain = clazz.getMethod("main", String[].class);
    }//w  w  w. j  ava2s.c om

    // redirect stdout and stderr
    PrintStream stdoutOrig = System.out;
    PrintStream stderrOrig = System.err;

    ByteArrayOutputStream stdoutByteStream = new ByteArrayOutputStream();
    PrintStream stdoutPrintStream = new PrintStream(stdoutByteStream);
    System.setOut(stdoutPrintStream);

    ByteArrayOutputStream stderrByteStream = new ByteArrayOutputStream();
    PrintStream stderrPrintStream = new PrintStream(stderrByteStream);
    System.setErr(stderrPrintStream);

    // call the method
    String[] args;
    // if test is for an actor, add -a argument for ParseWorkflow.main()
    if (test.getTestType() == TestType.Actor) {
        args = new String[] { "-a", test.getPath() };
    } else {
        args = new String[] { test.getPath() };
    }

    long startTime = System.nanoTime();

    _parseWorkflowMain.invoke(null, (Object) args);

    long elapsed = System.nanoTime() - startTime;
    if (elapsed > 0) {
        elapsed = elapsed / 1000000000;
    }
    test.setTime(elapsed);

    // restore stdout and stderr
    System.setOut(stdoutOrig);
    System.setErr(stderrOrig);

    // parse stdout and stderr
    InputStream stream = new ByteArrayInputStream(stdoutByteStream.toByteArray());
    _parseOutput(test, stream, true);
    stdoutByteStream.close();
    stream.close();

    stream = new ByteArrayInputStream(stderrByteStream.toByteArray());
    _parseOutput(test, stream, false);
    stderrByteStream.close();
    stream.close();
}

From source file:org.apache.tika.cli.TikaCLITest.java

/**
 * Tears down the test. Returns the System.out
 */
@After
public void tearDown() throws Exception {
    System.setOut(stdout);
}

From source file:SystemUtils.java

public static void RedirectStdOut(OutputStream outs) throws IOException {
    System.setOut(new PrintStream(outs, true));
}

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

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

public static JInternalFrame FlowSequence() {

    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  w w.j  av  a  2s.c  om

    /** create blank internal frame */

    JInternalFrame FlowSequence = new JInternalFrame("Flow Sequence", true, true, true, true);
    FlowSequence.setBounds(601, 0, 600, 660);
    JTextArea textArea3 = new JTextArea(50, 10);
    PrintStream printStream3 = new PrintStream(new CustomOutputStream(textArea3));
    System.setOut(printStream3);
    System.setErr(printStream3);
    JScrollPane scrollPane3 = new JScrollPane(textArea3);
    FlowSequence.add(scrollPane3);

    /** Process to print the packet one by one */

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

        public void nextPacket(JPacket packet, String user) {
            final JCaptureHeader header = packet.getCaptureHeader();
            Timestamp timestamp = new Timestamp(header.timestampInMillis());
            Tcp tcp = new Tcp();
            Udp udp = new Udp();
            Icmp icmp = new Icmp();
            Ip4 ip4 = new Ip4();
            Ethernet ethernet = new Ethernet();

            /** For IP Packet */

            if (packet.hasHeader(ip4)) {

                if (packet.hasHeader(tcp)) {
                    System.out.println(timestamp.toString() + " :  [TCP]  :  " + FormatUtils.ip(ip4.source())
                            + ":" + tcp.source() + "->" + FormatUtils.ip(ip4.destination()) + ":"
                            + tcp.destination());
                }
                if (packet.hasHeader(udp)) {
                    System.out.println(timestamp.toString() + " :  [UDP]  :  " + FormatUtils.ip(ip4.source())
                            + ":" + udp.source() + "->" + FormatUtils.ip(ip4.destination()) + ":"
                            + udp.destination());
                }
                if (packet.hasHeader(icmp)) {
                    System.out.println(timestamp.toString() + " : [ICMP]  :  " + FormatUtils.ip(ip4.source())
                            + "->" + FormatUtils.ip(ip4.destination()) + ":" + icmp.type());
                }

            }

            /** For Ethernet Packet */

            else if (packet.hasHeader(ethernet)) {
                System.out.println(timestamp.toString() + " :  [ETH]  :  " + FormatUtils.mac(ethernet.source())
                        + "->" + FormatUtils.mac(ethernet.destination()) + ":" + ethernet.type());

            }
        }
    };

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

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

    FlowSequence.setVisible(true);
    pcap4.loop(Pcap.LOOP_INFINITE, jpacketHandler, null);
    FlowSequence.revalidate();
    pcap4.close();

    return FlowSequence;

}

From source file:functionaltests.NodeSourceCommandsFunctTest.java

private void undeployNodeSourceAndCheckOutput(String nodeSourceName, boolean preemptUndeploy) {

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

    if (preemptUndeploy) {
        this.clearAndTypeLine("undeployns( '" + nodeSourceName + "', 'true')");
    } else {/*from  w ww . j  ava  2 s. c o m*/
        this.clearAndTypeLine("undeployns( '" + nodeSourceName + "')");
    }
    this.runCli();

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

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

    this.checkOccurrencesOfNodeSourceInNodeSourceList(nodeSourceName);
    this.checkNoOccurrenceOfNodeSourceInNodesList(nodeSourceName);
}

From source file:functionaltests.TagCommandsFunctTest.java

@Test
public void testJobOutput() throws Exception {
    typeLine("joboutput(" + jobId.longValue() + ")");

    runCli();//from w w w  . j  a  va 2 s .  c om

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testJobOutput:");
    System.out.println(out);
    assertTrue(StringUtils.countMatches(out, "Task 1 : Test STDERR") == 2);
    assertTrue(StringUtils.countMatches(out, "Task 1 : Test STDOUT") == 2);
    assertTrue(StringUtils.countMatches(out, "Terminate task number 1") == 2);
    assertTrue(StringUtils.countMatches(out, "Task 2 : Test STDERR") == 2);
    assertTrue(StringUtils.countMatches(out, "Task 2 : Test STDOUT") == 2);
    assertTrue(StringUtils.countMatches(out, "Terminate task number 2") == 2);
}

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

/**
 * Test subscriptions:list command with one subscription ID argument not matching any registered
 * subscriptions. Should return no subscriptions.
 *
 * @throws Exception/*from   w  w w .j a  v  a 2s .  co  m*/
 */
@Test
public void testListOneNonMatchingSubscriptionIdArg() throws Exception {
    // Setup argument captor for LDAP filter that will be passed in to getServiceReferences()
    // call
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);

    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.id = MY_SUBSCRIPTION_ID;
    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();

    // Verify the LDAP filter passed in when mock BundleContext.getServiceReferences() was
    // called.
    verify(bundleContext).getServiceReferences(anyString(), argument.capture());
    String expectedLdapFilter = "(" + SUBSCRIPTION_ID_PROPERTY_KEY + "=" + MY_SUBSCRIPTION_ID + ")";
    assertThat(argument.getValue(), containsString(expectedLdapFilter));
}

From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java

private void initializeGUI() {
    frame = new JFrame("Hybris Demo GUI");
    frame.setIconImage(new ImageIcon(getClass().getResource("/clouds.png")).getImage());
    frame.setBounds(100, 100, 650, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new GridBagLayout());

    JPanel cloudParentPanel = new JPanel(new GridLayout(1, 2, 10, 10));
    JPanel hybrisPanel = new JPanel(new GridBagLayout());
    JPanel cloudsPanel = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;//from w  w w .jav  a  2 s  .co  m
    gbc.weighty = 1.0;
    gbc.insets = new Insets(5, 5, 5, 5);

    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 3;
    gbc.gridheight = 1;
    gbc.gridx = 0;
    gbc.gridy = 0;
    hybrisPanel.add(new JLabel("<html><b>Hybris</b></html>"), gbc);

    gbc.gridwidth = 3;
    gbc.gridheight = 3;
    gbc.gridx = 0;
    gbc.gridy = 1;

    lstHybris = new JList<String>(lmHybris);
    lstHybris.setPreferredSize(new java.awt.Dimension(100, 500));
    lstHybris.setMinimumSize(new java.awt.Dimension(100, 440));
    hybrisPanel.add(lstHybris, gbc);

    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = 1;
    gbc.gridx = 0;
    gbc.gridy = 4;
    btnPut = new JButton("Put");
    hybrisPanel.add(btnPut, gbc);
    gbc.gridx = 1;
    gbc.gridy = 4;
    btnGet = new JButton("Get");
    hybrisPanel.add(btnGet, gbc);
    gbc.gridx = 2;
    gbc.gridy = 4;
    btnDelete = new JButton("Delete");
    hybrisPanel.add(btnDelete, gbc);

    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    cloudsPanel.add(new JLabel("<html><b>Amazon S3</b></html>"), gbc);

    gbc.gridheight = 2;
    gbc.gridy = 1;
    lstAmazon = new JList<String>(lmAmazon);
    lstAmazon.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstAmazon.setPreferredSize(new java.awt.Dimension(100, 100));
    cloudsPanel.add(lstAmazon, gbc);

    gbc.gridy = 3;
    gbc.gridheight = 1;
    cloudsPanel.add(new JLabel("<html><b>Microsoft Azure</b></html>"), gbc);

    gbc.gridheight = 2;
    gbc.gridy = 4;
    lstAzure = new JList<String>(lmAzure);
    lstAzure.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstAzure.setPreferredSize(new java.awt.Dimension(100, 100));
    cloudsPanel.add(lstAzure, gbc);

    gbc.gridy = 6;
    gbc.gridheight = 1;
    cloudsPanel.add(new JLabel("<html><b>Google Cloud Storage</b></html>"), gbc);

    gbc.gridheight = 2;
    gbc.gridy = 7;
    lstGoogle = new JList<String>(lmGoogle);
    lstGoogle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstGoogle.setPreferredSize(new java.awt.Dimension(100, 100));
    cloudsPanel.add(lstGoogle, gbc);

    gbc.gridy = 9;
    gbc.gridheight = 1;
    cloudsPanel.add(new JLabel("<html><b>Rackspace Cloud Files</b></html>"), gbc);

    gbc.gridheight = 2;
    gbc.gridy = 10;
    lstRackspace = new JList<String>(lmRackspace);
    lstRackspace.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstRackspace.setPreferredSize(new java.awt.Dimension(100, 100));
    cloudsPanel.add(lstRackspace, gbc);

    cloudParentPanel.add(hybrisPanel);
    cloudParentPanel.add(cloudsPanel);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    frame.add(cloudParentPanel, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    JTextArea jt = new JTextArea(10, 30);
    JScrollPane scrollPane = new JScrollPane(jt);
    frame.add(scrollPane, gbc);

    PrintStream printStream = new PrintStream(new CustomOutputStream(jt));
    System.setOut(printStream);
    System.setErr(printStream);

    frame.pack();
    frame.setSize(550, 800);
    frame.setResizable(false);

    lstAmazon.addKeyListener(this);
    lstAzure.addKeyListener(this);
    lstGoogle.addKeyListener(this);
    lstRackspace.addKeyListener(this);
    lstHybris.addKeyListener(this);

    lstAmazon.setCellRenderer(this.new MyListRenderer("amazon"));
    lstGoogle.setCellRenderer(this.new MyListRenderer("google"));
    lstAzure.setCellRenderer(this.new MyListRenderer("azure"));
    lstRackspace.setCellRenderer(this.new MyListRenderer("rackspace"));

    btnGet.addActionListener(this);
    btnPut.addActionListener(this);
    btnDelete.addActionListener(this);
}

From source file:gate.jape.functest.TestJape.java

/**
 * This test sets up a JAPE transducer based on a grammar
 * (RhsError2.jape) that will throw a compiler error.
 * The test succeeds so long as we get that exception.
 *///w w w . j  av a 2  s.c o  m
public void disabled_testRhsErrorMessages2() {

    PrintStream sysout = System.out;
    System.setOut(new PrintStream(new NullOutputStream()));

    // run a JAPE batch on the faulty grammar
    try {
        Document doc = Factory.newDocument("This is a Small Document.");
        FeatureMap features = Factory.newFeatureMap();
        features.put("orth", "upperInitial");
        doc.getAnnotations().add(new Long(0), new Long(8), "Token", features);
        doTest(doc, "tests/RhsError2.jape", null, null);
        fail("Bad JAPE grammar (2) didn't throw an exception");
    } catch (Exception e) {
        // success
    } finally {
        System.setOut(sysout);
    }

}