public abstract class FilteredBufferedReader extends BufferedReader
BufferedReader
class,
as the result is guaranteed to behave as expected.
To use this class, you have to implement the filterLine(String)
method.
For example:
BufferedReader reader = new FilteredBufferedReader(new FileReader(in)) { public String filterLine(String line) { return line.trim().toLowerCase(); } };In this example, each attempts to the
readLine()
method will get the next
line in the input File, after trimming this line and transforming it to lower case.Constructor and Description |
---|
FilteredBufferedReader(Reader in)
Create a buffering character-input stream that uses a default-sized input buffer.
|
FilteredBufferedReader(Reader in,
int sz)
Create a buffering character-input stream that uses an input buffer of the specified size.
|
Modifier and Type | Method and Description |
---|---|
abstract String |
filterLine(String line)
This abstract method allows to filter each line which is read by this Reader.
|
void |
mark(int readAheadLimit)
Mark the present position in the stream.
|
int |
read()
Read a single character.
|
int |
read(char[] cbuf)
Read characters into an array.
|
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array.
|
String |
readLine()
Read a line of text.
|
boolean |
ready()
Tell whether this stream is ready to be read.
|
void |
reset()
Resets the stream to the most recent mark.
|
long |
skip(long n)
Skip characters.
|
close, lines, markSupported
public FilteredBufferedReader(Reader in)
in
- the readerpublic FilteredBufferedReader(Reader in, int sz)
in
- the readersz
- the size of the bufferpublic String readLine() throws IOException
Remark :As for all read methods, the lines will be filtered by the
filterLine(String)
method.
readLine
in class BufferedReader
IOException
BufferedReader.readLine()
,
filterLine(String)
public abstract String filterLine(String line)
public String filterLine(String line) { return line; }
line
- the linepublic int read() throws IOException
filterLine(String)
method.read
in class BufferedReader
IOException
BufferedReader.read()
,
filterLine(String)
public int read(char[] cbuf, int off, int len) throws IOException
filterLine(String)
method.read
in class BufferedReader
IOException
BufferedReader.read(char[], int, int)
,
filterLine(String)
public int read(char[] cbuf) throws IOException
filterLine(String)
method.read
in class Reader
IOException
Reader.read(char[])
,
filterLine(String)
public boolean ready() throws IOException
ready
in class BufferedReader
IOException
BufferedReader.ready()
public long skip(long n) throws IOException
skip
in class BufferedReader
IOException
BufferedReader.skip(long)
public void mark(int readAheadLimit) throws IOException
readLine()
method.mark
in class BufferedReader
IOException
BufferedReader.mark(int)
public void reset() throws IOException
reset
in class BufferedReader
IOException
mark(int)
,
BufferedReader.reset()