net.sf.jmatchparser.util
Class LineCountVerifyReader
java.lang.Object
java.io.Reader
net.sf.jmatchparser.util.LineCountVerifyReader
- All Implemented Interfaces:
- Closeable, Readable
public class LineCountVerifyReader
- extends Reader
A Reader
that reads from a BufferedReader
and counts the
lines read. At the end of the output, there is a marker followed by the
actual line count. If the line count is wrong, an exception is thrown, else
the line count and everything after it is ignored.
As a convenience, when closing a not fully consumed reader, the remaining
lines are read and the line count is verified. Therefore, to verify the line
count without reading the contents, it is sufficient to close the reader.
Method Summary |
void |
close()
|
int |
read(char[] cbuf,
int off,
int len)
|
boolean |
ready()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LineCountVerifyReader
public LineCountVerifyReader(BufferedReader br,
Pattern lineCountMarkerPattern,
Pattern lineCountPattern,
int lineCountOffset)
- Create a new reader.
- Parameters:
br
- Buffered reader to read fromlineCountMarkerPattern
- Pattern of the line that marks the end of the file and the
following line countlineCountPattern
- Pattern of the line that contains the line count as group 1.
If null
group 1 of the previous pattern contains
the line countlineCountOffset
- Difference between number of lines and line count printed.
Positive if the printed line count is higher and vice versa
ready
public boolean ready()
throws IOException
- Overrides:
ready
in class Reader
- Throws:
IOException
read
public int read(char[] cbuf,
int off,
int len)
throws IOException
- Specified by:
read
in class Reader
- Throws:
IOException
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Specified by:
close
in class Reader
- Throws:
IOException
Copyright © 2011. All Rights Reserved.