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:ca.uqac.dim.mapreduce.ltl.LTLValidation.java

/**
 * Program entry point./*from w  w w.  j  ava  2  s.com*/
 * @param args Command-line arguments
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    // Define and process command line arguments
    Options options = new Options();
    HelpFormatter help_formatter = new HelpFormatter();
    Option opt;
    options.addOption("h", "help", false, "Show help");
    opt = OptionBuilder.withArgName("property").hasArg()
            .withDescription("Property to verify, enclosed in double quotes").create("p");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename").create("i");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg()
            .withDescription("Set verbosity level to x (default: 0 = quiet)").create("v");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("ParserType").hasArg().withDescription("Parser type (Dom or Sax)")
            .create("t");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("redirection").withArgName("x").hasArg()
            .withDescription("Set the redirection file for the System.out").create("r");
    options.addOption(opt);
    CommandLine c_line = parseCommandLine(options, args);

    String redirectionFile = "";

    //Contains a redirection file for the output
    if (c_line.hasOption("redirection")) {
        try {
            redirectionFile = c_line.getOptionValue("redirection");
            PrintStream ps;
            ps = new PrintStream(redirectionFile);
            System.setOut(ps);
        } catch (FileNotFoundException e) {
            System.out.println("Redirection error !!!");
            e.printStackTrace();
        }
    }

    if (!c_line.hasOption("p") || !c_line.hasOption("i") | c_line.hasOption("h")) {
        help_formatter.printHelp(app_name, options);
        System.exit(1);
    }
    assert c_line.hasOption("p");
    assert c_line.hasOption("i");
    String trace_filename = c_line.getOptionValue("i");
    String trace_format = getExtension(trace_filename);
    String property_str = c_line.getOptionValue("p");
    String ParserType = "";

    if (c_line.hasOption("t")) {
        ParserType = c_line.getOptionValue("t");
    } else {
        System.err.println("No Parser Type in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    if (c_line.hasOption("v"))
        m_verbosity = Integer.parseInt(c_line.getOptionValue("v"));

    // Obtain the property to verify and break into subformulas
    Operator property = null;
    try {
        int preset = Integer.parseInt(property_str);
        property = new Edoc2012Presets().property(preset);
    } catch (NumberFormatException e) {
        try {
            property = Operator.parseFromString(property_str);
        } catch (Operator.ParseException pe) {
            System.err.println("ERROR: parsing");
            System.exit(1);
        }
    }
    Set<Operator> subformulas = property.getSubformulas();

    // Initialize first collector depending on input file format
    int max_loops = property.getDepth();
    int max_tuples_total = 0, total_tuples_total = 0;
    long time_begin = System.nanoTime();
    TraceCollector initial_collector = null;
    {
        File in_file = new File(trace_filename);
        if (trace_format.compareToIgnoreCase(".txt") == 0) {
            initial_collector = new CharacterTraceCollector(in_file, subformulas);
        } else if (trace_format.compareToIgnoreCase(".xml") == 0) {
            if (ParserType.equals("Dom")) {
                initial_collector = new XmlDomTraceCollector(in_file, subformulas);
            } else if (ParserType.equals("Sax")) {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            } else {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            }
        }
    }
    if (initial_collector == null) {
        System.err.println("ERROR: unrecognized input format");
        System.exit(1);
    }

    // Start workflow
    int trace_len = initial_collector.getTraceLength();
    InCollector<Operator, LTLTupleValue> loop_collector = initial_collector;
    print(System.out, property.toString(), 2);
    print(System.out, loop_collector.toString(), 3);
    for (int i = 0; i < max_loops; i++) {
        print(System.out, "Loop " + i, 2);
        LTLSequentialWorkflow w = new LTLSequentialWorkflow(new LTLMapper(subformulas),
                new LTLReducer(subformulas, trace_len), loop_collector);
        loop_collector = w.run();
        max_tuples_total += w.getMaxTuples();
        total_tuples_total += w.getTotalTuples();

        if (m_verbosity >= 3) {
            print(System.out, loop_collector.toString(), 3);
        }

    }
    boolean result = getVerdict(loop_collector, property);
    long time_end = System.nanoTime();
    if (result)
        print(System.out, "Formula is true", 1);
    else
        print(System.out, "Formula is false", 1);

    long time_total = (time_end - time_begin) / 1000000;
    System.out.println(trace_len + "," + max_tuples_total + "," + total_tuples_total + "," + time_total);
}

From source file:com.denimgroup.threadfix.importer.cli.CommandLineMigration.java

public static void main(String[] args) {

    if (!check(args))
        return;/* w w  w .  j ava 2 s.c om*/

    try {
        String inputScript = args[0];
        String inputMySqlConfig = args[1];
        String outputScript = "import.sql";
        String outputMySqlConfigTemp = "jdbc_temp.properties";
        String errorLogFile = "error.log";
        String fixedSqlFile = "error_sql.sql";
        String errorLogAttemp1 = "error1.log";
        String infoLogFile = "info.log";
        String rollbackScript = "rollback.sql";

        deleteFile(outputScript);
        deleteFile(errorLogFile);
        deleteFile(errorLogFile);
        deleteFile(fixedSqlFile);
        deleteFile(errorLogAttemp1);
        deleteFile(infoLogFile);
        deleteFile(rollbackScript);

        PrintStream infoPrintStream = new PrintStream(new FileOutputStream(new File(infoLogFile)));
        System.setOut(infoPrintStream);

        long startTime = System.currentTimeMillis();

        copyFile(inputMySqlConfig, outputMySqlConfigTemp);

        LOGGER.info("Creating threadfix table in mySql database ...");
        ScriptRunner scriptRunner = SpringConfiguration.getContext().getBean(ScriptRunner.class);

        startTime = printTimeConsumed(startTime);
        convert(inputScript, outputScript);

        startTime = printTimeConsumed(startTime);

        PrintStream errPrintStream = new PrintStream(new FileOutputStream(new File(errorLogFile)));
        System.setErr(errPrintStream);

        LOGGER.info("Sending sql script to MySQL server ...");
        scriptRunner.run(outputScript, outputMySqlConfigTemp);

        long errorCount = scriptRunner.checkRunningAndFixStatements(errorLogFile, fixedSqlFile);
        long lastCount = errorCount + 1;
        int times = 1;
        int sameFixedSet = 0;

        // Repeat
        while (errorCount > 0) {
            //Flush error log screen to other file
            errPrintStream = new PrintStream(new FileOutputStream(new File(errorLogAttemp1)));
            System.setErr(errPrintStream);

            times += 1;

            if (errorCount == lastCount) {
                sameFixedSet++;
            } else {
                sameFixedSet = 0;
            }

            LOGGER.info("Found " + errorCount + " error statements. Sending fixed sql script to MySQL server "
                    + times + " times ...");
            scriptRunner.run(fixedSqlFile, outputMySqlConfigTemp);
            lastCount = errorCount;
            errorCount = scriptRunner.checkRunningAndFixStatements(errorLogAttemp1, fixedSqlFile);

            if (errorCount > lastCount || sameFixedSet > SAME_SET_TRY_LIMIT)
                break;
        }

        if (errorCount > 0) {
            LOGGER.error("After " + times + " of trying, still found errors in sql script. "
                    + "Please check error_sql.sql and error1.log for more details.");
            LOGGER.info("Do you want to keep data in MySQL, and then import manually error statements (y/n)? ");
            try (java.util.Scanner in = new java.util.Scanner(System.in)) {
                String answer = in.nextLine();
                if (!answer.equalsIgnoreCase("y")) {
                    rollbackData(scriptRunner, outputMySqlConfigTemp, rollbackScript);
                } else {
                    LOGGER.info(
                            "Data imported to MySQL, but still have some errors. Please check error_sql.sql and error1.log to import manually.");
                }

            }

        } else {
            printTimeConsumed(startTime);
            LOGGER.info("Migration successfully finished");
        }

        deleteFile(outputMySqlConfigTemp);

    } catch (Exception e) {
        LOGGER.error("Error: ", e);
    }
}

From source file:co.cask.cdap.data2.util.hbase.HBaseVersion.java

/**
 * Prints out the HBase {@link Version} enum value for the current version of HBase on the classpath.
 *//*  w  ww  . ja  v a2 s.c om*/
public static void main(String[] args) {
    // Suppress any output to stdout
    PrintStream stdout = System.out;
    System.setOut(new PrintStream(new NullOutputStream()));
    Version version = HBaseVersion.get();

    // Restore stdout
    System.setOut(stdout);
    System.out.println(version.getMajorVersion());

    if (args.length == 1 && "-v".equals(args[0])) {
        // Print versionString if verbose
        System.out.println("versionString=" + getVersionString());
    }
}

From source file:ca.uqac.dim.mapreduce.ltl.ParaLTLValidation.java

/**
 * Program entry point./*from   ww w  . j  a  v a  2s  . c  o  m*/
 * @param args Command-line arguments
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    // Define and process command line arguments
    Options options = new Options();
    HelpFormatter help_formatter = new HelpFormatter();
    Option opt;
    options.addOption("h", "help", false, "Show help");
    opt = OptionBuilder.withArgName("property").hasArg()
            .withDescription("Property to verify, enclosed in double quotes").create("p");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename").create("i");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("x").hasArg()
            .withDescription("Set verbosity level to x (default: 0 = quiet)").create("v");
    options.addOption(opt);
    opt = OptionBuilder.withArgName("ParserType").hasArg().withDescription("Parser type (Dom or Sax)")
            .create("t");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("redirection").withArgName("x").hasArg()
            .withDescription("Set the redirection file for the System.out").create("r");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("mapper").withArgName("x").hasArg()
            .withDescription("Set the number of mapper").create("m");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("reducer").withArgName("x").hasArg()
            .withDescription("Set the number of reducer").create("n");
    options.addOption(opt);
    CommandLine c_line = parseCommandLine(options, args);

    String redirectionFile = "";

    //Contains a redirection file for the output
    if (c_line.hasOption("redirection")) {
        try {
            redirectionFile = c_line.getOptionValue("redirection");
            PrintStream ps;
            ps = new PrintStream(redirectionFile);
            System.setOut(ps);
        } catch (FileNotFoundException e) {
            System.out.println("Redirection error !!!");
            e.printStackTrace();
        }
    }

    if (!c_line.hasOption("p") || !c_line.hasOption("i") | c_line.hasOption("h")) {
        help_formatter.printHelp(app_name, options);
        System.exit(1);
    }
    assert c_line.hasOption("p");
    assert c_line.hasOption("i");
    String trace_filename = c_line.getOptionValue("i");
    String trace_format = getExtension(trace_filename);
    String property_str = c_line.getOptionValue("p");
    String ParserType = "";
    int MapperNum = 0;
    int ReducerNum = 0;

    //Contains a parser type
    if (c_line.hasOption("t")) {
        ParserType = c_line.getOptionValue("t");
    } else {
        System.err.println("No Parser Type in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a mapper number
    if (c_line.hasOption("m")) {
        MapperNum = Integer.parseInt(c_line.getOptionValue("m"));
    } else {
        System.err.println("No Mapper Number in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a reducer number
    if (c_line.hasOption("n")) {
        ReducerNum = Integer.parseInt(c_line.getOptionValue("n"));
    } else {
        System.err.println("No Reducer Number in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    if (c_line.hasOption("v"))
        m_verbosity = Integer.parseInt(c_line.getOptionValue("v"));

    // Obtain the property to verify and break into subformulas
    Operator property = null;
    try {
        int preset = Integer.parseInt(property_str);
        property = new Edoc2012Presets().property(preset);
    } catch (NumberFormatException e) {
        try {
            property = Operator.parseFromString(property_str);
        } catch (Operator.ParseException pe) {
            System.err.println("ERROR: parsing");
            System.exit(1);
        }
    }
    Set<Operator> subformulas = property.getSubformulas();

    // Initialize first collector depending on input file format
    int max_loops = property.getDepth();
    int max_tuples_total = 0, total_tuples_total = 0;
    long time_begin = System.nanoTime();
    TraceCollector initial_collector = null;
    {
        File in_file = new File(trace_filename);
        if (trace_format.compareToIgnoreCase(".txt") == 0) {
            initial_collector = new CharacterTraceCollector(in_file, subformulas);
        } else if (trace_format.compareToIgnoreCase(".xml") == 0) {
            if (ParserType.equals("Dom")) {
                initial_collector = new XmlDomTraceCollector(in_file, subformulas);
            } else if (ParserType.equals("Sax")) {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            } else {
                initial_collector = new XmlSaxTraceCollector(in_file, subformulas);
            }
        }
    }
    if (initial_collector == null) {
        System.err.println("ERROR: unrecognized input format");
        System.exit(1);
    }

    // Start workflow
    int trace_len = initial_collector.getTraceLength();
    InCollector<Operator, LTLTupleValue> loop_collector = initial_collector;
    print(System.out, property.toString(), 2);
    print(System.out, loop_collector.toString(), 3);
    for (int i = 0; i < max_loops; i++) {
        print(System.out, "Loop " + i, 2);
        LTLParallelWorkflow w = new LTLParallelWorkflow(new LTLMapper(subformulas),
                new LTLReducer(subformulas, trace_len), loop_collector,
                new ResourceManager<Operator, LTLTupleValue>(MapperNum),
                new ResourceManager<Operator, LTLTupleValue>(ReducerNum));
        loop_collector = w.run();
        max_tuples_total += w.getMaxTuples();
        total_tuples_total += w.getTotalTuples();

        if (m_verbosity >= 3) {
            print(System.out, loop_collector.toString(), 3);
        }
    }
    boolean result = getVerdict(loop_collector, property);
    long time_end = System.nanoTime();
    if (result)
        print(System.out, "Formula is true", 1);
    else
        print(System.out, "Formula is false", 1);

    long time_total = (time_end - time_begin) / 1000000;
    System.out.println(trace_len + "," + max_tuples_total + "," + total_tuples_total + "," + time_total);
}

From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java

public static void main(String[] argv) {

    // Parse command line arguments
    CommandLine args = null;/*from www  . j  a v a  2s. co  m*/
    try {
        Parser p = new BasicParser();
        args = p.parse(cliOpts, argv);
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
    }

    // Check for help
    if (args.hasOption('?')) {
        printUsage();
        return;
    }

    // Runtime properties
    Properties props = System.getProperties();

    // Check for ~/.rabbitmqrc
    File userSettings = new File(System.getProperty("user.home"), ".rabbitmqrc");
    if (userSettings.exists()) {
        try {
            props.load(new FileInputStream(userSettings));
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }

    // Load Groovy builder file
    StringBuffer script = new StringBuffer();
    BufferedInputStream in = null;
    String filename = "<STDIN>";
    if (args.hasOption("f")) {
        filename = args.getOptionValue("f");
        try {
            in = new BufferedInputStream(new FileInputStream(filename));
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        in = new BufferedInputStream(System.in);
    }

    // Read script
    if (null != in) {
        byte[] buff = new byte[4096];
        try {
            for (int read = in.read(buff); read > -1;) {
                script.append(new String(buff, 0, read));
                read = in.read(buff);
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        System.err.println("No script file to evaluate...");
    }

    PrintStream stdout = System.out;
    PrintStream out = null;
    if (args.hasOption("o")) {
        try {
            out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true);
            System.setOut(out);
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        }
    }

    String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE")
            ? System.getenv("MQDSL_INCLUDE").split(String.valueOf(File.pathSeparatorChar))
            : new String[] { System.getenv("HOME") + File.separator + ".mqdsl.d" });

    try {
        // Setup RabbitMQ
        String username = (args.hasOption("U") ? args.getOptionValue("U")
                : props.getProperty("mq.user", "guest"));
        String password = (args.hasOption("P") ? args.getOptionValue("P")
                : props.getProperty("mq.password", "guest"));
        String virtualHost = (args.hasOption("v") ? args.getOptionValue("v")
                : props.getProperty("mq.virtualhost", "/"));
        String host = (args.hasOption("h") ? args.getOptionValue("h")
                : props.getProperty("mq.host", "localhost"));
        int port = Integer.parseInt(
                args.hasOption("p") ? args.getOptionValue("p") : props.getProperty("mq.port", "5672"));

        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host);
        connectionFactory.setPort(port);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        if (null != virtualHost) {
            connectionFactory.setVirtualHost(virtualHost);
        }

        // The DSL builder
        RabbitMQBuilder builder = new RabbitMQBuilder();
        builder.setConnectionFactory(connectionFactory);
        // Our execution environment
        Binding binding = new Binding(args.getArgs());
        binding.setVariable("mq", builder);
        String fileBaseName = filename.replaceAll("\\.groovy$", "");
        binding.setVariable("log",
                LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1)));
        if (null != out) {
            binding.setVariable("out", out);
        }

        // Include helper files
        GroovyShell shell = new GroovyShell(binding);
        for (String inc : includes) {
            File f = new File(inc);
            if (f.isDirectory()) {
                File[] files = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File file, String s) {
                        return s.endsWith(".groovy");
                    }
                });
                for (File incFile : files) {
                    run(incFile, shell, binding);
                }
            } else {
                run(f, shell, binding);
            }
        }

        run(script.toString(), shell, binding);

        while (builder.isActive()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
            }
        }

        if (null != out) {
            out.close();
            System.setOut(stdout);
        }

    } finally {
        System.exit(0);
    }
}

From source file:com.qawaa.gui.PointAnalysisGUI.java

/**
* Auto-generated main method to display this JFrame
*//* w  w w .  j a  v  a 2 s  .  com*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            PointAnalysisGUI inst = new PointAnalysisGUI();
            inst.setLocationRelativeTo(null);
            inst.setVisible(true);
            inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JFrame.setDefaultLookAndFeelDecorated(true);
            FlowLayout flowLayout = new FlowLayout();
            flowLayout.setAlignment(FlowLayout.LEFT);
            flowLayout.setAlignOnBaseline(true);
            inst.setTitle(PROGRAM_NAME + " [" + PROGRAM_VERSION + "] " + " - " + DefaultMessage.SOFT_NAME
                    + " - " + DefaultMessage.COMPANY_NAME);
            {
                consoleScrollPane = new JScrollPane();
                inst.getContentPane().add(consoleScrollPane, BorderLayout.CENTER);
                {
                    consolePane = new JEditorPane();
                    consoleScrollPane.setViewportView(consolePane);
                    consolePane.setText("");
                    setConsoleRight();
                    jConsole = new JConsole(System.out, consolePane);
                    System.setOut(jConsole);
                    System.setErr(jConsole);
                    consolePane.setEditable(false);
                    consolePane.addMouseListener(new MouseAdapter() {
                        /* (non-Javadoc)
                         * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent)
                         */
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON3) {
                                consolePane.add(consoleRight);
                                consoleRight.show(e.getComponent(), e.getX(), e.getY());
                            }
                        }
                    });
                }
            }
            {
                infoPanel = new JPanel();
                inst.getContentPane().add(infoPanel, BorderLayout.SOUTH);
                infoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 1, false));
                infoPanel.setPreferredSize(new Dimension(784, 30));
                infoPanel.setLayout(flowLayout);
                {
                    {
                        statusbar_count = new JTextPane();
                        infoPanel.add(statusbar_count);
                        statusbar_count
                                .setText(CONTEXT.getMessage("point.statusbar.count", null, Locale.CHINA));
                        statusbar_count.setBackground(null);
                        statusbar_count.setEditable(false);
                    }
                    {
                        statusbar_count_value = new JTextPane();
                        infoPanel.add(statusbar_count_value);
                        statusbar_count_value.setText(String.valueOf(SCAN_COUNT));
                        statusbar_count_value.setBackground(null);
                        statusbar_count_value.setEditable(false);
                        statusbar_count_value.setEnabled(false);
                    }
                    {
                        programPID = new JTextPane();
                        infoPanel.add(programPID);
                        programPID.setText("PID:");
                        programPID.setBackground(null);
                        programPID.setEditable(false);
                    }
                    {
                        programPID_value = new JTextPane();
                        infoPanel.add(programPID_value);
                        programPID_value.setText(JvmPid.getPID());
                        programPID_value.setBackground(null);
                        programPID_value.setEditable(false);
                        programPID_value.setEnabled(false);
                    }
                    {
                        memory = new JTextPane();
                        infoPanel.add(memory);
                        memory.setText(CONTEXT.getMessage("gobal.gui.memory", null, Locale.CHINA));
                        memory.setBackground(null);
                        memory.setEditable(false);
                    }
                    {
                        memory_value = new JTextPane();
                        infoPanel.add(memory_value);
                        memory_value.setText("0KB");
                        memory_value.setBackground(null);
                        memory_value.setEditable(false);
                        memory_value.setEnabled(false);
                        MemoryListener memory = new MemoryListener(memory_value);
                        memory.start();
                    }
                    {
                        runtime = new JTextPane();
                        infoPanel.add(runtime);
                        runtime.setText(CONTEXT.getMessage("gobal.gui.runtime", null, Locale.CHINA));
                        runtime.setBackground(null);
                        runtime.setEditable(false);
                    }
                    {
                        runtime_value = new JTextPane();
                        infoPanel.add(runtime_value);
                        runtime_value.setText("NULL");
                        runtime_value.setBackground(null);
                        runtime_value.setEditable(false);
                        runtime_value.setEnabled(false);
                    }
                }
            }
            {
                shortcut = new JPanel();
                inst.getContentPane().add(shortcut, BorderLayout.NORTH);
                shortcut.setSize(784, 35);
                shortcut.setPreferredSize(new Dimension(784, 35));
                shortcut.setBorder(new LineBorder(new Color(0, 0, 0), 1, false));
                shortcut.setLayout(new BorderLayout());
                {
                    eventText = new JTextPane();
                    shortcut.add(eventText, BorderLayout.WEST);
                    eventText.setText(CONTEXT.getMessage("point.event.name", null, Locale.CHINA) + ": ");
                    eventText.setEditable(false);
                    eventText.setEnabled(true);
                    eventText.setBackground(null);
                    eventText.setCaretColor(new Color(0, 0, 0));
                }
                {
                    eventTextField = new JTextField();
                    shortcut.add(eventTextField, BorderLayout.CENTER);
                    eventTextField.setSize(500, 25);
                    eventTextField.setText("");
                    eventTextField.setPreferredSize(new Dimension(500, 25));
                    eventTextField.setEditable(false);
                }
                {
                    submit = new JButton();
                    shortcut.add(submit, BorderLayout.EAST);
                    submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
                    submit.setSize(new Dimension(75, 25));
                    submit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                submitActionPerformed(evt);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
            }
        }
    });

}

