27
28
29 /**
30 * A buffered character-input stream that keeps track of line numbers. This
31 * class defines methods {@link #setLineNumber(int)} and {@link
32 * #getLineNumber()} for setting and getting the current line number
33 * respectively.
34 *
35 * <p> By default, line numbering begins at 0. This number increments at every
36 * <a href="#lt">line terminator</a> as the data is read, and can be changed
37 * with a call to <tt>setLineNumber(int)</tt>. Note however, that
38 * <tt>setLineNumber(int)</tt> does not actually change the current position in
39 * the stream; it only changes the value that will be returned by
40 * <tt>getLineNumber()</tt>.
41 *
42 * <p> A line is considered to be <a name="lt">terminated</a> by any one of a
43 * line feed ('\n'), a carriage return ('\r'), or a carriage return followed
44 * immediately by a linefeed.
45 *
46 * @author Mark Reinhold
47 * @since JDK1.1
48 */
49
50 public class LineNumberReader extends BufferedReader {
51
52 /** The current line number */
53 private int lineNumber = 0;
54
55 /** The line number of the mark, if any */
56 private int markedLineNumber; // Defaults to 0
57
58 /** If the next character is a line feed, skip it */
59 private boolean skipLF;
60
61 /** The skipLF flag when the mark was set */
62 private boolean markedSkipLF;
63
64 /**
65 * Create a new line-numbering reader, using the default input-buffer
66 * size.
67 *
|
27
28
29 /**
30 * A buffered character-input stream that keeps track of line numbers. This
31 * class defines methods {@link #setLineNumber(int)} and {@link
32 * #getLineNumber()} for setting and getting the current line number
33 * respectively.
34 *
35 * <p> By default, line numbering begins at 0. This number increments at every
36 * <a href="#lt">line terminator</a> as the data is read, and can be changed
37 * with a call to <tt>setLineNumber(int)</tt>. Note however, that
38 * <tt>setLineNumber(int)</tt> does not actually change the current position in
39 * the stream; it only changes the value that will be returned by
40 * <tt>getLineNumber()</tt>.
41 *
42 * <p> A line is considered to be <a name="lt">terminated</a> by any one of a
43 * line feed ('\n'), a carriage return ('\r'), or a carriage return followed
44 * immediately by a linefeed.
45 *
46 * @author Mark Reinhold
47 * @since 1.1
48 */
49
50 public class LineNumberReader extends BufferedReader {
51
52 /** The current line number */
53 private int lineNumber = 0;
54
55 /** The line number of the mark, if any */
56 private int markedLineNumber; // Defaults to 0
57
58 /** If the next character is a line feed, skip it */
59 private boolean skipLF;
60
61 /** The skipLF flag when the mark was set */
62 private boolean markedSkipLF;
63
64 /**
65 * Create a new line-numbering reader, using the default input-buffer
66 * size.
67 *
|