Example usage for java.io CharArrayReader mark

List of usage examples for java.io CharArrayReader mark

Introduction

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

Prototype

public void mark(int readAheadLimit) throws IOException 

Source Link

Document

Marks the present position in the stream.

Usage

From source file:Main.java

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

    char[] ch = { 'A', 'B', 'C', 'D', 'E' };

    CharArrayReader car = new CharArrayReader(ch);

    // read and print the characters from the stream
    System.out.println(car.read());
    System.out.println(car.read());

    // mark() is invoked at this position
    car.mark(0);
    System.out.println("Mark() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());

    // reset() is invoked at this position
    car.reset();// w w w.  j a  va  2 s .c o  m
    System.out.println("Reset() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());
    System.out.println(car.read());

}

From source file:Main.java

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

    char[] ch = { 'A', 'B', 'C', 'D', 'E' };

    CharArrayReader car = new CharArrayReader(ch);

    // verifies if the stream support mark() method
    boolean bool = car.markSupported();
    System.out.println("Is mark supported : " + bool);
    System.out.println("Proof:");

    // read and print the characters from the stream
    System.out.println(car.read());
    System.out.println(car.read());

    // mark() is invoked at this position
    car.mark(0);
    System.out.println("Mark() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());

    // reset() is invoked at this position
    car.reset();/*  w w  w  .j  ava 2s  .  c o  m*/
    System.out.println("Reset() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());
    System.out.println(car.read());

}