From source file:edu.wpi.margrave.MCommunicator.java

public static void main(String[] args) {
    ArrayList<String> foo = new ArrayList<String>();

    Set<String> argsSet = new HashSet<String>();
    for (int ii = 0; ii < args.length; ii++) {
        argsSet.add(args[ii].toLowerCase());
    }/*from   w  ww. java  2  s.c o m*/

    if (argsSet.contains("-log")) {
        // parser is in racket now. instead, require -log switch for logging
        //MEnvironment.debugParser = true;
        bDoLogging = true;
    }

    if (argsSet.contains("-min")) {
        bMinimalModels = true;
    }

    // Re-direct all System.err input to our custom buffer
    // Uses Apache Commons IO for WriterOutputStream.
    System.setErr(new PrintStream(new WriterOutputStream(MEnvironment.errorWriter), true));

    // Re-direct all System.out input to our custom buffer.
    // (We have already saved System.out.)
    // This is useful in case we start getting GC messages from SAT4j.
    System.setOut(new PrintStream(new WriterOutputStream(MEnvironment.outWriter), true));

    initializeLog();
    writeToLog("\n\n");

    // Inform the caller that we are ready to receive commands
    sendReadyReply();

    while (true) {
        // Block until a command is received, handle it, and then return the result.
        handleXMLCommand(in);
    }

    // outLog will be closed as it goes out of scope
}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
* Auto-generated main method to display this JFrame
*//*from   w ww .  j a v  a  2s.  c  o m*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            EventWebScanGUI inst = new EventWebScanGUI();
            inst.setLocationRelativeTo(null);
            inst.setVisible(true);
            inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JFrame.setDefaultLookAndFeelDecorated(true);
            FlowLayout flowLayout = new FlowLayout();
            flowLayout.setAlignment(FlowLayout.LEFT);
            flowLayout.setAlignOnBaseline(true);
            inst.setTitle(PROGRAM_NAME + " [" + PROGRAM_VERSION + "] " + " - " + DefaultMessage.SOFT_NAME
                    + " - " + DefaultMessage.COMPANY_NAME);
            {
                consoleScrollPane = new JScrollPane();
                inst.getContentPane().add(consoleScrollPane, BorderLayout.CENTER);
                {
                    consolePane = new JEditorPane();
                    consoleScrollPane.setViewportView(consolePane);
                    consolePane.setText("");
                    setConsoleRight();
                    jConsole = new JConsole(System.out, consolePane);
                    System.setOut(jConsole);
                    System.setErr(jConsole);
                    consolePane.setEditable(false);
                    consolePane.addMouseListener(new MouseAdapter() {
                        /* (non-Javadoc)
                         * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent)
                         */
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON3) {
                                consolePane.add(consoleRight);
                                consoleRight.show(e.getComponent(), e.getX(), e.getY());
                            }
                        }
                    });
                }
            }
            {
                infoPanel = new JPanel();
                inst.getContentPane().add(infoPanel, BorderLayout.SOUTH);
                infoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 1, false));
                infoPanel.setPreferredSize(new Dimension(784, 30));
                infoPanel.setLayout(flowLayout);
                {
                    {
                        statusbar_count = new JTextPane();
                        infoPanel.add(statusbar_count);
                        statusbar_count.setText(
                                CONTEXT.getMessage("event.web.scan.statusbar.count", null, Locale.CHINA));
                        statusbar_count.setBackground(null);
                        statusbar_count.setEditable(false);
                    }
                    {
                        statusbar_count_value = new JTextPane();
                        infoPanel.add(statusbar_count_value);
                        statusbar_count_value.setText(String.valueOf(SCAN_COUNT));
                        statusbar_count_value.setBackground(null);
                        statusbar_count_value.setEditable(false);
                        statusbar_count_value.setEnabled(false);
                    }
                    {
                        programPID = new JTextPane();
                        infoPanel.add(programPID);
                        programPID.setText("PID:");
                        programPID.setBackground(null);
                        programPID.setEditable(false);
                    }
                    {
                        programPID_value = new JTextPane();
                        infoPanel.add(programPID_value);
                        programPID_value.setText(JvmPid.getPID());
                        programPID_value.setBackground(null);
                        programPID_value.setEditable(false);
                        programPID_value.setEnabled(false);
                    }
                    {
                        memory = new JTextPane();
                        infoPanel.add(memory);
                        memory.setText(CONTEXT.getMessage("gobal.gui.memory", null, Locale.CHINA));
                        memory.setBackground(null);
                        memory.setEditable(false);
                    }
                    {
                        memory_value = new JTextPane();
                        infoPanel.add(memory_value);
                        memory_value.setText("0KB");
                        memory_value.setBackground(null);
                        memory_value.setEditable(false);
                        memory_value.setEnabled(false);
                        MemoryListener memory = new MemoryListener(memory_value);
                        memory.start();
                    }
                    {
                        runtime = new JTextPane();
                        infoPanel.add(runtime);
                        runtime.setText(CONTEXT.getMessage("gobal.gui.runtime", null, Locale.CHINA));
                        runtime.setBackground(null);
                        runtime.setEditable(false);
                    }
                    {
                        runtime_value = new JTextPane();
                        infoPanel.add(runtime_value);
                        runtime_value.setText("NULL");
                        runtime_value.setBackground(null);
                        runtime_value.setEditable(false);
                        runtime_value.setEnabled(false);
                    }
                }
            }
            {
                shortcut = new JPanel();
                inst.getContentPane().add(shortcut, BorderLayout.NORTH);
                shortcut.setSize(784, 35);
                shortcut.setPreferredSize(new Dimension(784, 35));
                shortcut.setBorder(new LineBorder(new Color(0, 0, 0), 1, false));
                shortcut.setLayout(new BorderLayout());
                {
                    eventText = new JTextPane();
                    shortcut.add(eventText, BorderLayout.WEST);
                    eventText.setText(CONTEXT.getMessage("event.web.scan.name", null, Locale.CHINA) + ": ");
                    eventText.setEditable(false);
                    eventText.setEnabled(true);
                    eventText.setBackground(null);
                    eventText.setCaretColor(new Color(0, 0, 0));
                }
                {
                    eventTextField = new JTextField();
                    shortcut.add(eventTextField, BorderLayout.CENTER);
                    eventTextField.setSize(500, 25);
                    eventTextField.setText("");
                    eventTextField.setPreferredSize(new Dimension(500, 25));
                    eventTextField.setEditable(false);
                }
                {
                    submit = new JButton();
                    shortcut.add(submit, BorderLayout.EAST);
                    submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
                    submit.setSize(new Dimension(75, 25));
                    submit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                submitActionPerformed(evt);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
            }
        }
    });

}

