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:lucee.runtime.tag.Http4.java

@Override
public int doEndTag() throws PageException {
    Struct cfhttp = new StructImpl();
    cfhttp.setEL(ERROR_DETAIL, "");
    pageContext.setVariable(result, cfhttp);

    // because commons 
    PrintStream out = System.out;
    try {/*from ww  w  .  j a  va2  s .c  om*/
        //System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
        _doEndTag(cfhttp);
        return EVAL_PAGE;
    } catch (IOException e) {
        throw Caster.toPageException(e);
    } finally {
        System.setOut(out);
    }

}

From source file:org.apache.sentry.provider.db.generic.tools.TestSentryShellKafka.java

private Set<String> getShellResultWithOSRedirect(SentryShellKafka sentryShell, String[] args,
        boolean expectedExecuteResult) throws Exception {
    PrintStream oldOut = System.out;
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    assertEquals(expectedExecuteResult, sentryShell.executeShell(args));
    Set<String> resultSet = Sets.newHashSet(outContent.toString().split("\n"));
    System.setOut(oldOut);/*from  w  w  w .j  a  v a 2  s  .  c  o m*/
    return resultSet;
}

From source file:org.apache.flink.yarn.YarnTestBase.java

protected static void sendOutput() {
    System.setOut(originalStdout);
    System.setErr(originalStderr);

    LOG.info("Sending stdout content through logger: \n\n{}\n\n", outContent.toString());
    LOG.info("Sending stderr content through logger: \n\n{}\n\n", errContent.toString());
}

From source file:org.apache.sentry.cli.tools.TestSentryShellKafka.java

private Set<String> getShellResultWithOSRedirect(SentryShellGeneric sentryShell, String[] args,
        boolean expectedExecuteResult) throws Exception {
    PrintStream oldOut = System.out;
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    assertEquals(expectedExecuteResult, sentryShell.executeShell(args));
    Set<String> resultSet = Sets.newHashSet(outContent.toString().split("\n"));
    System.setOut(oldOut);/*from   w  ww. j  a v a2 s. co m*/
    return resultSet;
}

