Example usage for java.io BufferedReader BufferedReader

List of usage examples for java.io BufferedReader BufferedReader

Introduction

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

Prototype

public BufferedReader(Reader in) 

Source Link

Document

Creates a buffering character-input stream that uses a default-sized input buffer.

Usage

From source file:Main.java

public static void main(String[] arg) throws Exception {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        String sLine = bf.readLine();
        System.out.println("::" + sLine);
    }//  ww  w . j av a2s  . com
}

From source file:WebClient.java

public static void main(String[] args) throws Exception {
        CookieStore store = new MyCookieStore();
        CookiePolicy policy = new MyCookiePolicy();
        CookieManager handler = new CookieManager(store, policy);
        CookieHandler.setDefault(handler);
        URL url = new URL("http://localhost:8080/cookieTest.jsp");
        URLConnection conn = url.openConnection();

        InputStream in = conn.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String input;// w  w w. j a va  2 s  .  c o m
        while ((input = reader.readLine()) != null) {
            System.out.println(input);
        }
        reader.close();

    }

From source file:math2605.gn_log.java

/**
 * @param args the command line arguments
 *///from www  .  j  ava  2 s .c  o  m
public static void main(String[] args) {
    //get file name
    System.out.println("Please enter a file name:");
    Scanner scanner = new Scanner(System.in);
    String fileName = scanner.nextLine();
    List<String[]> pairs = new ArrayList<>();
    //get coordinate pairs and add to arraylist
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = br.readLine()) != null) {
            String[] pair = line.split(",");
            pairs.add(pair);
        }
        br.close();
    } catch (Exception e) {
    }

    System.out.println("Please enter the value of a:");
    double a = scanner.nextInt();
    System.out.println("Please enter the value of b:");
    double b = scanner.nextInt();
    System.out.println("Please enter the value of c:");
    double c = scanner.nextInt();
    //init B, vector with 3 coordinates
    RealMatrix B = new Array2DRowRealMatrix(3, 1);
    B.setEntry(0, 0, a);
    B.setEntry(1, 0, b);
    B.setEntry(2, 0, c);

    System.out.println("Please enter the number of iteration for the Gauss-newton:");
    //init N, number of iterations
    int N = scanner.nextInt();

    //init r, vector of residuals
    RealMatrix r = new Array2DRowRealMatrix();
    setR(pairs, a, b, c, r);

    //init J, Jacobian of r
    RealMatrix J = new Array2DRowRealMatrix();
    setJ(pairs, a, b, c, r, J);

    System.out.println("J");
    System.out.println(J);
    System.out.println("r");
    System.out.println(r);

    RealMatrix sub = findQR(J, r);

    for (int i = N; i > 0; i--) {
        B = B.subtract(sub);
        double B0 = B.getEntry(0, 0);
        double B1 = B.getEntry(1, 0);
        double B2 = B.getEntry(2, 0);
        //CHANGE ABC TO USE B0, B1, B2
        setR(pairs, B0, B1, B2, r);
        setJ(pairs, B0, B1, B2, r, J);
    }
    System.out.println("B");
    System.out.println(B.toString());
}

From source file:ElementIteratorExample.java

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

    if (args.length != 1) {
        System.err.println("Usage: java ElementIteratorExample input-URL");
    }/*  w  ww .  jav  a  2 s.  c o  m*/

    // Load HTML file synchronously
    URL url = new URL(args[0]);
    URLConnection connection = url.openConnection();
    InputStream is = connection.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    HTMLEditorKit.Parser parser = new ParserDelegator();
    HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
    parser.parse(br, callback, true);

    // Parse
    ElementIterator iterator = new ElementIterator(htmlDoc);
    Element element;
    while ((element = iterator.next()) != null) {
        AttributeSet attributes = element.getAttributes();
        Object name = attributes.getAttribute(StyleConstants.NameAttribute);
        if ((name instanceof HTML.Tag)
                && ((name == HTML.Tag.H1) || (name == HTML.Tag.H2) || (name == HTML.Tag.H3))) {
            // Build up content text as it may be within multiple elements
            StringBuffer text = new StringBuffer();
            int count = element.getElementCount();
            for (int i = 0; i < count; i++) {
                Element child = element.getElement(i);
                AttributeSet childAttributes = child.getAttributes();
                if (childAttributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.CONTENT) {
                    int startOffset = child.getStartOffset();
                    int endOffset = child.getEndOffset();
                    int length = endOffset - startOffset;
                    text.append(htmlDoc.getText(startOffset, length));
                }
            }
            System.out.println(name + ": " + text.toString());
        }
    }
    System.exit(0);
}

