Example usage for java.io FilterReader FilterReader

List of usage examples for java.io FilterReader FilterReader

Introduction

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

Prototype

protected FilterReader(Reader in) 

Source Link

Document

Creates a new filtered reader.

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 ww  .j av a2 s .  com

    // true if the filter reader is ready to be read
    boolean bool = fr.ready();

    // prints
    System.out.println("Ready to read? " + bool);

}

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 2  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());

}

From source file:Main.java

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

    int i = 0;// w  w w.  j  a va  2 s.c o  m

    Reader r = new StringReader("ABCDEFG");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };

    // read till the end of the stream
    while ((i = fr.read()) != -1) {
        char c = (char) i;
        System.out.println(c);
    }

}

From source file:Main.java

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

    // create new reader
    Reader r = new StringReader("ABCDEF");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };/*from w w w. j ava2s . co m*/

    // tests if the filter reader supports mark()
    boolean bool = fr.markSupported();

    // prints
    System.out.print("If mark() supported? " + bool);

}

From source file:Main.java

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

    char[] cbuf = new char[6];
    int i = 0;// ww w  .  j a  v a 2s . co m

    Reader r = new StringReader("ABCDEF");

    FilterReader fr = new FilterReader(r) {
    };

    // read data of len 4, to the buffer
    i = fr.read(cbuf, 2, 4);
    System.out.println("No. of characters read: " + i);

    // read till the end of the char buffer
    for (char c : cbuf) {
        // checks for the empty character in buffer
        if ((byte) c == 0)
            c = '-';

        System.out.print(c);
    }

}

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) {
    };//from  w  ww.  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 {

    int i = 0;/*w  w w  .j  a  v a2 s  .c  om*/
    char c;

    // create new reader
    Reader r = new StringReader("ABCDEF");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };

    // read till the end of the stream
    while ((i = fr.read()) != -1) {
        // converts integer to character
        c = (char) i;

        // print
        System.out.println("Character read: " + c);
    }

}

From source file:Main.java

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

    int i = 0;//from  w w w  .  j  a  v a  2 s . c  o  m

    // create new reader
    Reader r = new StringReader("from java2s.com");

    // create new filter reader
    FilterReader fr = new FilterReader(r) {
    };

    // read till the end of the filter reader
    while ((i = fr.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        // prints
        System.out.println("Character read: " + c);

        // number of characters actually skipped
        long l = fr.skip(2);

        // prints
        System.out.println("Character skipped: " + l);
    }

}

From source file:com.adaptris.core.MarshallingBaseCase.java

public void testUnmarshalFromReader_WithException() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    String s = marshaller.marshal(adapter);
    Reader fail = new FilterReader(new StringReader(s)) {
        @Override/*from w  w w  .j  a v a2s  .co  m*/
        public int read() throws IOException {
            throw new IOException("testUnmarshalFromReader_WithException");
        }

        @Override
        public int read(char[] cbuf, int off, int len) throws IOException {
            throw new IOException("testUnmarshalFromReader_WithException");
        }
    };
    try (Reader in = fail) {
        Adapter adapter2 = (Adapter) marshaller.unmarshal(in);
        fail();
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        // assertEquals(IOException.class, e.getCause().getClass());
        assertRootCause("testUnmarshalFromReader_WithException", e);
    }
}