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:net.chrislongo.hls.Main.java

public static void main(String[] args) {
    CommandLine commandLine = parseCommandLine(args);
    String[] commandLineArgs = commandLine.getArgs();

    try {/*from w  w w.  j a v  a2 s. c o  m*/
        String playlistUrl = commandLineArgs[0];
        String outFile = null;
        String key = null;

        if (commandLine.hasOption(OPT_OUT_FILE)) {
            outFile = commandLine.getOptionValue(OPT_OUT_FILE);

            File file = new File(outFile);

            if (file.exists()) {
                if (!commandLine.hasOption(OPT_OVERWRITE)) {
                    System.out.printf("File '%s' already exists. Overwrite? [y/N] ", outFile);

                    int ch = System.in.read();

                    if (!(ch == 'y' || ch == 'Y')) {
                        System.exit(0);
                    }
                }

                file.delete();
            }
        }

        if (commandLine.hasOption(OPT_KEY))
            key = commandLine.getOptionValue(OPT_KEY);

        PlaylistDownloader downloader = new PlaylistDownloader(playlistUrl);

        if (commandLine.hasOption(OPT_SILENT)) {
            System.setOut(new PrintStream(new OutputStream() {
                public void close() {
                }

                public void flush() {
                }

                public void write(byte[] b) {
                }

                public void write(byte[] b, int off, int len) {
                }

                public void write(int b) {
                }
            }));
        }

        downloader.download(outFile, key);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:android.example.hlsmerge.crypto.Main.java

public static void main(String[] args) {
    CommandLine commandLine = parseCommandLine(args);
    String[] commandLineArgs = commandLine.getArgs();

    try {/*  w  ww .j a v  a 2  s . c  o m*/
        String playlistUrl = commandLineArgs[0];
        String outFile = null;
        String key = null;

        if (commandLine.hasOption(OPT_OUT_FILE)) {
            outFile = commandLine.getOptionValue(OPT_OUT_FILE);

            File file = new File(outFile);

            if (file.exists()) {
                if (!commandLine.hasOption(OPT_OVERWRITE)) {
                    System.out.printf("File '%s' already exists. Overwrite? [y/N] ", outFile);

                    int ch = System.in.read();

                    if (!(ch == 'y' || ch == 'Y')) {
                        System.exit(0);
                    }
                }

                file.delete();
            }
        }

        if (commandLine.hasOption(OPT_KEY))
            key = commandLine.getOptionValue(OPT_KEY);

        PlaylistDownloader downloader = new PlaylistDownloader(playlistUrl, null);

        if (commandLine.hasOption(OPT_SILENT)) {
            System.setOut(new PrintStream(new OutputStream() {
                public void close() {
                }

                public void flush() {
                }

                public void write(byte[] b) {
                }

                public void write(byte[] b, int off, int len) {
                }

                public void write(int b) {
                }
            }));
        }

        downloader.download(outFile, key);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.precioustech.fxtrading.oanda.restapi.marketdata.historic.HistoricMarketDataOnDemandDemo.java

public static void main(String[] args) throws Exception {
    usage(args);//from  w  w  w  .j a va2 s  . c  o  m
    final String url = args[0];
    final String accessToken = args[1];
    HistoricMarketDataProvider<String> historicMarketDataProvider = new OandaHistoricMarketDataProvider(url,
            accessToken);
    Scanner scanner = new Scanner(System.in);
    scanner.useDelimiter(System.getProperty("line.separator"));
    System.out.print("Instrument" + TradingConstants.COLON);
    String ccyPair = scanner.next();
    TradeableInstrument<String> instrument = new TradeableInstrument<>(ccyPair.toUpperCase());

    System.out.print(
            "Granularity" + ArrayUtils.toString(CandleStickGranularity.values()) + TradingConstants.COLON);
    CandleStickGranularity granularity = CandleStickGranularity.valueOf(scanner.next().toUpperCase());
    System.out.print("Time Range Candles(t) or Last N Candles(n)?:");
    String choice = scanner.next();

    List<CandleStick<String>> candles = null;
    if ("t".equalsIgnoreCase(choice)) {
        System.out.print("Start Time(" + datefmtLabel + ")" + TradingConstants.COLON);
        String startStr = scanner.next();
        Date startDt = sdf.parse(startStr);
        System.out.print("  End Time(" + datefmtLabel + ")" + TradingConstants.COLON);
        String endStr = scanner.next();
        Date endDt = sdf.parse(endStr);
        candles = historicMarketDataProvider.getCandleSticks(instrument, granularity,
                new DateTime(startDt.getTime()), new DateTime(endDt.getTime()));
    } else {
        System.out.print("Last how many candles?" + TradingConstants.COLON);
        int n = scanner.nextInt();
        candles = historicMarketDataProvider.getCandleSticks(instrument, granularity, n);
    }
    System.out.println(center("Time", timeColLen) + center("Open", priceColLen) + center("Close", priceColLen)
            + center("High", priceColLen) + center("Low", priceColLen));
    System.out.println(repeat("=", timeColLen + priceColLen * 4));
    for (CandleStick<String> candle : candles) {
        System.out.println(center(sdf.format(candle.getEventDate().toDate()), timeColLen)
                + formatPrice(candle.getOpenPrice()) + formatPrice(candle.getClosePrice())
                + formatPrice(candle.getHighPrice()) + formatPrice(candle.getLowPrice()));
    }
    scanner.close();
}

From source file:com.xiangzhurui.util.email.SMTPMail.java

public static void main(String[] args) {
    String sender, recipient, subject, filename, server, cc;
    List<String> ccList = new ArrayList<String>();
    BufferedReader stdin;/* w  w  w  . j a  va2 s. com*/
    FileReader fileReader = null;
    Writer writer;
    SimpleSMTPHeader header;
    SMTPClient client;

    if (args.length < 1) {
        System.err.println("Usage: mail smtpserver");
        System.exit(1);
    }

    server = args[0];

    stdin = new BufferedReader(new InputStreamReader(System.in));

    try {
        System.out.print("From: ");
        System.out.flush();

        sender = stdin.readLine();

        System.out.print("To: ");
        System.out.flush();

        recipient = stdin.readLine();

        System.out.print("Subject: ");
        System.out.flush();

        subject = stdin.readLine();

        header = new SimpleSMTPHeader(sender, recipient, subject);

        while (true) {
            System.out.print("CC <enter one address per line, hit enter to end>: ");
            System.out.flush();

            cc = stdin.readLine();

            if (cc == null || cc.length() == 0) {
                break;
            }

            header.addCC(cc.trim());
            ccList.add(cc.trim());
        }

        System.out.print("Filename: ");
        System.out.flush();

        filename = stdin.readLine();

        try {
            fileReader = new FileReader(filename);
        } catch (FileNotFoundException e) {
            System.err.println("File not found. " + e.getMessage());
        }

        client = new SMTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));

        client.connect(server);

        if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) {
            client.disconnect();
            System.err.println("SMTP server refused connection.");
            System.exit(1);
        }

        client.login();

        client.setSender(sender);
        client.addRecipient(recipient);

        for (String recpt : ccList) {
            client.addRecipient(recpt);
        }

        writer = client.sendMessageData();

        if (writer != null) {
            writer.write(header.toString());
            Util.copyReader(fileReader, writer);
            writer.close();
            client.completePendingCommand();
        }

        if (fileReader != null) {
            fileReader.close();
        }

        client.logout();

        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:org.springintegration.demo.Main.java

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

    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);

    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;
        }

    }

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

    System.exit(0);

}

