Example usage for java.lang System in

List of usage examples for java.lang System in

Introduction

In this page you can find the example usage for java.lang System in.

Prototype

InputStream in

To view the source code for java.lang System in.

Click Source Link

Document

The "standard" input stream.

Usage

From source file:com.vinod.spring.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*  ww w .ja v a  2s  .  c  o m*/
 */
public static void main(final String... args) {

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n          Welcome to Spring Integration!                 "
                + "\n                                                         "
                + "\n    For more information please visit:                   "
                + "\n    http://www.springsource.org/spring-integration       "
                + "\n                                                         "
                + "\n=========================================================");
    }

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    SpringIntegrationUtils.displayDirectories(context);

    final Scanner scanner = new Scanner(System.in);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    while (!scanner.hasNext("q")) {
        //Do nothing unless user presses 'q' to quit.
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}

From source file:org.nuxeo.connect.tools.report.viewer.Viewer.java

public static void main(String[] varargs) throws IOException, ParseException {

    class Arguments {
        Options options = new Options()
                .addOption(Option.builder("i").longOpt("input").hasArg().argName("file")
                        .desc("report input file").build())
                .addOption(Option.builder("o").longOpt("output").hasArg().argName("file")
                        .desc("thread dump output file").build());
        final CommandLine commandline = new DefaultParser().parse(options, varargs);

        Arguments() throws ParseException {

        }/* w ww  .  j  ava2 s.  com*/

        InputStream input() throws IOException {
            if (!commandline.hasOption('i')) {
                return System.in;
            }
            return Files.newInputStream(Paths.get(commandline.getOptionValue('i')));
        }

        PrintStream output() throws IOException {
            if (!commandline.hasOption('o')) {
                return System.out;
            }
            return new PrintStream(commandline.getOptionValue('o'));
        }

    }

    Arguments arguments = new Arguments();
    final JsonFactory jsonFactory = new JsonFactory();
    PrintStream output = arguments.output();
    JsonParser parser = jsonFactory.createParser(arguments.input());
    ObjectMapper mapper = new ObjectMapper();
    while (!parser.isClosed() && parser.nextToken() != JsonToken.NOT_AVAILABLE) {
        String hostid = parser.nextFieldName();
        output.println(hostid);
        {
            parser.nextToken();
            while (parser.nextToken() == JsonToken.FIELD_NAME) {
                if ("mx-thread-dump".equals(parser.getCurrentName())) {
                    parser.nextToken(); // start mx-thread-dump report
                    while (parser.nextToken() == JsonToken.FIELD_NAME) {
                        if ("value".equals(parser.getCurrentName())) {
                            parser.nextToken();
                            printThreadDump(mapper.readTree(parser), output);
                        } else {
                            parser.nextToken();
                            parser.skipChildren();
                        }
                    }
                } else if ("mx-thread-deadlocked".equals(parser.getCurrentName())) {
                    parser.nextToken();
                    while (parser.nextToken() == JsonToken.FIELD_NAME) {
                        if ("value".equals(parser.getCurrentName())) {
                            if (parser.nextToken() == JsonToken.START_ARRAY) {
                                printThreadDeadlocked(mapper.readerFor(Long.class).readValue(parser), output);
                            }
                        } else {
                            parser.nextToken();
                            parser.skipChildren();
                        }
                    }
                } else if ("mx-thread-monitor-deadlocked".equals(parser.getCurrentName())) {
                    parser.nextToken();
                    while (parser.nextToken() == JsonToken.FIELD_NAME) {
                        if ("value".equals(parser.getCurrentName())) {
                            if (parser.nextToken() == JsonToken.START_ARRAY) {
                                printThreadMonitorDeadlocked(mapper.readerFor(Long.class).readValues(parser),
                                        output);
                            }
                        } else {
                            parser.nextToken();
                            parser.skipChildren();
                        }
                    }
                } else {
                    parser.nextToken();
                    parser.skipChildren();
                }
            }
        }
    }

}

From source file:mx.uaq.facturacion.enlace.system.EmailSystemTest.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args/*from ww  w  .j a v  a  2  s . co m*/
 *            - command line arguments
 */