From source file:com.adobe.aem.demo.gui.AemDemo.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void initialize() {

    // Initialize properties
    setDefaultProperties(AemDemoUtils//from  w  w  w  .jav  a 2 s . c  om
            .loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties"));
    setPersonalProperties(AemDemoUtils.loadProperties(buildFile.getParentFile().getAbsolutePath()
            + File.separator + "conf" + File.separator + "build-personal.properties"));

    // Constructing the main frame
    frameMain = new JFrame();
    frameMain.setBounds(100, 100, 700, 530);
    frameMain.getContentPane().setLayout(null);

    // Main menu bar for the Frame
    JMenuBar menuBar = new JMenuBar();

    JMenu mnAbout = new JMenu("AEM Demo Machine");
    mnAbout.setMnemonic(KeyEvent.VK_A);
    menuBar.add(mnAbout);

    JMenuItem mntmDoc = new JMenuItem("Help and Documentation");
    mntmDoc.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmDoc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOCUMENTATION));
        }
    });
    mnAbout.add(mntmDoc);

    JMenuItem mntmQuit = new JMenuItem("Quit");
    mntmQuit.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmQuit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    mnAbout.add(mntmQuit);

    JMenu mnNew = new JMenu("New");
    mnNew.setMnemonic(KeyEvent.VK_N);
    menuBar.add(mnNew);

    // New Demo Machine
    JMenuItem mntmNewDemo = new JMenuItem("Demo Environment");
    mntmNewDemo.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewDemo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (AemDemo.this.getBuildInProgress()) {

                JOptionPane.showMessageDialog(null,
                        "A Demo Environment is currently being built. Please wait until it is finished.");

            } else {

                final AemDemoNew dialogNew = new AemDemoNew(AemDemo.this);
                dialogNew.setModal(true);
                dialogNew.setVisible(true);
                dialogNew.getDemoBuildName().requestFocus();
                ;

            }
        }
    });
    mnNew.add(mntmNewDemo);

    JMenuItem mntmNewOptions = new JMenuItem("Demo Properties");
    mntmNewOptions.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewOptions.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            final AemDemoOptions dialogOptions = new AemDemoOptions(AemDemo.this);
            dialogOptions.setModal(true);
            dialogOptions.setVisible(true);

        }
    });
    mnNew.add(mntmNewOptions);

    JMenu mnUpdate = new JMenu("Add-ons");
    menuBar.add(mnUpdate);

    // Sites Add-on
    JMenu mnSites = new JMenu("Sites");
    mnUpdate.add(mnSites);

    JMenuItem mntmSitesDownloadAddOn = new JMenuItem("Download Add-On");
    mntmSitesDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites");
        }
    });
    mnSites.add(mntmSitesDownloadAddOn);

    JMenuItem mntmSitesDownloadFP = new JMenuItem("Download Feature Pack (VPN)");
    mntmSitesDownloadFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites_fp");
        }
    });
    mnSites.add(mntmSitesDownloadFP);

    mnSites.addSeparator();

    JMenuItem mntmSitesInstallAddOn = new JMenuItem("Install Add-on");
    mntmSitesInstallAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "sites");
        }
    });
    mnSites.add(mntmSitesInstallAddOn);

    // Assets Add-on
    JMenu mnAssets = new JMenu("Assets");
    mnUpdate.add(mnAssets);

    JMenuItem mntmAssetsDownloadAddOn = new JMenuItem("Download Add-on");
    mntmAssetsDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_assets");
        }
    });
    mnAssets.add(mntmAssetsDownloadAddOn);
    mnAssets.addSeparator();

    JMenuItem mntmAssetsInstallAddOn = new JMenuItem("Install Add-on");
    mntmAssetsInstallAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "assets");
        }
    });
    mnAssets.add(mntmAssetsInstallAddOn);

    // Communities Add-on
    JMenu mnCommunities = new JMenu("Communities");
    mnUpdate.add(mnCommunities);

    JMenuItem mntmAemCommunitiesUber = new JMenuItem("Download Latest Bundles (VPN)");
    mntmAemCommunitiesUber.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemCommunitiesUber.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_communities_bundles");
        }
    });
    mnCommunities.add(mntmAemCommunitiesUber);

    JMenuItem mntmAemCommunitiesFeaturePacks = new JMenuItem("Download Latest Feature Packs (PackageShare)");
    mntmAemCommunitiesFeaturePacks.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_communities_fp");
        }
    });
    mnCommunities.add(mntmAemCommunitiesFeaturePacks);

    JMenuItem mntmAemCommunitiesEnablement = new JMenuItem("Download Enablement Demo Site Add-on (4.5GB)");
    mntmAemCommunitiesEnablement.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_enablement");
        }
    });
    mnCommunities.add(mntmAemCommunitiesEnablement);
    mnCommunities.addSeparator();

    JMenuItem mntmAemCommunitiesAddOn = new JMenuItem("Install Add-on");
    mntmAemCommunitiesAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "communities");
        }
    });
    mnCommunities.add(mntmAemCommunitiesAddOn);

    // Forms Add-on
    JMenu mnForms = new JMenu("Forms");
    mnUpdate.add(mnForms);

    JMenuItem mntmAemFormsFP = new JMenuItem("Download Demo Add-on (PackageShare)");
    mntmAemFormsFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_forms_fp");
        }
    });
    mnForms.add(mntmAemFormsFP);

    mnForms.addSeparator();

    JMenuItem mntmAemFormsAddOn = new JMenuItem("Install Add-on");
    mntmAemFormsAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "forms");
        }
    });
    mnForms.add(mntmAemFormsAddOn);

    // Apps Add-on
    JMenu mnApps = new JMenu("Apps");
    mnUpdate.add(mnApps);

    JMenuItem mntmAemApps = new JMenuItem("Download Add-on");
    mntmAemApps.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_apps");
        }
    });
    mnApps.add(mntmAemApps);

    mnApps.addSeparator();

    JMenuItem mntmAemAppsAddOn = new JMenuItem("Install Add-on");
    mntmAemAppsAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "apps");
        }
    });
    mnApps.add(mntmAemAppsAddOn);

    // Commerce Add-on
    JMenu mnCommerce = new JMenu("Commerce");
    mnUpdate.add(mnCommerce);

    JMenu mnCommerceDownload = new JMenu("Download Add-on");
    mnCommerce.add(mnCommerceDownload);

    // Commerce EP
    JMenuItem mnCommerceDownloadEP = new JMenuItem("ElasticPath");
    mnCommerceDownloadEP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_ep");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadEP);

    // Commerce WebSphere
    JMenuItem mnCommerceDownloadWAS = new JMenuItem("WebSphere");
    mnCommerceDownloadWAS.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_websphere");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadWAS);

    mnCommerce.addSeparator();

    JMenuItem mntmAemCommerceAddOn = new JMenuItem("Install Add-on");
    mntmAemCommerceAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "commerce");
        }
    });
    mnCommerce.add(mntmAemCommerceAddOn);

    mnUpdate.addSeparator();

    JMenuItem mntmAemDownloadAll = new JMenuItem("Download All Add-ons");
    mntmAemDownloadAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_all");
        }
    });
    mnUpdate.add(mntmAemDownloadAll);

    JMenuItem mntmAemDownloadFromDrive = new JMenuItem("Download Web Page");
    mntmAemDownloadFromDrive.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_WEBDOWNLOAD));

        }
    });
    mnUpdate.add(mntmAemDownloadFromDrive);

    JMenu mnInfrastructure = new JMenu("Infrastructure");
    menuBar.add(mnInfrastructure);

    JMenu mnMongo = new JMenu("MongoDB");

    JMenuItem mntmInfraMongoDB = new JMenuItem("Download");
    mntmInfraMongoDB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDB);

    JMenuItem mntmInfraMongoDBInstall = new JMenuItem("Install");
    mntmInfraMongoDBInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDBInstall);
    mnMongo.addSeparator();

    JMenuItem mntmInfraMongoDBStart = new JMenuItem("Start");
    mntmInfraMongoDBStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_start");
        }
    });
    mnMongo.add(mntmInfraMongoDBStart);

    JMenuItem mntmInfraMongoDBStop = new JMenuItem("Stop");
    mntmInfraMongoDBStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_stop");
        }
    });
    mnMongo.add(mntmInfraMongoDBStop);
    mnInfrastructure.add(mnMongo);

    // SOLR options
    JMenu mnSOLR = new JMenu("SOLR");

    JMenuItem mntmInfraSOLR = new JMenuItem("Download");
    mntmInfraSOLR.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLR);

    JMenuItem mntmInfraSOLRInstall = new JMenuItem("Install");
    mntmInfraSOLRInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLRInstall);
    mnSOLR.addSeparator();

    JMenuItem mntmInfraSOLRStart = new JMenuItem("Start");
    mntmInfraSOLRStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_start");
        }
    });
    mnSOLR.add(mntmInfraSOLRStart);

    JMenuItem mntmInfraSOLRStop = new JMenuItem("Stop");
    mntmInfraSOLRStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_stop");
        }
    });
    mnSOLR.add(mntmInfraSOLRStop);

    mnInfrastructure.add(mnSOLR);

    // MySQL options
    JMenu mnMySQL = new JMenu("MySQL");

    JMenuItem mntmInfraMysql = new JMenuItem("Download");
    mntmInfraMysql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysql);

    JMenuItem mntmInfraMysqlInstall = new JMenuItem("Install");
    mntmInfraMysqlInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysqlInstall);

    mnMySQL.addSeparator();

    JMenuItem mntmInfraMysqlStart = new JMenuItem("Start");
    mntmInfraMysqlStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_start");
        }
    });
    mnMySQL.add(mntmInfraMysqlStart);

    JMenuItem mntmInfraMysqlStop = new JMenuItem("Stop");
    mntmInfraMysqlStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_stop");
        }
    });
    mnMySQL.add(mntmInfraMysqlStop);

    mnInfrastructure.add(mnMySQL);

    // FFMPEPG options
    JMenu mnFFMPEG = new JMenu("FFMPEG");

    JMenuItem mntmInfraFFMPEG = new JMenuItem("Download");
    mntmInfraFFMPEG.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEG);

    JMenuItem mntmInfraFFMPEGInstall = new JMenuItem("Install");
    mntmInfraFFMPEGInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEGInstall);

    mnInfrastructure.add(mnFFMPEG);

    // Apache James options
    JMenu mnJames = new JMenu("James SMTP");

    JMenuItem mnJamesStart = new JMenuItem("Start");
    mnJamesStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_start");
        }
    });
    mnJames.add(mnJamesStart);

    JMenuItem mnJamesStop = new JMenuItem("Stop");
    mnJamesStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_stop");
        }
    });
    mnJames.add(mnJamesStop);

    mnInfrastructure.add(mnJames);

    mnInfrastructure.addSeparator();

    JMenuItem mntmInfraInstall = new JMenuItem("All in One Setup");
    mntmInfraInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "infrastructure");
        }
    });
    mnInfrastructure.add(mntmInfraInstall);

    JMenu mnOther = new JMenu("Other");
    menuBar.add(mnOther);

    JMenu mntmAemDownload = new JMenu("AEM & License files (VPN)");

    JMenuItem mntmAemDownloadAEM61 = new JMenuItem("Download AEM 6.1");
    mntmAemDownloadAEM61.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem61");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM61);

    JMenuItem mntmAemDownloadAEM60 = new JMenuItem("Download AEM 6.0");
    mntmAemDownloadAEM60.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem60");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM60);

    JMenuItem mntmAemDownloadCQ561 = new JMenuItem("Download CQ 5.6.1");
    mntmAemDownloadCQ561.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq561");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ561);

    JMenuItem mntmAemDownloadCQ56 = new JMenuItem("Download CQ 5.6");
    mntmAemDownloadCQ56.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq56");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ56);

    JMenuItem mntmAemDownloadOthers = new JMenuItem("Other Releases & License files");
    mntmAemDownloadOthers.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOWNLOAD));
        }
    });
    mntmAemDownload.add(mntmAemDownloadOthers);

    mnOther.add(mntmAemDownload);

    JMenuItem mntmAemSnapshot = new JMenuItem("Download Latest AEM Snapshot (VPN)");
    mntmAemSnapshot.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemSnapshot.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_snapshot");
        }
    });
    mnOther.add(mntmAemSnapshot);

    JMenuItem mntmAemDemoMachine = new JMenuItem("Download Latest AEM Demo Machine");
    mntmAemDemoMachine.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemDemoMachine.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DEMODOWNLOAD));
        }
    });
    mnOther.add(mntmAemDemoMachine);

    // Adding the menu bar
    frameMain.setJMenuBar(menuBar);

    // Adding other form elements
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(24, 184, 650, 230);
    frameMain.getContentPane().add(scrollPane);

    final JTextArea textArea = new JTextArea("");
    textArea.setEditable(false);
    scrollPane.setViewportView(textArea);

    // List of demo machines available
    JScrollPane scrollDemoList = new JScrollPane();
    scrollDemoList.setBounds(24, 55, 208, 100);
    frameMain.getContentPane().add(scrollDemoList);
    listModelDemoMachines = AemDemoUtils.listDemoMachines(buildFile.getParentFile().getAbsolutePath());
    listDemoMachines = new JList(listModelDemoMachines);
    scrollDemoList.setViewportView(listDemoMachines);

    // Capturing the output stream of ANT commands
    AemDemoOutputStream out = new AemDemoOutputStream(textArea);
    System.setOut(new PrintStream(out));

    JButton btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "start");

        }
    });
    btnStart.setBounds(250, 50, 117, 29);
    frameMain.getContentPane().add(btnStart);

    // Set Start as the default button
    JRootPane rootPane = SwingUtilities.getRootPane(btnStart);
    rootPane.setDefaultButton(btnStart);

    JButton btnInfo = new JButton("Details");
    btnInfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "version");
            AemDemoUtils.antTarget(AemDemo.this, "configuration");

        }
    });
    btnInfo.setBounds(250, 80, 117, 29);
    frameMain.getContentPane().add(btnInfo);

    JButton btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "stop");

        }
    });
    btnStop.setBounds(500, 50, 117, 29);
    frameMain.getContentPane().add(btnStop);

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    btnExit.setBounds(550, 429, 117, 29);
    frameMain.getContentPane().add(btnExit);

    JButton btnClear = new JButton("Clear");
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText("");
        }
    });
    btnClear.setBounds(40, 429, 117, 29);
    frameMain.getContentPane().add(btnClear);

    JButton btnBackup = new JButton("Backup");
    btnBackup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "backup");
        }
    });
    btnBackup.setBounds(500, 80, 117, 29);
    frameMain.getContentPane().add(btnBackup);

    JButton btnRestore = new JButton("Restore");
    btnRestore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "restore");
        }
    });
    btnRestore.setBounds(500, 110, 117, 29);
    frameMain.getContentPane().add(btnRestore);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "uninstall");
        }
    });
    btnDelete.setBounds(500, 140, 117, 29);
    frameMain.getContentPane().add(btnDelete);

    JLabel lblSelectYourDemo = new JLabel("Select your Demo Environment");
    lblSelectYourDemo.setBounds(24, 31, 219, 16);
    frameMain.getContentPane().add(lblSelectYourDemo);

    JLabel lblCommandOutput = new JLabel("Command Output");
    lblCommandOutput.setBounds(24, 164, 160, 16);
    frameMain.getContentPane().add(lblCommandOutput);

    // Launching the download tracker task
    AemDemoDownload aemDownload = new AemDemoDownload(AemDemo.this);
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(aemDownload, 0, 5, TimeUnit.SECONDS);

}

