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

public static void main(String[] args) {
    Set<String> words = new HashSet<String>(); // HashSet implements Set
    long totalTime = 0;

    Scanner in = new Scanner(System.in);
    while (in.hasNext()) {
        String word = in.next();//from  ww w  .  j  av  a2  s. c o m
        long callTime = System.currentTimeMillis();
        words.add(word);
        callTime = System.currentTimeMillis() - callTime;
        totalTime += callTime;
    }

    Iterator<String> iter = words.iterator();
    for (int i = 1; i <= 20 && iter.hasNext(); i++)
        System.out.println(iter.next());
    System.out.println(". . .");
    System.out.println(words.size() + " distinct words. " + totalTime + " milliseconds.");
}

From source file:org.springintegration.SpringIntegrationTest.java

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

    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/spring-integration-context.xml", SpringIntegrationTest.class);
    System.out.println("Hit Enter to terminate");
    System.in.read();
    context.close();/*from   ww  w  .j a  v  a 2 s.  c om*/
}

From source file:BlockingQueueTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter base directory (e.g. /usr/local/jdk1.6.0/src): ");
    String directory = in.nextLine();
    System.out.print("Enter keyword (e.g. volatile): ");
    String keyword = in.nextLine();

    final int FILE_QUEUE_SIZE = 10;
    final int SEARCH_THREADS = 100;

    BlockingQueue<File> queue = new ArrayBlockingQueue<File>(FILE_QUEUE_SIZE);

    FileEnumerationTask enumerator = new FileEnumerationTask(queue, new File(directory));
    new Thread(enumerator).start();
    for (int i = 1; i <= SEARCH_THREADS; i++)
        new Thread(new SearchTask(queue, keyword)).start();
}

From source file:isc_415_practica_1.ISC_415_Practica_1.java

/**
 * @param args the command line arguments
 *//*from ww w  .ja v a  2 s  . c om*/