public static void main(final String... args) {

    LOGGER.info(HORIZONTAL_LINE + "\n" + "\n          Welcome to Spring Integration!                 " + "\n"
            + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       " + "\n" + HORIZONTAL_LINE);

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:email-facturas.poller.xml", "classpath:facturacion-integration.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    LOGGER.info(HORIZONTAL_LINE + "\n" + "\n    Please press 'q + Enter' to quit the application.    " + "\n"
            + HORIZONTAL_LINE);

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

    }

    LOGGER.info("Exiting application...bye.");

    System.exit(0);
}

From source file:examples.ssh.RudimentaryPTY.java

public static void main(String... args) throws IOException {
    SSHClient ssh = new SSHClient();

    ssh.loadKnownHosts();/*  w ww  . j a v a2  s.  co m*/

    ssh.connect("localhost");

    Shell shell = null;

    try {

        ssh.authPublickey(System.getProperty("user.name"));

        Session session = ssh.startSession();
        session.allocateDefaultPTY();

        shell = session.startShell();

        new Pipe("stdout", shell.getInputStream(), System.out) //
                .bufSize(shell.getLocalMaxPacketSize()) //
                .start();

        new Pipe("stderr", shell.getErrorStream(), System.err) //
                .bufSize(shell.getLocalMaxPacketSize()) //
                .start();

        // Now make System.in act as stdin. To exit, hit Ctrl+D (since that results in an EOF on System.in)

        // This is kinda messy because java only allows console input after you hit return
        // But this is just an example... a GUI app could implement a proper PTY

        Pipe.pipe(System.in, shell.getOutputStream(), shell.getRemoteMaxPacketSize(), false);

    } finally {

        if (shell != null)
            shell.close();

        ssh.disconnect();
    }
}

From source file:edu.packt.neuralnet.som.Kohonen1DTest.java

public static void main(String[] args) {

    RandomNumberGenerator.seed = 0;//from   w w  w  .  ja va  2  s .co m

    int numberOfInputs = 2;
    int numberOfNeurons = 20;
    int numberOfPoints = 1000;

    double[][] rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, -100.0,
            100.0);

    for (int i = 0; i < numberOfPoints; i++) {
        rndDataSet[i][0] = i;
        rndDataSet[i][0] += RandomNumberGenerator.GenerateNext();
        rndDataSet[i][1] = Math.cos(i / 100.0) * 1000;
        rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 400;
    }

    Kohonen kn1 = new Kohonen(numberOfInputs, numberOfNeurons, new UniformInitialization(0.0, 1000.0), 1);

    NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2);

    CompetitiveLearning complrn = new CompetitiveLearning(kn1, neuralDataSet,
            LearningAlgorithm.LearningMode.ONLINE);
    complrn.show2DData = true;
    complrn.printTraining = true;
    complrn.setLearningRate(0.3);
    complrn.setMaxEpochs(10000);
    complrn.setReferenceEpoch(3000);
    try {
        String[] seriesNames = { "Training Data" };
        Paint[] seriesColor = { Color.WHITE };

        Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS);
        ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y"));
        frame.pack();
        frame.setVisible(true);

        complrn.setPlot2DFrame(frame);
        complrn.showPlot2DData();
        System.in.read();

        complrn.train();
    } catch (Exception ne) {

    }
}