From source file:org.apache.hadoop.hdfs.TestDFSShell.java

private void textTest(Path root, Configuration conf) throws Exception {
    PrintStream bak = null;// ww  w.  java  2 s  .c o m
    try {
        final FileSystem fs = root.getFileSystem(conf);
        fs.mkdirs(root);

        // Test the gzip type of files. Magic detection.
        OutputStream zout = new GZIPOutputStream(fs.create(new Path(root, "file.gz")));
        Random r = new Random();
        bak = System.out;
        ByteArrayOutputStream file = new ByteArrayOutputStream();
        for (int i = 0; i < 1024; ++i) {
            char c = Character.forDigit(r.nextInt(26) + 10, 36);
            file.write(c);
            zout.write(c);
        }
        zout.close();

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

        String[] argv = new String[2];
        argv[0] = "-text";
        argv[1] = new Path(root, "file.gz").toString();
        int ret = ToolRunner.run(new FsShell(conf), argv);
        assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
        assertTrue("Output doesn't match input", Arrays.equals(file.toByteArray(), out.toByteArray()));

        // Create a sequence file with a gz extension, to test proper
        // container detection. Magic detection.
        SequenceFile.Writer writer = SequenceFile.createWriter(conf,
                SequenceFile.Writer.file(new Path(root, "file.gz")), SequenceFile.Writer.keyClass(Text.class),
                SequenceFile.Writer.valueClass(Text.class));
        writer.append(new Text("Foo"), new Text("Bar"));
        writer.close();
        out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));
        argv = new String[2];
        argv[0] = "-text";
        argv[1] = new Path(root, "file.gz").toString();
        ret = ToolRunner.run(new FsShell(conf), argv);
        assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
        assertTrue("Output doesn't match input", Arrays.equals("Foo\tBar\n".getBytes(), out.toByteArray()));
        out.reset();

        // Test deflate. Extension-based detection.
        OutputStream dout = new DeflaterOutputStream(fs.create(new Path(root, "file.deflate")));
        byte[] outbytes = "foo".getBytes();
        dout.write(outbytes);
        dout.close();
        out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));
        argv = new String[2];
        argv[0] = "-text";
        argv[1] = new Path(root, "file.deflate").toString();
        ret = ToolRunner.run(new FsShell(conf), argv);
        assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
        assertTrue("Output doesn't match input", Arrays.equals(outbytes, out.toByteArray()));
        out.reset();

        // Test a simple codec. Extension based detection. We use
        // Bzip2 cause its non-native.
        CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(BZip2Codec.class, conf);
        String extension = codec.getDefaultExtension();
        Path p = new Path(root, "file." + extension);
        OutputStream fout = new DataOutputStream(codec.createOutputStream(fs.create(p, true)));
        byte[] writebytes = "foo".getBytes();
        fout.write(writebytes);
        fout.close();
        out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));
        argv = new String[2];
        argv[0] = "-text";
        argv[1] = new Path(root, p).toString();
        ret = ToolRunner.run(new FsShell(conf), argv);
        assertEquals("'-text " + argv[1] + " returned " + ret, 0, ret);
        assertTrue("Output doesn't match input", Arrays.equals(writebytes, out.toByteArray()));
        out.reset();
    } finally {
        if (null != bak) {
            System.setOut(bak);
        }
    }
}

