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:ScanStreamTok.java

public static void main(String[] av) throws IOException {
    if (av.length == 0)
        new ScanStreamTok(new InputStreamReader(System.in)).process();
    else//  w ww  .j  a va 2s . c  o m
        for (int i = 0; i < av.length; i++)
            new ScanStreamTok(av[i]).process();
}

From source file:TerminalMonitor.java

static public void main(String args[]) {
    DriverPropertyInfo[] required;
    StringBuffer buffer = new StringBuffer();
    Properties props = new Properties();
    boolean connected = false;
    Driver driver;/*  ww  w.  j a  va2  s.  c  o  m*/
    String url;
    int line = 1; // Mark current input line

    if (args.length < 1) {
        System.out.println("Syntax: <java -Djdbc.drivers=DRIVER_NAME " + "TerminalMonitor JDBC_URL>");
        return;
    }
    url = args[0];
    // We have to get a reference to the driver so we can
    // find out what values to prompt the user for in order
    // to make a connection.
    try {
        driver = DriverManager.getDriver(url);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to find a driver for the specified " + "URL.");
        System.err.println("Make sure you passed the jdbc.drivers " + "property on the command line to specify "
                + "the driver to be used.");
        return;
    }
    try {
        required = driver.getPropertyInfo(url, props);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to get driver property information.");
        return;
    }
    input = new BufferedReader(new InputStreamReader(System.in));
    // some drivers do not implement this properly
    // if that is the case, prompt for user name and password
    try {
        if (required.length < 1) {
            props.put("user", prompt("user: "));
            props.put("password", prompt("password: "));
        } else {
            // for each required attribute in the driver property info
            // prompt the user for the value
            for (int i = 0; i < required.length; i++) {
                if (!required[i].required) {
                    continue;
                }
                props.put(required[i].name, prompt(required[i].name + ": "));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to read property info.");
        return;
    }
    // Make the connection.
    try {
        connection = DriverManager.getConnection(url, props);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to connect to the database.");
    }
    connected = true;
    System.out.println("Connected to " + url);
    // Enter into a user input loop
    while (connected) {
        String tmp, cmd;

        // Print a prompt
        if (line == 1) {
            System.out.print("TM > ");
        } else {
            System.out.print(line + " -> ");
        }
        System.out.flush();
        // Get the next line of input
        try {
            tmp = input.readLine();
        } catch (java.io.IOException e) {
            e.printStackTrace();
            return;
        }
        // Get rid of extra space in the command
        cmd = tmp.trim();
        // The user wants to commit pending transactions
        if (cmd.equals("commit")) {
            try {
                connection.commit();
                System.out.println("Commit successful.");
            } catch (SQLException e) {
                System.out.println("Error in commit: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The user wants to execute the current buffer
        else if (cmd.equals("go")) {
            if (!buffer.equals("")) {
                try {
                    executeStatement(buffer);
                } catch (SQLException e) {
                    System.out.println(e.getMessage());
                }
            }
            buffer = new StringBuffer();
            line = 1;
            continue;
        }
        // The user wants to quit
        else if (cmd.equals("quit")) {
            connected = false;
            continue;
        }
        // The user wants to clear the current buffer
        else if (cmd.equals("reset")) {
            buffer = new StringBuffer();
            line = 1;
            continue;
        }
        // The user wants to abort a pending transaction
        else if (cmd.equals("rollback")) {
            try {
                connection.rollback();
                System.out.println("Rollback successful.");
            } catch (SQLException e) {
                System.out.println("An error occurred during rollback: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The user wants version info
        else if (cmd.startsWith("show")) {
            DatabaseMetaData meta;

            try {
                meta = connection.getMetaData();
                cmd = cmd.substring(5, cmd.length()).trim();
                if (cmd.equals("version")) {
                    showVersion(meta);
                } else {
                    System.out.println("show version"); // Bad arg
                }
            } catch (SQLException e) {
                System.out.println("Failed to load meta data: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The input that is not a keyword should appended be to the buffer
        else {
            buffer.append(" " + tmp);
            line++;
            continue;
        }
    }
    try {
        connection.close();
    } catch (SQLException e) {
        System.out.println("Error closing connection: " + e.getMessage());
    }
    System.out.println("Connection closed.");
}

From source file:org.apache.olingo.odata2.fit.mapping.MappingTest.java

public static void main(final String[] args) {
    final TestServer server = new TestServer(ServletType.JAXRS_SERVLET);
    try {/*from  w  ww  .ja va2s .  co m*/
        server.startServer(MapFactory.class);
        System.out.println("Press any key to exit");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } catch (final IOException e) {
        e.printStackTrace(System.err);
    } finally {
        server.stopServer();
    }
}

From source file:com.tbodt.trp.TheRapidPermuter.java

/**
 * Main method for The Rapid Permuter./*  w  ww . j  a v  a  2 s.co m*/
 *
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    CommandProcessor.processCommand("\"\": remove(\"\") in([words])").ifPresent(x -> x.forEach(y -> {
    })); // to load all the classes we need

    try {
        cmd = new BasicParser().parse(options, args);
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        return;
    }

    if (Arrays.asList(cmd.getOptions()).contains(help)) { // another way commons cli is severely broken
        new HelpFormatter().printHelp("trp", options);
        return;
    }

    if (cmd.hasOption('c'))
        doCommand(cmd.getOptionValue('c'));
    else {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("trp> ");
        String input;
        while ((input = in.readLine()) != null) {
            if (input.equals("exit"))
                return; // exit
            doCommand(input);
            System.out.print("trp> ");
        }
    }
}

From source file:MediaInvoicer.java

public static void main(String[] args) throws IOException {
    MediaInvoicer mi = new MediaInvoicer(System.in);
    Invoice i = mi.getInvoice();/* w  w  w  .j a v a 2 s.c  o  m*/
    i.print(System.out);
}

From source file:ar.com.zauber.garfio.Main.java

/**
 * @param args arguments.//ww  w . ja v a2 s.c  o  m
 * @throws Exception on error 
 */
public static void main(final String[] args) throws Exception {
    if (args.length < 3) {
        System.err.printf("Usage: %s revision username config.properties [dry-run]", Main.class);
        System.exit(1);
    }
    final String revision = args[0];
    final String username = args[1];
    final String config = args[2];
    final boolean isDryRun = args.length >= 4 && "dry-run".equals(args[3]);

    final PropertiesConfiguration configuration = getConfiguration(config, username, revision);
    final GarfioService garfioService = new DefaultGarfioService(getConfigurationDAO(configuration),
            getErrorNotificator());

    final StringWriter writer = new StringWriter();
    IOUtil.copy(System.in, writer);

    if (isDryRun) {
        final List<String> errors = garfioService.dryrun(configuration.getRepositoryName(), username,
                writer.toString());

        for (String error : errors) {
            System.err.println(error);
        }

        System.exit(errors.isEmpty() ? 0 : 1);
    } else {
        garfioService.run(configuration.getRepositoryName(), revision, args[1], writer.toString());
    }
}

From source file:main.ReportGenerator.java

/**
 * Entry point for the program.//from  w w w .j  a  v  a 2 s.  com
 * Takes the variables as JSON on the standard input.
 * @param args Arguments from the command line.
 */
public static void main(String[] args) {
    CommandLine cmd = createOptions(args);

    GeneratorError result = GeneratorError.NO_ERROR;
    try {
        //Build the output name, by default ./output
        String directory = cmd.getOptionValue("output", "./");
        if (!directory.endsWith(File.separator))
            directory += File.separator;
        String filename = cmd.getOptionValue("name", "output");
        String output = directory + filename;

        //Get the JSON from file if given, or get it from the standard input.
        String jsonText = null;
        if (!cmd.hasOption("input")) {
            // Initializes the input with the standard input
            jsonText = IOUtils.toString(System.in, "UTF-8");
        } else // read the file
        {
            FileInputStream inputStream = new FileInputStream(cmd.getOptionValue("input"));
            try {
                jsonText = IOUtils.toString(inputStream);
            } finally {
                inputStream.close();
            }
        }

        //Build the report object
        Report report = new Report(jsonText, cmd.getOptionValue("template"), output);

        //Generate the document
        if (cmd.hasOption("all")) {
            new AllGenerator(report).generate();
        } else {
            if (cmd.hasOption("html"))
                new HTMLGenerator(report).generate();
            if (cmd.hasOption("pdf"))
                new PDFGenerator(report).generate();
            if (cmd.hasOption("doc"))
                new DocGenerator(report).generate();
        }

    } catch (IOException e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(GeneratorError.IO_ERROR.getCode());
    } catch (GeneratorException e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(e.getError().getCode());
    }
    System.exit(result.getCode());
}

From source file:test.node.TestNodeNARRunner.java

public static void main(String[] args) {
    try {//from   ww w  .ja v a  2s.c  o m

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Submit Job
        log.debug("Reading NAR");

        sw.start();

        GridArchive archive;
        archive = GridArchive.fromFile(new File("simpletestjob.nar"));

        log.debug("Submitting NAR");

        GridJobFuture future = (GridJobFuture) node.getJobSubmissionService().submitArchive(archive).values()
                .toArray()[0];

        try {
            log.info("RESULT : " + future.getResult());
        } catch (RemoteInvocationFailureException e) {
            e.getCause().printStackTrace();
        }

        sw.stop();
        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);

    } catch (GridArchiveException e) {
        log.fatal("GridArchiveException", e);
    } catch (GridExecutionException e) {
        log.fatal("Execution Failed", e);
    } catch (IOException e) {
        log.error("IOException", e);
    }

}

From source file:Fmt.java

/** If files present, format each, else format the standard input. */
public static void main(String[] av) throws IOException {
    if (av.length == 0)
        new Fmt(System.in).format();
    else/* w w  w. j  a v  a 2 s .com*/
        for (int i = 0; i < av.length; i++)
            new Fmt(av[i]).format();
}

From source file:Indent.java

public static void main(String[] av) {
    Indent c = new Indent();
    switch (av.length) {
    case 0:/*from  w  w  w .j a  v  a 2s  .  c  om*/
        c.process(new BufferedReader(new InputStreamReader(System.in)));
        break;
    default:
        for (int i = 0; i < av.length; i++)
            try {
                c.process(new BufferedReader(new FileReader(av[i])));
            } catch (FileNotFoundException e) {
                System.err.println(e);
            }
    }
}