From source file:ReadStdinInt15.java

public static void main(String[] ap) {
    int val;
    try {//from   w w w  .  j  ava2s. c om
        Scanner sc = Scanner.create(System.in); // Requires J2SE 1.5
        val = sc.nextInt();
    } catch (NumberFormatException ex) {
        System.err.println("Not a valid number: " + ex);
        return;
    }
    System.out.println("I read this number: " + val);
}

From source file:TreeNode.java

public static void main(String[] argv) throws IOException {
    BinaryTree bt = new BinaryTree();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int val;
    char ch = ' ';
    String clearbuffer;/*from   w ww.ja  v a2 s. c o  m*/
    do {
        System.out.print("Enter a number: ");
        val = Integer.parseInt(br.readLine());
        bt.insert(val);
        System.out.print("Do you wish to enter more values (Y/N).....");
        ch = (char) br.read();
        clearbuffer = br.readLine();
    } while (ch == 'y' || ch == 'Y');
    System.out.println("Postorder traversal of given tree is: ");
    bt.postorder();
    System.out.println("Preorder traversal of given tree is: ");
    bt.preorder();
    System.out.println("Inorder traversal of given tree is: ");
    bt.inorder();
}

From source file:com.navercorp.client.Main.java

public static void main(String[] args) {
    Client clnt = null;/*from w  w w  . ja v  a 2  s.  co  m*/
    try {
        CommandLine cmd = new DefaultParser()
                .parse(new Options().addOption("z", true, "zookeeper address (ip:port,ip:port,...)")
                        .addOption("t", true, "zookeeper connection timeout")
                        .addOption("c", true, "command and arguments"), args);

        final String connectionString = cmd.hasOption("z") ? cmd.getOptionValue("z") : "127.0.0.1:2181";
        final int timeout = cmd.hasOption("t") ? Integer.valueOf(cmd.getOptionValue("t")) : 10000;
        clnt = new Client(connectionString, timeout);

        String command;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while ((command = in.readLine()) != null) {
            printResult(clnt.execute(command.split(" ")));
        }
        System.exit(Code.OK.n());
    } catch (ParseException e) {
        e.printStackTrace(System.err);
        System.err.println(Client.getUsage());
        System.exit(INVALID_ARGUMENT.n());
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(ZK_CONNECTION_LOSS.n());
    } catch (InterruptedException e) {
        e.printStackTrace(System.err);
        System.exit(INTERNAL_ERROR.n());
    } finally {
        if (clnt != null) {
            try {
                clnt.close();
            } catch (Exception e) {
                ; // nothing to do
            }
        }
    }
}