From source file:com.github.trugath.jdalvikvm.VirtualMachineTest.java

private VirtualMachine run(final byte[] dexFileContent, final String mainClassName,
        final boolean runInNewThread) {
    lines.clear();//w w  w. j  a va2  s .co  m

    final PrintStream oldErr = System.err;
    final PrintStream newOutAndErr = new PrintStream(new NullOutputStream()) {
        public synchronized void println(Object o) {
            println("" + o);
        }

        public void println(int x) {
            println("" + x);
        }

        public void println(long l) {
            println("" + l);
        }

        public void println(float f) {
            println("" + f);
        }

        public void println(double d) {
            println("" + d);
        }

        public synchronized void println(String x) {
            lines.add(x);
        }
    };
    System.setOut(newOutAndErr);
    System.setErr(newOutAndErr);

    final VirtualMachine vm = new VirtualMachine() {
        protected void error(Throwable e) {
            System.setErr(oldErr);
            e.printStackTrace();
            System.setErr(newOutAndErr);
        }
    };
    vm.load(dexFileContent);
    if (runInNewThread) {
        new java.lang.Thread() {
            public void run() {
                vm.run(mainClassName, new String[0]);
            }
        }.start();
    } else {
        vm.run(mainClassName, new String[0]);
    }

    return vm;
}

