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:v800_trainer.JCicloTronic.java

/** Creates new form JCicloTronic */
public JCicloTronic() {

    ScreenSize = new Dimension();
    SelectionChanged = false;/*  www  .j  av  a2s .c  o  m*/
    ScreenSize.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 50,
            java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 50);
    Size = new Dimension();

    Properties = new java.util.Properties();
    SystemProperties = java.lang.System.getProperties();
    chooser = new javax.swing.JFileChooser();
    RawData = new byte[98316];
    //        System.setProperty("jna.library.path" , "C:/WINDOWS/system32");

    try {
        FileInputStream in = new FileInputStream(SystemProperties.getProperty("user.dir")
                + SystemProperties.getProperty("file.separator") + "JCicloexp.cfg");
        Properties.load(in);
        in.close();
    } catch (Exception e) {
        FontSize = 20;
        setFontSizeGlobal("Tahoma", FontSize);

        JOptionPane.showMessageDialog(null,
                "Keine Config-Datei in:  " + SystemProperties.getProperty("user.dir"), "Achtung!",
                JOptionPane.ERROR_MESSAGE);
        Properties.put("working.dir", SystemProperties.getProperty("user.dir"));
        Eigenschaften = new Eigenschaften(new javax.swing.JFrame(), true, this);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();
        this.setSize(new Dimension((int) width, (int) height));
        this.setPreferredSize(new Dimension((int) width, (int) height));
        this.setMinimumSize(new Dimension((int) width, (int) height));
        repaint();
    }
    try {

        UIManager.setLookAndFeel(Properties.getProperty("LookFeel"));
        SwingUtilities.updateComponentTreeUI(this);
        this.pack();
    } catch (Exception exc) {
    }

    if (debug) {
        try {
            System.setErr(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
            //        System.err =  new FileOutputStream(Properties.getProperty("working.dir") + SystemProperties.getProperty("file.separator") + "error.txt");
            System.setOut(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
        } catch (Exception err) {
        }
    }

    initComponents();

    setTitle("V800 Trainer    Datadir: " + Properties.getProperty("data.dir"));

    icon = new ImageIcon("hw.jpg");
    setIconImage(icon.getImage());

    if (Integer.parseInt(Properties.getProperty("View Geschw", "1")) == 1) {
        Graphik_check_Geschwindigkeit.setSelected(true);
    } else {
        Graphik_check_Geschwindigkeit.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hhe", "1")) == 1) {
        Graphik_check_Hhe.setSelected(true);
    } else {
        Graphik_check_Hhe.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hf", "1")) == 1) {
        Graphik_check_HF.setSelected(true);
    } else {
        Graphik_check_HF.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Temp", "1")) == 1) {
        Graphik_check_Temp.setSelected(true);
    } else {
        Graphik_check_Temp.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigp", "1")) == 1) {
        Graphik_check_Steigung_p.setSelected(true);
    } else {
        Graphik_check_Steigung_p.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigm", "1")) == 1) {
        Graphik_check_Steigung_m.setSelected(true);
    } else {
        Graphik_check_Steigung_m.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View av_Geschw", "1")) == 1) {
        Graphik_check_av_Geschw.setSelected(true);
    } else {
        Graphik_check_av_Geschw.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Cadence", "1")) == 1) {
        Graphik_check_Cadence.setSelected(true);
    } else {
        Graphik_check_Cadence.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Schrittlnge", "1")) == 1) {
        Graphik_check_Schrittlnge.setSelected(true);
    } else {
        Graphik_check_Schrittlnge.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("ZeitStreckeAbstnde", "1")) == 1) {
        Graphik_check_Abstand.setSelected(true);
    } else {
        Graphik_check_Abstand.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("SummenHisto", "1")) == 1) {
        Summenhistogramm_Check.setSelected(true);
    } else {
        Summenhistogramm_Check.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("xy_Strecke", "1")) == 1) {
        Graphik_Radio_Strecke.setSelected(true);
        Graphik_Radio_Zeit.setSelected(false);
    } else {
        Graphik_Radio_Strecke.setSelected(false);
        Graphik_Radio_Zeit.setSelected(true);
    }

    //Buttons fr XY-Darstellung   (ber Strecke oder ber Zeit)
    X_Axis = new ButtonGroup();
    X_Axis.add(Graphik_Radio_Strecke);
    X_Axis.add(Graphik_Radio_Zeit);

    //Buttons fr Jahresbersicht
    bersicht = new ButtonGroup();
    bersicht.add(jRadioButton_jahresverlauf);
    bersicht.add(jRadioButton_monatsbersicht);

    Datenliste_Zeitabschnitt.addItem("nicht aktiv");
    Datenliste_Zeitabschnitt.addItem("vergangene Woche");
    Datenliste_Zeitabschnitt.addItem("vergangener Monat");
    Datenliste_Zeitabschnitt.addItem("vergangenes Jahr");
    Datenliste_Zeitabschnitt.addItem("Alles");

    if (Datentabelle.getRowCount() != 0) {
        Datentabelle.addRowSelectionInterval(0, 0);
        Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }
    //        if (Properties.getProperty("CommPort").equals("nocom")) {
    //            jMenuReceive.setEnabled(false);
    //        } else {
    //            jMenuReceive.setEnabled(true);
    //        }

    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());

    setFileChooserFont(chooser.getComponents());
    locmap = true;
    Map_Type.removeAllItems();
    Map_Type.addItem("OpenStreetMap");
    Map_Type.addItem("Virtual Earth Map");
    Map_Type.addItem("Virtual Earth Satelite");
    Map_Type.addItem("Virtual Earth Hybrid");
    locmap = false;
    //    ChangeModel();
}

