diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index ba14b10210..2a82d48a5a 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -55,14 +55,11 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader { /** The number of bytes read so far */ private long bytesRead; + private long bytesReadMark; + /** Encoder used to calculate the bytes of characters */ CharsetEncoder encoder; - /** - * A flag to indicate if the read is a peek operation. - */ - private boolean isReadPeek; - /** * Constructs a new instance using the default buffer size. */ @@ -75,7 +72,6 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader { if (encoding != null) { encoder = Charset.forName(encoding).newEncoder(); } - isReadPeek = false; } /** @@ -130,6 +126,7 @@ public void mark(final int readAheadLimit) throws IOException { lineNumberMark = lineNumber; lastCharMark = lastChar; positionMark = position; + bytesReadMark = bytesRead; super.mark(readAheadLimit); } @@ -140,7 +137,7 @@ public int read() throws IOException { current == EOF && lastChar != CR && lastChar != LF && lastChar != EOF) { lineNumber++; } - if (encoder != null && !isReadPeek) { + if (encoder != null) { this.bytesRead += getCharBytes(current); } lastChar = current; @@ -241,6 +238,7 @@ public void reset() throws IOException { lineNumber = lineNumberMark; lastChar = lastCharMark; position = positionMark; + bytesRead = bytesReadMark; super.reset(); } @@ -253,20 +251,4 @@ long getBytesRead() { return this.bytesRead; } - /** - * Returns the next character in the current reader without consuming it. So the next call to {@link #read()} will still return this value. - * - * @return the next character - * @throws IOException If an I/O error occurs - */ - @Override - public int peek() throws IOException { - isReadPeek = true; - mark(1); - final int c = read(); - reset(); - isReadPeek = false; - return c; - } - } diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index 998e04cd93..f871308e8f 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -699,6 +699,7 @@ public void testGetRecordThreeBytesRead() throws Exception { "11111111111111,'4017-09-01',きちんと節分近くには咲いてる~,v4\n" + "22222222222222,'4017-01-01',おはよう私の友人~,v4\n" + "33333333333333,'4017-01-01',きる自然の力ってすごいな~,v4\n"; + // String code = "'1',4"; // final CSVFormat format = CSVFormat.newFormat(',').withQuote('\''); final CSVFormat format = CSVFormat.Builder.create() .setDelimiter(',')