You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2014/09/17 04:57:47 UTC
svn commit: r1625455 -
/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Author: ggregory
Date: Wed Sep 17 02:57:46 2014
New Revision: 1625455
URL: http://svn.apache.org/r1625455
Log:
[CSV-131] Save positions of records to enable random access. First commit for this new feature. Let the ExtendedBufferedReader track how many characters it has read so far.
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java?rev=1625455&r1=1625454&r2=1625455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java Wed Sep 17 02:57:46 2014
@@ -30,7 +30,8 @@ import java.io.Reader;
* A special buffered reader which supports sophisticated read access.
* <p>
* 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()}.
+ * </p>
*
* @version $Id$
*/
@@ -42,6 +43,9 @@ final class ExtendedBufferedReader exten
/** 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 exten
eolCounter++;
}
lastChar = current;
+ this.position++;
return lastChar;
}
@@ -100,6 +105,7 @@ final class ExtendedBufferedReader exten
lastChar = END_OF_STREAM;
}
+ position += len;
return len;
}
@@ -157,6 +163,15 @@ final class ExtendedBufferedReader exten
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;
}