public static void main(String[] args) {
    String urlString;
    Scanner input = new Scanner(System.in);
    Document doc;

    try {
        urlString = input.next();
        if (urlString.equals("servlet")) {
            urlString = "http://localhost:8084/ISC_415_Practica1_Servlet/client";
        }
        urlString = urlString.contains("http://") || urlString.contains("https://") ? urlString
                : "http://" + urlString;
        doc = Jsoup.connect(urlString).get();
    } catch (Exception ex) {
        System.out.println("El URL ingresado no es valido.");
        return;
    }

    ArrayList<NameValuePair> formInputParams;
    formInputParams = new ArrayList<>();
    String[] plainTextDoc = new TextNode(doc.html(), "").getWholeText().split("\n");
    System.out.println(String.format("Nmero de lineas del documento: %d", plainTextDoc.length));
    System.out.println(String.format("Nmero de p tags: %d", doc.select("p").size()));
    System.out.println(String.format("Nmero de img tags: %d", doc.select("img").size()));
    System.out.println(String.format("Nmero de form tags: %d", doc.select("form").size()));

    Integer index = 1;

    ArrayList<NameValuePair> urlParameters = new ArrayList<>();
    for (Element e : doc.select("form")) {
        System.out.println(String.format("Form %d: Nmero de Input tags %d", index, e.select("input").size()));
        System.out.println(e.select("input"));

        for (Element formInput : e.select("input")) {
            if (formInput.attr("id") != null && formInput.attr("id") != "") {
                urlParameters.add(new BasicNameValuePair(formInput.attr("id"), "PRACTICA1"));
            } else if (formInput.attr("name") != null && formInput.attr("name") != "") {
                urlParameters.add(new BasicNameValuePair(formInput.attr("name"), "PRACTICA1"));
            }
        }

        index++;
    }

    if (!urlParameters.isEmpty()) {
        try {
            CloseableHttpClient httpclient = HttpClients.createDefault();
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, Consts.UTF_8);
            HttpPost httpPost = new HttpPost(urlString);
            httpPost.setHeader("User-Agent", USER_AGENT);
            httpPost.setEntity(entity);
            HttpResponse response = httpclient.execute(httpPost);
            System.out.println(response.getStatusLine());
        } catch (IOException ex) {
            Logger.getLogger(ISC_415_Practica_1.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:org.corfudb.sharedlog.examples.ConfigClnt.java

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

    DefaultHttpClient httpclient = new DefaultHttpClient();
    final BufferedReader prompt = new BufferedReader(new InputStreamReader(System.in));

    CorfuConfiguration C = null;/*from  w w w  . j  a  v a2  s . c  o  m*/

    while (true) {

        System.out.print("> ");
        String line = prompt.readLine();
        if (line.startsWith("get")) {

            HttpGet httpget = new HttpGet("http://localhost:8000/corfu");

            System.out.println("Executing request: " + httpget.getRequestLine());
            HttpResponse response = (HttpResponse) httpclient.execute(httpget);

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            // response.getEntity().writeTo(System.out);
            // System.out.println();
            // System.out.println("----------------------------------------");

            C = new CorfuConfiguration(response.getEntity().getContent());
        } else {

            if (C == null) {
                System.out.println("configuration not set yet!");
                continue;
            }

            HttpPost httppost = new HttpPost("http://localhost:8000/corfu");
            httppost.setEntity(new StringEntity(C.ConfToXMLString()));

            System.out.println("Executing request: " + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            response.getEntity().writeTo(System.out);

        }
    }
    // httpclient.close();
}

From source file:es.cnio.bioinfo.bicycle.BinomialAnnotator.java

public static void main(String[] args) throws IOException, MathException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    double p = Double.parseDouble(args[0]);
    String line = null;// w  w  w .  j  a v a 2s  .  c o  m

    while ((line = in.readLine()) != null) {

        String[] tokens = line.split("\t");
        int reads = Integer.parseInt(tokens[5]);
        int cCount = Integer.parseInt(tokens[4]);
        BinomialDistribution binomial = new BinomialDistributionImpl(reads, p);
        double pval = (reads == 0) ? 1.0d : (1.0d - binomial.cumulativeProbability(cCount - 1));
        if (System.out.checkError()) {
            System.exit(1);
        }
        System.out.println(line + "\t" + pval);

    }
}

From source file:br.upf.contatos.tcp.Client.java

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

    String teste = Arrays.toString(args);
    if (args.length == 0) {
        Client.HOST = "localhost";
    } else {//from  w  w w .ja  v a2 s .  c  o  m
        Client.HOST = args[0];
    }

    ClientConnector tcpService = new ClientConnector(Client.HOST, PORTA);
    String line;
    tcpService.connect();
    do {
        System.out.println("Digite help, para o menu");
        Scanner scanner = new Scanner(System.in);
        line = scanner.nextLine();
    } while (comando(line, tcpService));

    tcpService.disconnect();
}

From source file:fi.jyu.it.ties456.week38.Main.Main.java

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

    TeacherRegistryService connect = new TeacherRegistryService();
    TeacherRegistry teacher = connect.getTeacherRegistryPort();
    CourseISService connectCourse = new CourseISService();
    CourseIS course = connectCourse.getCourseISPort();
    int i;/*from   www. jav  a 2 s.  co m*/
    Scanner inputchoice = new Scanner(System.in);
    Scanner cin = new Scanner(System.in);

    do {
        System.out.println("0: Quit the application");
        System.out.println("1: Search the teacher Info");
        System.out.println("2: Create the Course");
        i = inputchoice.nextInt();
        switch (i) {
        case 0:
            System.out.println("quit the application");
            break;
        case 1:
            System.out.println("Input search info of teacher");
            String searchString = cin.nextLine();
            JSONObject result = searchTeacher(teacher, searchString);
            if (result == null)
                System.out.println("No person found");
            else
                System.out.println(result);
            break;
        case 2:
            createCourse(teacher, course);
            break;
        default:
            System.err.println("Not a valid choice");

        }
    } while (i != 0);
}

From source file:poc.telnet.TelnetServer.java

public static void main(String[] args) throws Exception {
    new ClassPathXmlApplicationContext("/META-INF/spring/integration/telnet-inbound.xml");
    System.out.println("Press Enter/Return in the console to exit");
    System.in.read();
    System.exit(0);/*from   w  w w.  j a v  a 2 s  .c om*/
}

From source file:base64test.Base64Test.java

/**
 * @param args the command line arguments
 *///  ww w  .j a v a  2  s.com
public static void main(String[] args) {
    try {
        if (!Base64.isBase64(args[0])) {
            throw new Exception("Arg 1 is not a Base64 string!");
        } else {
            String decodedBase64String = new String(Base64.decodeBase64(args[0]));
            File tempFile = File.createTempFile("base64Test", ".tmp");
            tempFile.deleteOnExit();
            FileWriter fw = new FileWriter(tempFile, false);
            PrintWriter pw = new PrintWriter(fw);
            pw.write(decodedBase64String);
            pw.close();
            String fileType = getFileType(tempFile.toPath());
            System.out.println(fileType);
            System.in.read();
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}