diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index 31c7c33f..03f8142e 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -30,7 +30,8 @@ import java.io.Reader; * A special buffered reader which supports sophisticated read access. *

* In particular the reader supports a look-ahead option, which allows you to see the next char returned by - * {@link #read()}. + * {@link #read()}. This reader also tracks how many characters have been read with {@link #getPosition()}. + *

* * @version $Id$ */ @@ -42,6 +43,9 @@ final class ExtendedBufferedReader extends BufferedReader { /** The count of EOLs (CR/LF/CRLF) seen so far */ private long eolCounter = 0; + /** The position, which is number of characters read so far */ + private long position = 0; + private boolean closed; /** @@ -58,6 +62,7 @@ final class ExtendedBufferedReader extends BufferedReader { eolCounter++; } lastChar = current; + this.position++; return lastChar; } @@ -100,6 +105,7 @@ final class ExtendedBufferedReader extends BufferedReader { lastChar = END_OF_STREAM; } + position += len; return len; } @@ -157,6 +163,15 @@ final class ExtendedBufferedReader extends BufferedReader { return eolCounter + 1; // Allow for counter being incremented only at EOL } + /** + * Gets the character position in the reader. + * + * @return the current position in the reader (counting characters, not bytes since this is a Reader) + */ + long getPosition() { + return this.position; + } + public boolean isClosed() { return closed; }