From source file:org.apache.nifi.toolkit.zkmigrator.ZooKeeperMigratorMain.java

public static void main(String[] args) throws IOException {
    PrintStream output = System.out;
    System.setOut(System.err);

    final Options options = createOptions();
    final CommandLine commandLine;
    try {//from   w w w. ja  v a 2 s .  c  o m
        commandLine = new DefaultParser().parse(options, args);
        if (commandLine.hasOption(OPTION_ZK_MIGRATOR_HELP.getLongOpt())) {
            printUsage(null, options);
        } else {
            final String zookeeperUri = commandLine.getOptionValue(OPTION_ZK_ENDPOINT.getOpt());
            final Mode mode = commandLine.hasOption(OPTION_RECEIVE.getOpt()) ? Mode.READ : Mode.WRITE;
            final String filename = commandLine.getOptionValue(OPTION_FILE.getOpt());
            final String auth = commandLine.getOptionValue(OPTION_ZK_AUTH_INFO.getOpt());
            final String jaasFilename = commandLine.getOptionValue(OPTION_ZK_KRB_CONF_FILE.getOpt());
            final boolean ignoreSource = commandLine.hasOption(OPTION_IGNORE_SOURCE.getLongOpt());
            final AuthMode authMode;
            final byte[] authData;
            if (auth != null) {
                authMode = AuthMode.DIGEST;
                authData = auth.getBytes(StandardCharsets.UTF_8);
            } else {
                authData = null;
                if (!Strings.isNullOrEmpty(jaasFilename)) {
                    authMode = AuthMode.SASL;
                    System.setProperty("java.security.auth.login.config", jaasFilename);
                } else {
                    authMode = AuthMode.OPEN;
                }
            }
            final ZooKeeperMigrator zookeeperMigrator = new ZooKeeperMigrator(zookeeperUri);
            if (mode.equals(Mode.READ)) {
                try (OutputStream zkData = filename != null ? new FileOutputStream(Paths.get(filename).toFile())
                        : output) {
                    zookeeperMigrator.readZooKeeper(zkData, authMode, authData);
                }
            } else {
                try (InputStream zkData = filename != null ? new FileInputStream(Paths.get(filename).toFile())
                        : System.in) {
                    zookeeperMigrator.writeZooKeeper(zkData, authMode, authData, ignoreSource);
                }
            }
        }
    } catch (ParseException e) {
        printUsage(e.getLocalizedMessage(), options);
    } catch (IOException | KeeperException | InterruptedException | ExecutionException e) {
        throw new IOException(String.format("unable to perform operation: %s", e.getLocalizedMessage()), e);
    }
}

