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

public static void main(String args[]) throws IOException {
    Vector v = new Vector(3);
    v.add(new FileInputStream("/etc/motd"));
    v.add(new FileInputStream("foo.bar"));
    v.add(new FileInputStream("/temp/john.txt"));
    Enumeration e = v.elements();
    SequenceInputStream sis = new SequenceInputStream(e);
    InputStreamReader isr = new InputStreamReader(sis);
    BufferedReader br = new BufferedReader(isr);
    String line;//w  w  w . j  ava  2 s. com
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:RegExpExample.java

public static void main(String args[]) {
    String fileName = "RETestSource.java";

    String unadornedClassRE = "^\\s*class (\\w+)";
    String doubleIdentifierRE = "\\b(\\w+)\\s+\\1\\b";

    Pattern classPattern = Pattern.compile(unadornedClassRE);
    Pattern doublePattern = Pattern.compile(doubleIdentifierRE);
    Matcher classMatcher, doubleMatcher;

    int lineNumber = 0;

    try {//from  w  ww.  j  a  va  2  s.c o  m
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;

        while ((line = br.readLine()) != null) {
            lineNumber++;

            classMatcher = classPattern.matcher(line);
            doubleMatcher = doublePattern.matcher(line);

            if (classMatcher.find()) {
                System.out.println("The class [" + classMatcher.group(1) + "] is not public");
            }

            while (doubleMatcher.find()) {
                System.out.println("The word \"" + doubleMatcher.group(1) + "\" occurs twice at position "
                        + doubleMatcher.start() + " on line " + lineNumber);
            }
        }
    } catch (IOException ioe) {
        System.out.println("IOException: " + ioe);
        ioe.printStackTrace();
    }
}

From source file:MainClass.java

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

    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 8888);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println("Hi,How are u!");
    out.println("");
    String line = null;/*from   w  w w  .  java  2 s . co m*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }

    in.close();
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);/*from  w w w  .  ja va2 s  . c  o  m*/
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close();
    System.setOut(console);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(443);
    while (true) {
        Socket s = ss.accept();/*  w  ww . j  a  va  2  s  .  co  m*/
        PrintStream out = new PrintStream(s.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String info = null;
        String request = null;
        String refer = null;

        while ((info = in.readLine()) != null) {
            if (info.startsWith("GET")) {
                request = info;
            }
            if (info.startsWith("Referer:")) {
                refer = info;
            }
            if (info.equals(""))
                break;
        }
        if (request != null) {
            out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html");
            int sp1 = request.indexOf(' ');
            int sp2 = request.indexOf(' ', sp1 + 1);
            String filename = request.substring(sp1 + 2, sp2);
            if (refer != null) {
                sp1 = refer.indexOf(' ');
                refer = refer.substring(sp1 + 1, refer.length());
                if (!refer.endsWith("/")) {
                    refer = refer + "/";
                }
                filename = refer + filename;
            }
            URL con = new URL(filename);
            InputStream gotoin = con.openStream();
            int n = gotoin.available();
            byte buf[] = new byte[1024];
            out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html");
            out.println("Content_Length:" + n + "\n");
            while ((n = gotoin.read(buf)) >= 0) {
                out.write(buf, 0, n);
            }
            out.close();
            s.close();
            in.close();
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.java2s.com");
    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);//w  w  w .  jav a  2s.c  o  m

    for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator
            .next()) {

        AttributeSet attributes = iterator.getAttributes();
        String srcString = (String) attributes.getAttribute(HTML.Attribute.HREF);
        System.out.print(srcString);
        int startOffset = iterator.getStartOffset();
        int endOffset = iterator.getEndOffset();
        int length = endOffset - startOffset;
        String text = htmlDoc.getText(startOffset, length);
        System.out.println(" - " + text);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    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);/*from   w  w  w .  j  av  a 2 s . c om*/

    for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator
            .next()) {

        AttributeSet attributes = iterator.getAttributes();
        String srcString = (String) attributes.getAttribute(HTML.Attribute.HREF);
        System.out.print(srcString);
        int startOffset = iterator.getStartOffset();
        int endOffset = iterator.getEndOffset();
        int length = endOffset - startOffset;
        String text = htmlDoc.getText(startOffset, length);
        System.out.println(" - " + text);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    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);// w  ww  .j a  v  a 2  s . c o  m

    for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator
            .next()) {

        AttributeSet attributes = iterator.getAttributes();
        String srcString = (String) attributes.getAttribute(HTML.Attribute.HREF);
        System.out.print(srcString);
        int startOffset = iterator.getStartOffset();
        int endOffset = iterator.getEndOffset();
        int length = endOffset - startOffset;
        String text = htmlDoc.getText(startOffset, length);
        System.out.println("  " + text);
    }
}

From source file:pl.edu.amu.wmi.bank.Bank.java

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

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

    ApplicationContext context = new ClassPathXmlApplicationContext("Context.xml");

    SendPublicKeyService keySender = (SendPublicKeyService) context.getBean("sendPublicKeyToShopService");

    keySender.sendPublicKey();//from w  w w. ja  va  2 s. c  o m

    Accounts accounts = (Accounts) context.getBean("accounts");

    System.out.println(accounts);

    while (true) {
        System.out.println("Wcisnij cokolwiek zeby ponownie wyslac klucz");
        reader.readLine();
        keySender.sendPublicKey();
    }

}

From source file:DocumentIteratorExample.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.java2s.com");
    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);//from  ww w . ja  v a 2 s  . co  m

    for (HTMLDocument.Iterator iterator = htmlDoc.getIterator(HTML.Tag.A); iterator.isValid(); iterator
            .next()) {

        AttributeSet attributes = iterator.getAttributes();
        String srcString = (String) attributes.getAttribute(HTML.Attribute.HREF);
        System.out.print(srcString);
        int startOffset = iterator.getStartOffset();
        int endOffset = iterator.getEndOffset();
        int length = endOffset - startOffset;
        String text = htmlDoc.getText(startOffset, length);
        System.out.println(" - " + text);
    }
    System.exit(0);
}