01: package snow.utils;
02:
03: import java.util.*;
04: import java.io.*;
05:
06: /** The number is usually used a human-readable debug information
07: this also stores the last line, allowing a kind of "undo"
08: very useful in certain parse operations.
09: */
10: public class NumberedLineReader extends BufferedReader {
11: int lineNumber = 0;
12: String lastLine = null;
13:
14: public NumberedLineReader(String cont) {
15: super (new StringReader(cont));
16: }
17:
18: @Override
19: public String readLine() throws IOException {
20: lineNumber++;
21: lastLine = super .readLine();
22: return lastLine;
23: }
24:
25: public String getLastLineCached() {
26: return lastLine;
27: }
28:
29: public int getLineNumber() {
30: return lineNumber;
31: }
32:
33: }
|