Example usage for java.io InputStreamReader InputStreamReader

List of usage examples for java.io InputStreamReader InputStreamReader

Introduction

In this page you can find the example usage for java.io InputStreamReader InputStreamReader.

Prototype

public InputStreamReader(InputStream in) 

Source Link

Document

Creates an InputStreamReader that uses the default charset.

Usage

From source file:ui.pack.MyFrame.java

public static void main(String... args) throws IOException {
    //MyFrame mf= new MyFrame();
    HttpClient client = HttpClientBuilder.create().build();
    String url = "http://localhost:8080/students/all";
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(response.getEntity().getContent()));
    StringBuilder builder = new StringBuilder();
    while (true) {
        String line = bufferedReader.readLine();
        if (line == null) {
            break;
        } else {/*  w w  w  .  jav a 2 s  . c  o  m*/
            builder.append(line);
        }
    }
    bufferedReader.close();
    String result = builder.toString();
    System.out.println(result);
    JSONArray arr = new JSONArray(result);
    System.out.println(arr.length());

    //client.
}

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 a  2 s .  co  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;/*from  w w  w  . j a v  a 2  s .  co  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:SendMail.java

public static void main(String[] args) {
    try {//  ww  w  . j  a v  a2s . c  o  m
        // If the user specified a mailhost, tell the system about it.
        if (args.length >= 1)
            System.getProperties().put("mail.host", args[0]);

        // A Reader stream to read from the console
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        // Ask the user for the from, to, and subject lines
        System.out.print("From: ");
        String from = in.readLine();
        System.out.print("To: ");
        String to = in.readLine();
        System.out.print("Subject: ");
        String subject = in.readLine();

        // Establish a network connection for sending mail
        URL u = new URL("mailto:" + to); // Create a mailto: URL
        URLConnection c = u.openConnection(); // Create its URLConnection
        c.setDoInput(false); // Specify no input from it
        c.setDoOutput(true); // Specify we'll do output
        System.out.println("Connecting..."); // Tell the user
        System.out.flush(); // Tell them right now
        c.connect(); // Connect to mail host
        PrintWriter out = // Get output stream to host
                new PrintWriter(new OutputStreamWriter(c.getOutputStream()));

        // We're talking to the SMTP server now.
        // Write out mail headers. Don't let users fake the From address
        out.print("From: \"" + from + "\" <" + System.getProperty("user.name") + "@"
                + InetAddress.getLocalHost().getHostName() + ">\r\n");
        out.print("To: " + to + "\r\n");
        out.print("Subject: " + subject + "\r\n");
        out.print("\r\n"); // blank line to end the list of headers

        // Now ask the user to enter the body of the message
        System.out.println("Enter the message. " + "End with a '.' on a line by itself.");
        // Read message line by line and send it out.
        String line;
        for (;;) {
            line = in.readLine();
            if ((line == null) || line.equals("."))
                break;
            out.print(line + "\r\n");
        }

        // Close (and flush) the stream to terminate the message
        out.close();
        // Tell the user it was successfully sent.
        System.out.println("Message sent.");
    } catch (Exception e) { // Handle any exceptions, print error message.
        System.err.println(e);
        System.err.println("Usage: java SendMail [<mailhost>]");
    }
}

From source file:com.cliqset.magicsig.util.KeyTester.java

public static void main(String[] args) {
    try {/*from   ww w. ja v a  2  s .co  m*/
        FileInputStream fis = new FileInputStream(keyFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
        String line = null;

        while ((line = reader.readLine()) != null) {
            MagicKey key = new MagicKey(line.getBytes("ASCII"));

            RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm();
            byte[] sig = alg.sign(data, key);

            System.out.println(Base64.encodeBase64URLSafeString(sig));

            boolean verified = alg.verify(data, sig, key);

            if (!verified) {
                System.out.println("FAILED - " + line);
            }

            //System.out.println(lineSplit[0] + " " + key.toString(true));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Done.");
}

From source file:MainClass.java

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

        URL url = new URL("http://www.java2s.com/");
        URLConnection urlConnection = url.openConnection();
        Map<String, List<String>> headers = urlConnection.getHeaderFields();
        Set<Map.Entry<String, List<String>>> entrySet = headers.entrySet();
        for (Map.Entry<String, List<String>> entry : entrySet) {
            String headerName = entry.getKey();
            System.out.println("Header Name:" + headerName);
            List<String> headerValues = entry.getValue();
            for (String value : headerValues) {
                System.out.print("Header value:" + value);
            }
            System.out.println();
            System.out.println();
        }
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = bufferedReader.readLine();
        while (line != null) {
            System.out.println(line);
            line = bufferedReader.readLine();
        }
        bufferedReader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ExecDemoPartial.java

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

    BufferedReader is; // reader for output of process
    String line;//from   w  w  w . j  a  va 2  s  . co  m

    final Process p = Runtime.getRuntime().exec(PROGRAM);

    Thread waiter = new Thread() {
        public void run() {
            try {
                p.waitFor();
            } catch (InterruptedException ex) {
                // OK, just quit this thread.
                return;
            }
            System.out.println("Program terminated!");
            done = true;
        }
    };
    waiter.start();

    // getInputStream gives an Input stream connected to
    // the process p's standard output (and vice versa). We use
    // that to construct a BufferedReader so we can readLine() it.
    is = new BufferedReader(new InputStreamReader(p.getInputStream()));

    while (!done && ((line = is.readLine()) != null))
        System.out.println(line);

    return;
}