From source file:dynamicrefactoring.interfaz.dynamic.DynamicExamplesTab.java

/**
 * Genera htmls mediante java2html para visualizar los ejemplos de la
 * refactorizacin en un navegador html./*ww w.ja v  a  2  s  . c om*/
 */
private void generarHTMLS() {
    // directorio de la refactorizacion
    String dirRefactoring = new File(refactoringDefinition.getExamplesAbsolutePath().get(0).getAfter())
            .getParent();

    // Cambiamos de extensin los ficheros .txt por .java para que puedan
    // ser interpretados
    // por java2HTML
    copyExampleFilesWithOtherExtension(".java");

    try {
        // redirijo la consola a un fichero .txt para que no salga las
        // trazas de la
        // biblioteca java2html.
        PrintStream out = new PrintStream(
                new FileOutputStream(dirRefactoring + File.separator + "consola.txt"));
        System.setOut(out);

        Java2HTML java2html = new Java2HTML();
        String[] dir = new String[1];
        dir[0] = dirRefactoring;
        java2html.setJavaDirectorySource(dir);
        java2html.setDestination(dirRefactoring);
        java2html.buildJava2HTML();

        out.close();

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

}

From source file:org.apache.geode.internal.cache.CacheServerLauncher.java

protected void restoreStdOut() {
    System.setErr(oldErr);
    System.setOut(oldOut);
}

From source file:org.dita.dost.AbstractIntegrationTest.java

/**
 * Run test conversion//from  w  ww.ja v  a 2 s. c o  m
 *
 * @param d          test source directory
 * @param transtypes list of transtypes to test
 * @return list of log messages
 * @throws Exception if conversion failed
 */
private List<TestListener.Message> run(final File d, final String[] transtypes, final File resDir)
        throws Exception {
    if (transtypes.length == 0) {
        return emptyList();
    }

    final File tempDir = new File(baseTempDir, d.getName() + File.separator + "temp");
    deleteDirectory(resDir);
    deleteDirectory(tempDir);

    final TestListener listener = new TestListener(System.out, System.err);
    final PrintStream savedErr = System.err;
    final PrintStream savedOut = System.out;
    try {
        final File buildFile = new File(d, "build.xml");
        final Project project = new Project();
        project.addBuildListener(listener);
        System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
        System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
        project.fireBuildStarted();
        project.init();
        for (final String transtype : transtypes) {
            if (canCompare.contains(transtype)) {
                project.setUserProperty("run." + transtype, "true");
                if (transtype.equals("pdf") || transtype.equals("pdf2")) {
                    project.setUserProperty("pdf.formatter", "fop");
                    project.setUserProperty("fop.formatter.output-format", "text/plain");
                }
            }
        }
        project.setUserProperty("generate-debug-attributes", "false");
        project.setUserProperty("preprocess.copy-generated-files.skip", "true");
        project.setUserProperty("ant.file", buildFile.getAbsolutePath());
        project.setUserProperty("ant.file.type", "file");
        project.setUserProperty("dita.dir", ditaDir.getAbsolutePath());
        project.setUserProperty("result.dir", resDir.getAbsolutePath());
        project.setUserProperty("temp.dir", tempDir.getAbsolutePath());
        project.setKeepGoingMode(false);
        ProjectHelper.configureProject(project, buildFile);
        final Vector<String> targets = new Vector<>();
        targets.addElement(project.getDefaultTarget());
        project.executeTargets(targets);

        assertEquals("Warn message count does not match expected", getMessageCount(project, "warn"),
                countMessages(listener.messages, Project.MSG_WARN));
        assertEquals("Error message count does not match expected", getMessageCount(project, "error"),
                countMessages(listener.messages, Project.MSG_ERR));
    } finally {
        System.setOut(savedOut);
        System.setErr(savedErr);
        return listener.messages;
    }
}

From source file:org.jkiss.dbeaver.core.application.DBeaverApplication.java

private void initDebugWriter() {
    File logPath = GeneralUtils.getMetadataFolder();
    File debugLogFile = new File(logPath, "dbeaver-debug.log"); //$NON-NLS-1$
    if (debugLogFile.exists()) {
        if (!debugLogFile.delete()) {
            System.err.println("Can't delete debug log file"); //$NON-NLS-1$
        }// w w w.  j  a  va2  s . c  o m
    }
    try {
        debugWriter = new FileOutputStream(debugLogFile);
        oldSystemOut = System.out;
        oldSystemErr = System.err;
        System.setOut(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemOut)));
        System.setErr(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemErr)));
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:org.apache.metron.dataloads.bulk.ElasticsearchDataPrunerTest.java