From source file:lucee.runtime.tag.Http.java

@Override
public int doEndTag() throws PageException {

    // because commons
    PrintStream out = System.out;
    try {//from  w  ww  .  ja v a 2  s . c om
        // System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
        _doEndTag();
        return EVAL_PAGE;
    } catch (IOException e) {
        throw Caster.toPageException(e);
    } finally {
        System.setOut(out);
    }

}

From source file:org.openlaszlo.sc.SWF9External.java

/**
 * Run the compiler using the command/arguments in cmd. Invokes the Flex compiler classes
 * directly, does not exec a subprocess. 
 * Collect and report any errors, and check for the existence
 * of the output file./*from  w ww. jav a 2 s .co m*/
 * @throw CompilerError if there are errors messages from the external
 *        compiler, or if any part of the compilation process has problems
 */
public void callJavaCompileCommand(List acmd, String dir, List tunits, String outfileName) throws IOException // TODO: [2007-11-20 dda] clean up, why catch only some exceptions?
{
    final List cmd = acmd;
    final String compilerClass = (String) cmd.remove(0);
    String[] cmdstr = (String[]) cmd.toArray(new String[0]);
    String prettycmd = prettyCommand(cmd);
    System.err.println("Executing compiler: (cd " + dir + "; " + prettycmd + ")");
    BigErrorString bigErrorString = new BigErrorString();

    // Generate a small script (unix style) to document how
    // to build this batch of files.
    String buildsh = isWindows() ? "rem build script\n" : "#!/bin/sh\n";
    buildsh += "cd \"" + dir + "\"\n";
    buildsh += prettycmd + "\n";
    String buildfn = isWindows() ? "build.bat" : "build.sh";
    Compiler.emitFile(workDirectoryName(buildfn), buildsh);

    // Remove the shell script executable path from beginning of cmd arg list
    cmd.remove(0);

    if (options.getBoolean(Compiler.EMIT_AS3_ONLY)) {
        // write out the command line as the output instead
        PrintWriter outf = new PrintWriter(new FileWriter(outfileName));
        for (Iterator iter = cmd.iterator(); iter.hasNext();) {
            String arg = (String) iter.next();
            outf.println(arg);
        }
        outf.close();
        System.err.println(
                "option EMIT_AS3_ONLY set, returning without invoking flex compiler, call 'lcompile #' to compile as3");
        return;
    }
    // Save original System.err, System.out
    PrintStream sout = System.out;
    PrintStream serr = System.err;

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ByteArrayOutputStream berr = new ByteArrayOutputStream();

    PrintStream nout = new PrintStream(bout);
    PrintStream nerr = new PrintStream(berr);

    // Rebind to capture output
    System.setErr(nerr);
    System.setOut(nout);

    // flex2.tools.Mxmlc +flexlib="$FLEX_HOME/frameworks"
    // flex2.tools.Compc
    // 

    System.setProperty("FLEX_HOME", FLEX_HOME());
    // The Mxlmc and Compc util classes need to see this arg first in the args list
    cmd.add(0, "+flexlib=" + FLEX_HOME() + "/frameworks");

    final Integer exitval[] = new Integer[1];

    Thread worker = new Thread() {
        public void run() {
            //Process proc = Runtime.getRuntime().exec(cmdstr, (String[])newenv.toArray(new String[0]), null);

            String args[] = (String[]) cmd.toArray(new String[0]);
            if (compilerClass.equals("mxmlc")) {
                flex2.tools.Mxmlc.mxmlc(args);
                exitval[0] = new Integer(flex2.compiler.util.ThreadLocalToolkit.errorCount());

            } else if (compilerClass.equals("compc")) {
                flex2.tools.Compc.compc(args);
                exitval[0] = new Integer(flex2.compiler.util.ThreadLocalToolkit.errorCount());
            }

        }
    };

    try {
        worker.start();
        worker.join();
    } catch (java.lang.InterruptedException e) {
        throw new CompilerError("Errors from compiler, output file not created" + e);
    } finally {
        // Restore system output and err streams
        System.setErr(serr);
        System.setOut(sout);
    }

    try {
        nerr.flush();
        nout.flush();

        System.out.println("compiler output is " + bout.toString());

        OutputCollector outcollect = new OutputCollector(new ByteArrayInputStream(bout.toByteArray()));
        ExternalCompilerErrorCollector errcollect = new ExternalCompilerErrorCollector(
                new ByteArrayInputStream(berr.toByteArray()), tunits);
        outcollect.start();
        errcollect.start();
        outcollect.join();
        errcollect.join();

        if (outcollect.getException() != null) {
            System.err.println("Error collecting compiler output: " + outcollect.getException());
            // TODO: [2007-11-20 dda] log this
        }
        String compilerOutput = outcollect.getOutput();
        if (compilerOutput.length() > 0) {
            System.err.println("compiler output:\n" + compilerOutput);
        }

        if (errcollect.getException() != null) {
            System.err.println("Error collecting compiler output: " + errcollect.getException());
            // TODO: [2007-11-20 dda] log this
        }
        List severe = errcollect.getSevereErrors();
        if (severe.size() > 0) {
            for (Iterator iter = severe.iterator(); iter.hasNext();) {
                String errstr = "SEVERE ERROR: " + (String) iter.next();
                bigErrorString.add(errstr);
                System.err.println(errstr);
            }
        }
        List errs = errcollect.getErrors();
        if (errs.size() > 0) {
            System.err.println("ERRORS: ");
            for (Iterator iter = errs.iterator(); iter.hasNext();) {
                ExternalCompilerError err = (ExternalCompilerError) iter.next();
                TranslationUnit tunit = err.getTranslationUnit();
                String srcLineStr;
                TranslationUnit.SourceFileLine srcFileLine;

                // actualSrcLine is the name/linenumber of the actual files
                // used in compilation, not the original sources.
                String actualSrcFile = null;
                if (tunit == null) {
                    actualSrcFile = "(unknown)";
                } else {
                    actualSrcFile = tunit.getSourceFileName();
                    if (actualSrcFile == null)
                        actualSrcFile = "(" + tunit.getName() + ")";
                }

                String actualSrcLine = "[" + actualSrcFile + ": " + err.getLineNumber() + "] ";

                if (tunit == null) {
                    srcLineStr = "tunit/line unknown: ";
                } else if ((srcFileLine = tunit.originalLineNumber(err.getLineNumber())) == null) {
                    srcLineStr = "line unknown: ";
                } else {
                    srcLineStr = srcFileLine.sourcefile.name + ": " + srcFileLine.line + ": ";
                }
                System.err.println(actualSrcLine + srcLineStr + err.getErrorString());

                bigErrorString.add(srcLineStr + err.cleanedErrorString());
            }
        }

        if (exitval[0].intValue() != 0) {
            System.err.println("FAIL: compiler returned " + exitval[0].intValue());
        }
    } catch (InterruptedException ie) {
        throw new CompilerError("Interrupted compiler");
    }

    System.err.println("Done executing compiler");
    if (!new File(outfileName).exists()) {
        System.err.println("Intermediate file " + outfileName + ": does not exist");
        if (bigErrorString.str.length() > 0) {
            throw new CompilerError(bigErrorString.str);
        } else {
            throw new CompilerError("Errors from compiler, output file not created");
        }
    }

}

