Example usage for java.io FilterReader reset

List of usage examples for java.io FilterReader reset

Introduction

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

Prototype

public void reset() throws IOException 

Source Link

Document

Resets the stream.

Usage

From source file:Main.java

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

    Reader r = new StringReader("ABCDEF");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };/*  w w  w . j a  v  a  2s.  c  o m*/

    // reads and prints FilterReader
    System.out.println((char) fr.read());
    System.out.println((char) fr.read());

    // mark invoked at this position
    fr.mark(0);
    System.out.println("mark() invoked");
    System.out.println((char) fr.read());
    System.out.println((char) fr.read());

    // reset() repositioned the stream to the mark
    fr.reset();
    System.out.println("reset() invoked");
    System.out.println((char) fr.read());
    System.out.println((char) fr.read());

}

From source file:Main.java

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

    Reader r = new StringReader("ABCDEF");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };//ww w.  j av  a2 s. c  o  m

    // read and print characters one by one
    System.out.println("Char : " + (char) fr.read());
    System.out.println("Char : " + (char) fr.read());
    System.out.println("Char : " + (char) fr.read());

    // mark is set on the filter reader
    fr.mark(0);
    System.out.println("Char : " + (char) fr.read());
    System.out.println("reset() invoked");

    // reset is called
    fr.reset();

    // read and print characters
    System.out.println("char : " + (char) fr.read());
    System.out.println("char : " + (char) fr.read());

}