@Before
public void setUp() throws Exception {

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, Calendar.MARCH);
    calendar.set(Calendar.YEAR, 2016);
    calendar.set(Calendar.DATE, 31);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    testDate = calendar.getTime();//from w  ww  .  j  av  a 2s .c  o m

    when(indexClient.admin()).thenReturn(adminClient);
    when(adminClient.indices()).thenReturn(indicesAdminClient);
    when(deleteIndexRequestBuilder.request()).thenReturn(deleteIndexRequest);
    when(deleteIndexAction.actionGet()).thenReturn(deleteIndexResponse);

    File resourceFile = new File(TestConstants.SAMPLE_CONFIG_PATH);
    Path resourcePath = Paths.get(resourceFile.getCanonicalPath());

    configuration = new Configuration(resourcePath);

    outContent = new ByteArrayOutputStream();
    errContent = new ByteArrayOutputStream();

    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));

}

From source file:functionaltests.TagCommandsFunctTest.java

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

    runCli();// www. jav a2  s  .c o  m

    String out = this.capturedOutput.toString();
    System.setOut(stdOut);
    System.out.println("------------- testJobResultWithUnknownTag:");
    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:org.apache.maven.cli.CopyOfMavenCli.java

/**
 * configure logging/* www  .jav  a  2s  .c  o m*/
 */
private void logging(CliRequest cliRequest) {
    cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG);
    cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET);
    cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS);

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);

    if (cliRequest.debug) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.quiet) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }
    // else fall back to default log level specified in conf
    // see http://jira.codehaus.org/browse/MNG-2570

    if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE));
        logFile = resolveFile(logFile, cliRequest.workingDirectory);

        // redirect stdout and stderr to file
        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            //
            // Ignore
            //
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:com.cisco.dvbu.ps.deploytool.dao.wsapi.VCSWSDAOImpl.java