From source file:base64.EncodeBase64.java

public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter string to encode (input is not escaped):");

    String originalString = reader.readLine();
    String encodedBase64String = Base64.encodeBase64String(originalString.getBytes());
    System.out.println("Your encoded Base64 string :");
    System.out.println(encodedBase64String);
}

From source file:math2605.gn_exp.java

/**
 * @param args the command line arguments
 *///from  w  ww. j  a va  2s .c  om
public static void main(String[] args) {
    //get file name
    System.out.println("Please enter a file name:");
    Scanner scanner = new Scanner(System.in);
    String fileName = scanner.nextLine();
    List<String[]> pairs = new ArrayList<>();
    //get coordinate pairs and add to arraylist
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;
        while ((line = br.readLine()) != null) {
            String[] pair = line.split(",");
            pairs.add(pair);
        }
        br.close();
    } catch (Exception e) {
    }

    System.out.println("Please enter the value of a:");
    double a = scanner.nextInt();
    System.out.println("Please enter the value of b:");
    double b = scanner.nextInt();
    System.out.println("Please enter the value of c:");
    double c = scanner.nextInt();
    //init B, vector with 3 coordinates
    RealMatrix B = new Array2DRowRealMatrix(3, 1);
    B.setEntry(0, 0, a);
    B.setEntry(1, 0, b);
    B.setEntry(2, 0, c);

    System.out.println("Please enter the number of iteration for the Gauss-newton:");
    //init N, number of iterations
    int N = scanner.nextInt();

    //init r, vector of residuals
    RealMatrix r = new Array2DRowRealMatrix();
    setR(pairs, a, b, c, r);

    //init J, Jacobian of r
    RealMatrix J = new Array2DRowRealMatrix();
    setJ(pairs, a, b, c, r, J);

    System.out.println("J");
    System.out.println(J);
    System.out.println("r");
    System.out.println(r);

    RealMatrix sub = findQR(J, r);

    for (int i = N; i > 0; i--) {
        B = B.subtract(sub);
        double B0 = B.getEntry(0, 0);
        double B1 = B.getEntry(1, 0);
        double B2 = B.getEntry(2, 0);
        //CHANGE ABC TO USE B0, B1, B2
        setR(pairs, B0, B1, B2, r);
        setJ(pairs, B0, B1, B2, r, J);
    }
    System.out.println("B");
    System.out.println(B.toString());

}

From source file:FlightInfo.java

public static void main(String args[]) {
    String to, from;//  w  w  w  . j  a v  a2 s  .  c  om
    Optimal ob = new Optimal();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    boolean done = false;
    FlightInfo f;

    ob.setup();

    try {
        System.out.print("From? ");
        from = br.readLine();
        System.out.print("To? ");
        to = br.readLine();
        do {
            ob.isflight(from, to);

            if (ob.btStack.size() == 0)
                done = true;
            else {
                ob.route(to);
                ob.btStack = new Stack();
            }
        } while (!done);

        // Display optimal solution.
        if (ob.optimal != null) {
            System.out.println("Optimal solution is: ");

            int num = ob.optimal.size();
            for (int i = 0; i < num; i++) {
                f = (FlightInfo) ob.optimal.pop();
                System.out.print(f.from + " to ");
            }

            System.out.println(to);
            System.out.println("Distance is " + ob.minDist);
        }
    } catch (IOException exc) {
        System.out.println("Error on input.");
    }
}

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 {//from www  . j  a  v 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  ww .j av  a 2s . com

    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  2 s .  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);

    }
}