From source file:com.twinsoft.convertigo.eclipse.ConvertigoPlugin.java

/**
 * This method is called upon plug-in activation
 *///from w w  w . j a v a  2  s . c  om
@Override
public void start(final BundleContext context) throws Exception {
    super.start(context);

    // Version check
    if (!com.twinsoft.convertigo.eclipse.Version.productVersion
            .equals(com.twinsoft.convertigo.beans.Version.productVersion)) {
        throw new Exception(
                "The product version numbers of Eclipse Plugin and Objects libraries are differents.");
    } else if (!com.twinsoft.convertigo.eclipse.Version.productVersion
            .equals(com.twinsoft.convertigo.engine.Version.productVersion)) {
        throw new Exception(
                "The product version numbers of Eclipse Plugin and Engine libraries are differents.");
    }

    Engine.setStudioMode();

    plugin = this;
    try {
        resourceBundle = ResourceBundle.getBundle("com.twinsoft.convertigo.eclipse.ConvertigoPluginResources");
    } catch (MissingResourceException x) {
        resourceBundle = null;
    }

    log = getLog();
    projectManager = new ProjectManager();
    clipboardManagerSystem = new ClipboardManager();
    clipboardManagerDND = new ClipboardManager();
    //learnProxy = new LearnProxy();

    // Create consoles
    createConsoles();

    // Redirect stdout and stderr
    System.setOut(new StdoutStream());
    System.setErr(new StderrStream());

    studioLog = new Log(ConvertigoPlugin.getDefault().studioConsoleStream);
    studioLog.logLevel = Log.LOGLEVEL_DEBUG;

    try {
        studioLog.logLevel = new Integer(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_LOG_LEVEL))
                .intValue();
    } catch (NumberFormatException e) {
        studioLog.warning("Unable to retrieve the log level; using default log level (4).");
    }

    studioLog.message("Starting the Convertigo studio eclipse plugin");

    try {
        highlightDetectedObject = new Boolean(
                ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_TREE_HIGHLIGHT_DETECTED))
                        .booleanValue();
    } catch (NumberFormatException e) {
        studioLog.warning("Unable to retrieve the highlight option; using default highlight option (true).");
    }

    // In STUDIO, the Convertigo User Workspace is in the current Eclipse Workspace/.metadata/.plugins/com.twinsoft.convertigo.studio
    Engine.USER_WORKSPACE_PATH = getDefault().getStateLocation().toFile().getCanonicalPath();

    // In STUDIO, the Convertigo Projects directory is the current Eclipse Workspace
    Engine.PROJECTS_PATH = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toFile()
            .getCanonicalPath();

    //      checkPre_6_2_0_Migration();

    // Adds listeners
    addListeners();

    DatabaseObjectsManager.openableProject = new DatabaseObjectsManager.OpenableProject() {

        @Override
        public boolean canOpen(String projectName) {
            if ("true".equals(ConvertigoPlugin.getProperty(PREFERENCE_ENGINE_LOAD_ALL_PROJECTS))) {
                return true;
            }
            return isProjectOpened(projectName);
        }

    };

    final Exception afterPscException[] = { null };
    final Runnable afterPscOk = new Runnable() {

        public void run() {
            try {
                // Create embedded Tomcat
                studioLog.message("Starting the embedded Tomcat");
                System.setProperty("org.apache.commons.logging.log",
                        "org.apache.commons.logging.impl.Jdk14Logger");

                Path path = new Path("tomcat");
                URL tomcatHomeUrl = FileLocator.find(context.getBundle(), path, null);

                String xulrunner_url = System.getProperty("org.eclipse.swt.browser.XULRunnerPath");
                if (xulrunner_url == null || xulrunner_url.equals("")) {
                    Bundle[] bundles = Platform.getFragments(context.getBundle());
                    for (Bundle bundle : bundles) {
                        String symbolicName = bundle.getSymbolicName();
                        if (symbolicName.startsWith("com.twinsoft.convertigo.studio.xulrunner")) {
                            URL url = FileLocator.find(bundle, new Path("xulrunner"), null);
                            xulrunner_url = FileLocator.toFileURL(url).getPath();
                            System.setProperty("org.eclipse.swt.browser.XULRunnerPath", xulrunner_url);
                            break;
                        }
                    }
                }

                String tomcatHome = FileLocator.toFileURL(tomcatHomeUrl).getPath();

                int index = (System.getProperty("os.name").indexOf("Windows") != -1) ? 1 : 0;
                tomcatHome = tomcatHome.substring(index);

                embeddedTomcat = new EmbeddedTomcat(tomcatHome);

                configureDeployConfiguration();

                displayWaitScreen();

                new Thread(embeddedTomcat, "Embedded Tomcat").start();
                new Thread(new Runnable() {

                    public void run() {
                        int nbRetry = 0;
                        while (!Engine.isStartFailed && !Engine.isStarted) {
                            try {
                                Thread.sleep(500);
                                nbRetry++;
                            } catch (InterruptedException e) {
                                // Ignore
                            }

                            // Aborting if too many retries
                            if (nbRetry > 360)
                                return;
                        }

                        if (Engine.isStartFailed) {
                            logError("Unable to start engine; see console for more details");
                            return;
                        }

                        // The console threads must be started AFTER the engine
                        consolePipes.startConsoleThreads();

                        try {
                            deploymentConfigurationManager.doMigration();
                        } catch (Exception e) {
                            logException(e, "Unable to migrate deployment configurations");
                        }

                        studioLog.message("Embedded Tomcat started");

                        for (Runnable runnable : runAtStartup) {
                            Display.getDefault().asyncExec(runnable);
                        }
                        runAtStartup.clear();
                    }

                }, "Wait Embedded Tomcat started").start();

            } catch (Exception e) {
                afterPscException[0] = e;
            }
        }

    };

    try {
        decodePsc();
        //Engine.isStartFailed = true;
        afterPscOk.run();
        if (afterPscException[0] != null) {
            throw afterPscException[0];
        }
    } catch (PscException e) {
        studioLog.message(
                "No valid PSC, the Engine will start after the registration wizard.\nFailure message : "
                        + e.getMessage());
        Engine.isStartFailed = true;
        Display display = getDisplay();
        display.asyncExec(new Runnable() {

            public void run() {
                try {
                    boolean success = SetupAction.runSetup();
                    if (success) {
                        Engine.isStartFailed = false;
                        new Thread(afterPscOk, "Start embedded Tomcat").start();
                    } else {
                        IWorkbench workbench = PlatformUI.getWorkbench();
                        workbench.close();
                    }
                } catch (Throwable t) {
                    studioLog.exception(t, "Failure during the Convertigo setup wizard");
                }
            }

        });
    }

    studioLog.message("Convertigo studio started");
}