From source file:org.apache.parquet.tools.Main.java

public static void main(String[] args) {
    Main.out = System.out;/*w ww.j  ava2 s.  c om*/
    Main.err = System.err;

    PrintStream VoidStream = new PrintStream(new OutputStream() {
        @Override
        public void write(int b) throws IOException {
        }

        @Override
        public void write(byte[] b) throws IOException {
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
        }

        @Override
        public void flush() throws IOException {
        }

        @Override
        public void close() throws IOException {
        }
    });
    System.setOut(VoidStream);
    System.setErr(VoidStream);

    if (args.length == 0) {
        die("No command specified", true, null, null);
    }

    String name = args[0];
    if ("-h".equals(name) || "--help".equals(name)) {
        showUsage();
        System.exit(0);
    }

    Command command = Registry.getCommandByName(name);
    if (command == null) {
        die("Unknown command: " + name, true, null, null);
    }

    boolean debug = false;
    try {
        String[] cargs = Arrays.copyOfRange(args, 1, args.length);

        Options opts = mergeOptions(OPTIONS, command.getOptions());
        boolean extra = command.supportsExtraArgs();

        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(opts == null ? new Options() : opts, cargs, extra);
        if (cmd.hasOption('h')) {
            showUsage(name, command);
            System.exit(0);
        }

        if (cmd.hasOption("no-color")) {
            System.setProperty("DISABLE_COLORS", "true");
        }

        debug = cmd.hasOption("debug");

        command.execute(cmd);
    } catch (ParseException ex) {
        if (debug)
            ex.printStackTrace(Main.err);
        die("Invalid arguments: " + ex.getMessage(), true, name, command);
    } catch (Throwable th) {
        if (debug)
            th.printStackTrace(Main.err);
        die(th, false, name, command);
    }
}