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

public static String readLine() {
    StringBuffer response = new StringBuffer();
    try {//from   w  ww  . j a  v  a  2  s  .  com
        BufferedInputStream buff = new BufferedInputStream(System.in);
        int in = 0;
        char inChar;
        do {
            in = buff.read();
            inChar = (char) in;
            if ((in != -1) & (in != '\n') & (in != '\r')) {
                response.append(inChar);
            }
        } while ((in != -1) & (inChar != '\n') & (in != '\r'));
        buff.close();
        return response.toString();
    } catch (IOException e) {
        System.out.println("Exception: " + e.getMessage());
        return null;
    }
}

From source file:it.unipd.dei.ims.falcon.CmdLine.java

public static void main(String[] args) {

    // last argument is always index path
    Options options = new Options();
    // one of these actions has to be specified
    OptionGroup actionGroup = new OptionGroup();
    actionGroup.addOption(new Option("i", true, "perform indexing")); // if dir, all files, else only one file
    actionGroup.addOption(new Option("q", true, "perform a single query"));
    actionGroup.addOption(new Option("b", false, "perform a query batch (read from stdin)"));
    actionGroup.setRequired(true);//  w  w w  .  ja v a 2s. c  o  m
    options.addOptionGroup(actionGroup);

    // other options
    options.addOption(new Option("l", "segment-length", true, "length of a segment (# of chroma vectors)"));
    options.addOption(
            new Option("o", "segment-overlap", true, "overlap portion of a segment (# of chroma vectors)"));
    options.addOption(new Option("Q", "quantization-level", true, "quantization level for chroma vectors"));
    options.addOption(new Option("k", "min-kurtosis", true, "minimum kurtosis for indexing chroma vectors"));
    options.addOption(new Option("s", "sub-sampling", true, "sub-sampling of chroma features"));
    options.addOption(new Option("v", "verbose", false, "verbose output (including timing info)"));
    options.addOption(new Option("T", "transposition-estimator-strategy", true,
            "parametrization for the transposition estimator strategy"));
    options.addOption(new Option("t", "n-transp", true,
            "number of transposition; if not specified, no transposition is performed"));
    options.addOption(new Option("f", "force-transp", true, "force transposition by an amount of semitones"));
    options.addOption(new Option("p", "pruning", false,
            "enable query pruning; if -P is unspecified, use default strategy"));
    options.addOption(new Option("P", "pruning-custom", true, "custom query pruning strategy"));

    // parse
    HelpFormatter formatter = new HelpFormatter();
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
        if (cmd.getArgs().length != 1)
            throw new ParseException("no index path was specified");
    } catch (ParseException ex) {
        System.err.println("ERROR - parsing command line:");
        System.err.println(ex.getMessage());
        formatter.printHelp("falcon -{i,q,b} [options] index_path", options);
        return;
    }

    // default values
    final float[] DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY = new float[] { 0.65192807f, 0.0f, 0.0f, 0.0f,
            0.3532628f, 0.4997167f, 0.0f, 0.41703504f, 0.0f, 0.16297342f, 0.0f, 0.0f };
    final String DEFAULT_QUERY_PRUNING_STRATEGY = "ntf:0.340765*[0.001694,0.995720];ndf:0.344143*[0.007224,0.997113];"
            + "ncf:0.338766*[0.001601,0.995038];nmf:0.331577*[0.002352,0.997884];"; // TODO not the final one

    int hashes_per_segment = Integer.parseInt(cmd.getOptionValue("l", "150"));
    int overlap_per_segment = Integer.parseInt(cmd.getOptionValue("o", "50"));
    int nranks = Integer.parseInt(cmd.getOptionValue("Q", "3"));
    int subsampling = Integer.parseInt(cmd.getOptionValue("s", "1"));
    double minkurtosis = Float.parseFloat(cmd.getOptionValue("k", "-100."));
    boolean verbose = cmd.hasOption("v");
    int ntransp = Integer.parseInt(cmd.getOptionValue("t", "1"));
    TranspositionEstimator tpe = null;
    if (cmd.hasOption("t")) {
        if (cmd.hasOption("T")) {
            // TODO this if branch is yet to test
            Pattern p = Pattern.compile("\\d\\.\\d*");
            LinkedList<Double> tokens = new LinkedList<Double>();
            Matcher m = p.matcher(cmd.getOptionValue("T"));
            while (m.find())
                tokens.addLast(new Double(cmd.getOptionValue("T").substring(m.start(), m.end())));
            float[] strategy = new float[tokens.size()];
            if (strategy.length != 12) {
                System.err.println("invalid transposition estimator strategy");
                System.exit(1);
            }
            for (int i = 0; i < strategy.length; i++)
                strategy[i] = new Float(tokens.pollFirst());
        } else {
            tpe = new TranspositionEstimator(DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY);
        }
    } else if (cmd.hasOption("f")) {
        int[] transps = parseIntArray(cmd.getOptionValue("f"));
        tpe = new ForcedTranspositionEstimator(transps);
        ntransp = transps.length;
    }
    QueryPruningStrategy qpe = null;
    if (cmd.hasOption("p")) {
        if (cmd.hasOption("P")) {
            qpe = new StaticQueryPruningStrategy(cmd.getOptionValue("P"));
        } else {
            qpe = new StaticQueryPruningStrategy(DEFAULT_QUERY_PRUNING_STRATEGY);
        }
    }

    // action
    if (cmd.hasOption("i")) {
        try {
            Indexing.index(new File(cmd.getOptionValue("i")), new File(cmd.getArgs()[0]), hashes_per_segment,
                    overlap_per_segment, subsampling, nranks, minkurtosis, tpe, verbose);
        } catch (IndexingException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (cmd.hasOption("q")) {
        String queryfilepath = cmd.getOptionValue("q");
        doQuery(cmd, queryfilepath, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp,
                minkurtosis, qpe, verbose);
    }
    if (cmd.hasOption("b")) {
        try {
            long starttime = System.currentTimeMillis();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String line = null;
            while ((line = in.readLine()) != null && !line.trim().isEmpty())
                doQuery(cmd, line, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp,
                        minkurtosis, qpe, verbose);
            in.close();
            long endtime = System.currentTimeMillis();
            System.out.println(String.format("total time: %ds", (endtime - starttime) / 1000));
        } catch (IOException ex) {
            Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:Main.java

public static void waitHere(String msg) {
    System.out.println("");
    System.out.println(msg);//from   ww w  . j av a  2 s .c  o  m
    if (canWait) {
        try {
            System.in.read();
        } catch (Exception e) {
        } // Ignore any errors while reading.
        try {
            System.in.read();
        } catch (Exception e) {
        } // Ignore any errors while reading.
    }
}

From source file:Main.java

public static String readInputTextLine(String prompt) {
    if (prompt != null) {
        System.out.print(prompt + ": ");
    }//from   w w w  .  j av a2s .  c o m
    BufferedReader lineOfText = new BufferedReader(new InputStreamReader(System.in));
    String textLine = null;
    try {
        textLine = lineOfText.readLine();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return textLine;
}

From source file:Main.java

public static String readStringFromStdin(String message) throws Exception {
    System.out.print(message);// w  w w . ja va 2  s  . c  o  m
    System.out.flush();
    System.in.skip(System.in.available());
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    return reader.readLine().trim();
}

From source file:Main.java

public static ArrayList<String> getInput() {
    ArrayList<String> result = new ArrayList<String>(10);
    String line;/*from  w  w w. j  a  v  a 2 s  .co m*/
    try {
        line = new BufferedReader(new InputStreamReader(System.in)).readLine();
        if (line != null) {
            StringTokenizer st = new StringTokenizer(line);
            while (st.hasMoreTokens())
                result.add(st.nextToken());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

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

/**
 * @param args//from   www  .j ava 2s.c o  m
 */
public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option(OPT_INFILE, true,
            "input file oe-supported Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_ESTATE_COUNT, false, "Output the the counts (occurrence) for each E-state atom group."
            + " E-state counts will be output if no output option is specified");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_ESTATE_SUM, false, "Output the sum of the E-state indices for each E-state atom group"
            + " in addition to the output of the" + " E-state atom groups.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_ESTATE_SYMBOL, false, "Output the E-state atom group symbol");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_UNASSIGNED_ATOMS, false,
            "Output atoms in the given molecules that" + " could not be assigned to an E-state atom group");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_UNASSIGNED_COUNT, false, "Output the number of atoms in the given molecules that"
            + " could not be assigned to an E-state atom group");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_ESTATE_INDICE, false,
            "Output the E-state indice of all atoms in the given molecule" + " in one field.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_SMARTS, true, "Description of the group of interest. If specified, the"
            + " E-state indice of atoms matching the SMARTS are output" + " in separated fields.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(OPT_PRINT_DETAILS, false, "Output the details of the calculation to stderr");
    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(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);
    String smarts = cmd.getOptionValue(OPT_SMARTS);
    boolean outputESIndex = cmd.hasOption(OPT_ESTATE_INDICE);
    boolean outputESCount = cmd.hasOption(OPT_ESTATE_COUNT);
    boolean outputESSum = cmd.hasOption(OPT_ESTATE_SUM);
    boolean outputESSymbol = cmd.hasOption(OPT_ESTATE_SYMBOL);
    boolean outputUnkCount = cmd.hasOption(OPT_UNASSIGNED_COUNT);
    boolean outputUnkAtoms = cmd.hasOption(OPT_UNASSIGNED_ATOMS);
    boolean printDetails = cmd.hasOption(OPT_PRINT_DETAILS);
    SDFEStateCalculator calculator = new SDFEStateCalculator(outFile);

    if (!outputESCount && !outputESSum && !outputUnkCount && !outputESSymbol && !outputESIndex
            && (smarts == null || smarts.length() == 0))
        outputESCount = true;

    try {
        calculator.prepare(outputESCount, outputESSum, outputESSymbol, outputUnkCount, outputUnkAtoms,
                outputESIndex, smarts, printDetails);
        calculator.run(inFile);
    } finally {
        calculator.close();
    }
}

From source file:org.craftercms.profile.utils.AccessTokenManagerCli.java

public static void main(String... args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_PATH);
    AccessTokenRepository repository = context.getBean(AccessTokenRepository.class);
    ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter stdOut = new PrintWriter(System.out);
    AccessTokenManagerCli cli = new AccessTokenManagerCli(stdIn, stdOut, repository, objectMapper);

    cli.run(args);//  ww  w  .j  av  a2  s . c  o  m
}

From source file:magixcel.Main.java

private static void setup() {
    Scanner s = new Scanner(System.in);
    boolean doContinue = false;

    //        Intro
    printLogo();/* w w  w.  j  ava 2  s .  c om*/
    System.out.println("Welcome to MagiXcel");
    System.out.println("Current encoding is " + Charset.defaultCharset());

    //        Table name
    while (!doContinue) {
        System.out.println("Type your desired table name:");
        if (s.hasNextLine()) {
            Table.setTableName(s.nextLine());
        }

        doContinue = isThisOk(s);
    }
    doContinue = false;

    //        File path
    String path = "";
    while (!doContinue) {
        System.out.println("Enter FULL path of .csv or .txt file you wish to convert");
        if (s.hasNextLine()) {
            path = StringEscapeUtils.escapeJava(s.nextLine());
        }
        FileMan.setPath(path);
        if (FileMan.currentPathIsValid()) {
            doContinue = isThisOk(s);
        } else {
            System.out.println("ERROR: Invalid Path");
            doContinue = false;
        }

    }
    doContinue = false;

    //        File setup
    FileMan.getLinesFromFile();
    Table.setColumnNames(FileMan.takeFirstRow());
    FileMan.addRowsToTable();

    //        Choose output mode
    System.out.println("Choose output mode:");
    OutputFormat.printOutputOptionsNumbered();
    int selectedOption = -1;
    while (!doContinue) {
        if (s.hasNextLine()) {
            selectedOption = Integer.parseInt(s.nextLine());
        }
        doContinue = OutputFormat.chooseOption(selectedOption, s);
    }

    doContinue = false;
    OutputFormat.format();

    FileMan.writeToFile();

    System.out.println("Thank you for using MagiXcel!");
    System.out.println("Press Enter to exit");
    s.nextLine();
    s.close();

}

From source file:it.unimi.di.big.mg4j.document.WarcDocumentSequence.java

public static void main(String[] args) throws Exception {

    SimpleJSAP jsap = new SimpleJSAP(WarcDocumentSequence.class.getName(),
            "Saves a serialised Warc document sequence based on a set of file names.",
            new Parameter[] {
                    new FlaggedOption("factory", JSAP.CLASS_PARSER, IdentityDocumentFactory.class.getName(),
                            JSAP.NOT_REQUIRED, 'f', "factory",
                            "A document factory with a standard constructor."),
                    new FlaggedOption("property", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'p',
                            "property", "A 'key=value' specification, or the name of a property file")
                                    .setAllowMultipleDeclarations(true),
                    new Switch("gzip", 'z', "gzip",
                            "Expect gzip-ed WARC content (files should end in .warc.gz)."),
                    new FlaggedOption("bufferSize", JSAP.INTSIZE_PARSER, DEFAULT_BUFFER_SIZE, JSAP.NOT_REQUIRED,
                            'b', "buffer-size", "The size of an I/O buffer."),
                    new UnflaggedOption("sequence", JSAP.STRING_PARSER, JSAP.REQUIRED,
                            "The filename for the serialized sequence."),
                    new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            JSAP.GREEDY,
                            "A list of basename files that will be indexed. If missing, a list of files will be read from standard input.") });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
        System.exit(1);// w w  w.  j  a  v  a2  s.c  om

    final DocumentFactory factory = PropertyBasedDocumentFactory.getInstance(jsapResult.getClass("factory"),
            jsapResult.getStringArray("property"));
    final boolean isGZipped = jsapResult.getBoolean("gzip");

    String[] file = jsapResult.getStringArray("basename");
    if (file.length == 0)
        file = IOUtils.readLines(System.in).toArray(new String[0]);
    if (file.length == 0)
        LOGGER.warn("Empty fileset");

    BinIO.storeObject(new WarcDocumentSequence(file, factory, isGZipped, jsapResult.getInt("bufferSize")),
            jsapResult.getString("sequence"));
}