public void vcsExportCommand(String prefix, String arguments, String vcsIgnoreMessages, String propertyFile)
        throws CompositeException {

    String identifier = "VCSWSDAOImpl.vcsExportCommand"; // some unique identifier that characterizes this invocation.
    String actionName = "EXPORT";

    try {//from   w  ww .  ja  va 2  s  . co  m
        boolean preserveQuotes = false;
        boolean initArgsList = true;
        List<String> argsList = new ArrayList<String>();
        argsList = CommonUtils.parseArguments(argsList, initArgsList, arguments, preserveQuotes, propertyFile);
        String[] args = argsList.toArray(new String[0]);

        /*
         * 2014-02-14 (mtinius): Removed the PDTool Archive capability
         */
        //         ExportCommand.startCommand(null, null, args);
        /*
         * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because
         *                    it has System.out.println and System.exit commands.  Need to trap both.
         */
        String maskedargsList = CommonUtils.getArgumentListMasked(argsList);
        if (logger.isDebugEnabled()) {
            logger.debug(identifier + "(prefix, arguments, vcsIgnoreMessages, propertyFile).  prefix=" + prefix
                    + "  arguments=[" + maskedargsList + "]" + "  vcsIgnoreMessages=" + vcsIgnoreMessages
                    + "  propertyFile=" + propertyFile);
        }

        // Get the existing security manager
        SecurityManager sm = System.getSecurityManager();
        PrintStream originalOut = System.out;
        PrintStream originalErr = System.err;
        String command = "ExportCommand.startCommand";
        try {
            // Get the offset location of the java.policy file [offset from PDTool home].
            String javaPolicyOffset = CommonConstants.javaPolicy;
            String javaPolicyLocation = CommonUtils.extractVariable(prefix,
                    CommonUtils.getFileOrSystemPropertyValue(propertyFile, "PROJECT_HOME_PHYSICAL"),
                    propertyFile, true) + javaPolicyOffset;
            // Set the java security policy
            System.getProperties().setProperty("java.security.policy", javaPolicyLocation);

            // Create a new System.out Logger
            Logger exportLogger = Logger.getLogger(ExportCommand.class);
            System.setOut(new PrintStream(new LogOutputStream(exportLogger, Level.INFO)));
            System.setErr(new PrintStream(new LogOutputStream(exportLogger, Level.ERROR)));
            // Create a new security manager
            System.setSecurityManager(new NoExitSecurityManager());

            // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation.
            if (CommonUtils.isExecOperation()) {
                // Invoke the Composite native export command.
                ExportCommand.startCommand(null, null, args);
            } else {
                logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName
                        + "] WAS NOT PERFORMED.\n");
            }
        } catch (NoExitSecurityExceptionStatusNonZero nesesnz) {
            String error = identifier + ":: Exited with exception from System.exit(): " + command
                    + "(null, null, " + maskedargsList + ")";
            logger.error(error);
            throw new CompositeException(error);
        } catch (NoExitSecurityExceptionStatusZero nesezero) {
            if (logger.isDebugEnabled()) {
                logger.debug(identifier + ":: Exited successfully from System.exit(): " + command
                        + "(null, null, " + maskedargsList + ")");
            }
        } finally {
            System.setSecurityManager(sm);
            System.setOut(originalOut);
            System.setErr(originalErr);
        }

    } catch (Exception e) {
        if (resolveExecCommandLineError(prefix, e.getMessage().toString(), vcsIgnoreMessages)) {
            ApplicationException applicationException = new ApplicationException(
                    "ExportCommand execution returned an error=" + e.getMessage().toString());
            if (logger.isErrorEnabled()) {
                logger.error(applicationException);
            }
            throw applicationException;
        }
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java

public int doMain(AFCliRequest cliRequest, ClassWorld classWorld) {

    PrintStream originalOut = System.out;
    PrintStream originalErr = System.err;
    try {// w  w  w.ja v a2  s .  c om
        initialize(cliRequest);
        cli(cliRequest);
        logging(cliRequest);
        version(cliRequest);
        properties(cliRequest);
        reusableContainer = container(cliRequest, classWorld);
        commands(cliRequest);//ok
        configure(cliRequest);
        toolchains(cliRequest);
        populateRequest(cliRequest);
        repository(cliRequest);
        return execute(cliRequest);
    } catch (ExitException e) {
        //e.printStackTrace();
        e.getStackTrace();
        return e.exitCode;
    } catch (UnrecognizedOptionException e) {
        //e.printStackTrace();
        e.getStackTrace();
        return 1;
    } catch (BuildAbort e) {
        //e.printStackTrace();
        e.getStackTrace();
        AFCLIReportingUtils.showError(reusableSlf4jLogger, "ABORTED", e, cliRequest.isShowErrors());
        return 2;
    } catch (Exception e) {
        //e.printStackTrace();
        e.getStackTrace();
        AFCLIReportingUtils.showError(reusableSlf4jLogger, "Error executing Maven.", e,
                cliRequest.isShowErrors());

        return 1;
    } finally {
        System.setOut(originalOut);
        System.setErr(originalErr);
    }
}