From source file:com.genentech.chemistry.openEye.apps.SDFSubRMSD.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file oe-supported");
    opt.setRequired(true);/*ww w .j a va  2  s  .  com*/
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fragFile", true, "file with single 3d substructure query");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("isMDL", false,
            "if given the fragFile is suposed to be an mdl query file, query features are supported.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String fragFile = cmd.getOptionValue("fragFile");

    // read fragment
    OESubSearch ss;
    oemolistream ifs = new oemolistream(fragFile);
    OEMolBase mol;
    if (!cmd.hasOption("isMDL")) {
        mol = new OEGraphMol();
        oechem.OEReadMolecule(ifs, mol);
        ss = new OESubSearch(mol, OEExprOpts.AtomicNumber, OEExprOpts.BondOrder);
    } else {
        int aromodel = OEIFlavor.Generic.OEAroModelOpenEye;
        int qflavor = ifs.GetFlavor(ifs.GetFormat());
        ifs.SetFlavor(ifs.GetFormat(), (qflavor | aromodel));
        int opts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH;
        OEQMol qmol = new OEQMol();
        oechem.OEReadMDLQueryFile(ifs, qmol, opts);
        ss = new OESubSearch(qmol);
        mol = qmol;
    }

    double nSSatoms = mol.NumAtoms();
    double sssCoords[] = new double[mol.GetMaxAtomIdx() * 3];
    mol.GetCoords(sssCoords);
    mol.Clear();
    ifs.close();

    if (!ss.IsValid())
        throw new Error("Invalid query " + args[0]);

    ifs = new oemolistream(inFile);
    oemolostream ofs = new oemolostream(outFile);
    int count = 0;

    while (oechem.OEReadMolecule(ifs, mol)) {
        count++;
        double rmsd = Double.MAX_VALUE;
        double molCoords[] = new double[mol.GetMaxAtomIdx() * 3];
        mol.GetCoords(molCoords);

        for (OEMatchBase mb : ss.Match(mol, false)) {
            double r = 0;
            for (OEMatchPairAtom mp : mb.GetAtoms()) {
                OEAtomBase asss = mp.getPattern();
                double sx = sssCoords[asss.GetIdx() * 3];
                double sy = sssCoords[asss.GetIdx() * 3];
                double sz = sssCoords[asss.GetIdx() * 3];

                OEAtomBase amol = mp.getTarget();
                double mx = molCoords[amol.GetIdx() * 3];
                double my = molCoords[amol.GetIdx() * 3];
                double mz = molCoords[amol.GetIdx() * 3];

                r += Math.sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my) + (sz - mz) * (sz - mz));
            }
            r /= nSSatoms;
            rmsd = Math.min(rmsd, r);
        }

        if (rmsd != Double.MAX_VALUE)
            oechem.OESetSDData(mol, "SSSrmsd", String.format("%.3f", rmsd));

        oechem.OEWriteMolecule(ofs, mol);
        mol.Clear();
    }

    ifs.close();
    ofs.close();

    mol.delete();
    ss.delete();
}

From source file:com.game.GameLauncherApplication.java

public static void main(String[] args) throws Exception {
    // System.exit is common for Batch applications since the exit code can be used to
    // drive a workflow
    //      System.exit(SpringApplication.exit(SpringApplication.run(
    //            SampleBatchApplication.class, args)));

    String s = "Y";
    while ("Y".equalsIgnoreCase(s.trim())) {
        ticTacToeGame.startGame();//from   w  w  w . j  av  a2 s. c o  m
        System.out.println(" Do you want to play more to Play more enter Y ");
        BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
        s = BR.readLine();
        if (s != null && !s.isEmpty()) {
            s = s.trim();
        }

    }

}

From source file:Undent.java

public static void main(String[] av) {
    Undent c = new Undent();
    if (av.length == 0)
        c.process(new BufferedReader(new InputStreamReader(System.in)));
    else//from www.  ja  va 2s  . c  o  m
        for (int i = 0; i < av.length; i++) {
            try {
                c.process(new BufferedReader(new FileReader(av[i])));
            } catch (FileNotFoundException e) {
                System.err.println(e);
            }
        }
}

From source file:Timer0.java

public static void main(String[] argv) throws IOException {
    //+//w  w  w .  j a  v a  2  s.  c  o  m
    long t0, t1;
    System.out.println("Press return when ready");
    t0 = System.currentTimeMillis();
    int b;
    do {
        b = System.in.read();
    } while (b != '\r' && b != '\n');
    t1 = System.currentTimeMillis();
    double deltaT = t1 - t0;
    System.out.println("You took " + DecimalFormat.getInstance().format(deltaT / 1000.) + " seconds.");
    //-
}

From source file:com.cjtotten.example.si.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from www .j ava  2 s.c o  m*/
 */
public static void main(final String... args) {

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n          Welcome to Spring Integration!                 "
                + "\n                                                         "
                + "\n    For more information please visit:                   "
                + "\n    http://www.springsource.org/spring-integration       "
                + "\n                                                         "
                + "\n=========================================================");
    }

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final StringConversionService service = context.getBean(StringConversionService.class);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    System.out.print("Please enter a string and press <enter>: ");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

        try {

            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));

        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

        System.out.print("Please enter a string and press <enter>:");

    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}