From source file:org.isaacphysics.labs.chemistry.checker.RunParser.java

public static void main(String args[]) throws Exception {
    //noinspection deprecation (We know DefaultSymbolFactory is depracated!)
    ArrayList<Statement> statements = (ArrayList<Statement>) new ChemistryParser(
            new ChemistryLexer(new InputStreamReader(new FileInputStream("src/test.txt"))),
            new DefaultSymbolFactory()).parse().value;
    System.err.flush();/*from w w  w. j  a  va2  s. co m*/
    System.out.flush();
    System.out.println();
    for (Statement statement : statements) {
        System.out.println(statement);
        if (statement instanceof ExpressionStatement) {
            System.out.println("Total atoms: " + ((ExpressionStatement) statement).getAtomCount());
            System.out.println("Total charge: " + ((ExpressionStatement) statement).getCharge());
        } else if (statement instanceof EquationStatement) {
            System.out.println("Is balanced? " + ((EquationStatement) statement).isBalanced());
            System.out.println(
                    "Total atoms LHS: " + ((EquationStatement) statement).getLeftExpression().getAtomCount());
            System.out.println(
                    "Total atoms RHS: " + ((EquationStatement) statement).getRightExpression().getAtomCount());
            System.out.println(
                    "Total charge LHS: " + ((EquationStatement) statement).getLeftExpression().getCharge());
            System.out.println(
                    "Total charge RHS: " + ((EquationStatement) statement).getRightExpression().getCharge());
        }
        System.out.println("\n");
    }

    System.out.println();
    EquationStatement a = (EquationStatement) statements.get(5);
    EquationStatement b = (EquationStatement) statements.get(6);
    if (a.equals(b)) {
        System.out.println("\"" + a.toString() + "\" == \"" + b.toString() + "\"");
        if (!b.equals(a)) {
            System.err.println("Equality not symmetric!");
        }
    } else {
        System.out.println("\"" + a.toString() + "\" != \"" + b.toString() + "\"");
        if (b.equals(a)) {
            System.err.println("Equality not symmetric!");
        }
    }
}

From source file:postenergy.PostHttpClient.java

public static void main(String[] args) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass");

    try {/*w w w .  ja  va2  s  . c o  m*/

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("?n", "=mindass"));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        String line = "";
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
            if (line.startsWith("Input:")) {
                String key = line.substring(6);
                // do something with the key
                System.out.println("key:" + key);
            }

        }
    } catch (IOException e) {
        System.out.println("There was an error: " + e);
    }
}

From source file:com.blockhaus2000.csvviewer.CsvViewerMain.java

public static void main(final String[] args) {
    try (final CSVParser parser = new CSVParser(new InputStreamReader(System.in), CSVFormat.DEFAULT)) {
        final Table table = new Table();

        final Map<String, Integer> headerMap = parser.getHeaderMap();
        if (headerMap != null) {
            final TableRow headerRow = new TableRow();
            headerMap.keySet().forEach(headerData -> headerRow.addCell(new TableRowCell(headerData)));
            table.setHeaderRow(headerRow);
        }//from w  ww .  ja  v a 2  s. c  o m

        final AtomicBoolean asHeader = new AtomicBoolean(headerMap == null);
        parser.getRecords().forEach(record -> {
            final TableRow row = new TableRow();
            record.forEach(rowData -> row.addCell(new TableRowCell(rowData)));
            if (asHeader.getAndSet(false)) {
                table.setHeaderRow(row);
            } else {
                table.addRow(row);
            }
        });

        System.out.println(table.getFormattedString());
    } catch (final IOException cause) {
        throw new RuntimeException("An error occurred whilst parsing stdin!", cause);
    }
}