Example usage for java.io PushbackReader PushbackReader

List of usage examples for java.io PushbackReader PushbackReader

Introduction

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

Prototype

public PushbackReader(Reader in, int size) 

Source Link

Document

Creates a new pushback reader with a pushback buffer of the given size.

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from ww  w  . j a  v  a  2  s  .co m
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        pr.mark(5);
        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from  w w  w .j av a2  s  . c o  m
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        System.out.println("" + pr.markSupported());

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    char cbuf[] = new char[5];

    try {/*w  w w  .j a va2  s  .  c  o m*/
        System.out.println(pr.read(cbuf));

        System.out.println(cbuf);

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {/*from  w  w  w  .  j a  va  2  s  .com*/
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        char cbuf[] = { 'w', 'o', 'r', 'l', 'd' };

        pr.unread(cbuf, 1, 4);

        for (int i = 0; i < 4; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {/* w  w  w  .j a  va2 s  .  co  m*/
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        char cbuf[] = { 'w', 'o', 'r', 'l', 'd' };

        pr.unread(cbuf);

        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);
    try {//w  ww .jav a2s .com
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from   w w w.j  a v  a 2  s.c o m
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from  w w w . j a  v a2  s.  com
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);

            // skip a character every time
            pr.skip(1);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);

    try {//  ww  w.j a  va 2 s. c o m
        // check if the reader is ready
        System.out.println(pr.ready());

        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);

    try {/*from   w ww.  j av  a  2s. com*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        // unread a character
        pr.unread('F');

        // read the next char, which is the one we unread
        char c = (char) pr.read();

        System.out.println(c);

        pr.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}