de.unkrig.commons.io
Class CountingReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by de.unkrig.commons.io.CountingReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class CountingReader
extends java.io.FilterReader

A FilterReader that counts characters and line breaks in the stream. As usual, a line break is either a '\r', a '\n', or a sequence "\r\n".

See Also:
offset(), lineNumber(), columnNumber()

Field Summary
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
CountingReader(java.io.Reader in)
           
 
Method Summary
 int columnNumber()
          Returns the column number of the previously read character, or '0' if no character has been read yet.
 int lineNumber()
          Returns the line number of the previously read character, or '1' if no character has been read yet.
 int offset()
           
 int read()
           
 int read(char[] cbuf, int off, int len)
           
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset, skip
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CountingReader

public CountingReader(java.io.Reader in)
Method Detail

offset

public int offset()
Returns:
The number of characters read so far

lineNumber

public int lineNumber()
Returns the line number of the previously read character, or '1' if no character has been read yet.

If the previously read character is CR or LF, then the result is the number of the line following the line separator.


columnNumber

public int columnNumber()
Returns the column number of the previously read character, or '0' if no character has been read yet. The column number of the first character in a line is '1'.

If the previously read character is CR or LF, then the result is '0'.


read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.FilterReader
Throws:
java.io.IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.FilterReader
Throws:
java.io.IOException