From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java

public static void main(String... args) throws IOException {
    long start = System.currentTimeMillis();
    int iCounter = 0;
    int fpCounter = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);//  w ww.j  a  v a2 s .c  om
    options.addOption(opt);

    opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)");
    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();
    }

    if (args.length != 0) {
        exitWithHelp(options);
    }

    String type = cmd.getOptionValue("fpType");
    boolean updateDictionaryFile = false;
    boolean hashUnknownFrag = false;
    Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag);
    OEMolBase mol = new OEGraphMol();

    String inFile = cmd.getOptionValue("i");
    oemolistream ifs = new oemolistream(inFile);

    double fract = 2D;
    String tmp = cmd.getOptionValue("sampleFract");
    if (tmp != null)
        fract = Double.parseDouble(tmp);

    Random rnd = new Random();

    LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper();
    int dictSize = mapper.getMaxIdx() + 1;
    int[] freq = new int[dictSize];

    while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;
        if (rnd.nextDouble() < fract) {
            fpCounter++;

            Fingerprint fp = fprinter.getFingerprint(mol);
            for (int bit : fp.getBits())
                freq[bit]++;
        }

        if (iCounter % 100 == 0)
            System.err.print(".");
        if (iCounter % 4000 == 0) {
            System.err.printf(" %d %d %dsec\n", iCounter, fpCounter,
                    (System.currentTimeMillis() - start) / 1000);
        }
    }

    System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter,
            fpCounter, (System.currentTimeMillis() - start) / 1000);

    mapper.reSortDictionary(freq);
    mapper.writeDictionary();
    fprinter.close();
}

From source file:com.hm.SSI.dubbo.DubboConsumer.java

public static void main(String[] args) throws Exception {
    String config = "classpath:/dubbo-consumer.xml"; //AnnotationConsumer.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//from   www  . j a  v  a2  s . c o  m
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
    System.in.read();
}