diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index d3d8c9f3da..9ff28a96ae 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -153,7 +153,7 @@ public static class Builder extends AbstractStreamBuilder { private CSVFormat format; private long characterOffset; private long recordNumber = 1; - private boolean enableByteTracking = false; + private boolean enableByteTracking; /** * Constructs a new instance. @@ -201,6 +201,12 @@ public Builder setRecordNumber(final long recordNumber) { return asThis(); } + /** + * Sets whether to enable byte tracking for the parser. + * + * @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it. + * @return this instance. + */ public Builder setEnableByteTracking(final boolean enableByteTracking) { this.enableByteTracking = enableByteTracking; return asThis(); diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java index f0a0a6b816..54c88812f0 100644 --- a/src/main/java/org/apache/commons/csv/CSVRecord.java +++ b/src/main/java/org/apache/commons/csv/CSVRecord.java @@ -160,7 +160,7 @@ public long getCharacterPosition() { } /** - * Returns the start byte of this record as a character byte in the source stream. + * Gets the start byte of this record as a character byte in the source stream * * @return the start byte of this record as a character byte in the source stream. */ diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index a64868b39b..61f6ae2f3e 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -67,6 +67,15 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader { super(reader); } + /** + * Constructs a new instance with the specified reader, character set, + * and byte tracking option. Initializes an encoder if byte tracking is enabled + * and a character set is provided. + * + * @param reader the reader supports a look-ahead option. + * @param charset the character set for encoding, or {@code null} if not applicable. + * @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it. + */ ExtendedBufferedReader(final Reader reader, Charset charset, boolean enableByteTracking) { super(reader); if (charset != null && enableByteTracking) { @@ -146,7 +155,7 @@ public int read() throws IOException { } /** - * In Java, the {@code char} data type is based on the original Unicode + * Gets the byte length of the given character based on the the original Unicode * specification, which defined characters as fixed-width 16-bit entities. *

* The Unicode characters are divided into two main ranges: @@ -166,6 +175,10 @@ public int read() throws IOException { * * * + * + * @param current the current character to process. + * @return the byte length of the character. + * @throws CharacterCodingException if the character cannot be encoded. */ private long getCharBytes(int current) throws CharacterCodingException { final char cChar = (char) current; diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index afbba4d21d..3f14b2d883 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -104,7 +104,7 @@ long getCharacterPosition() { } /** - * Returns the number of bytes read + * Gets the number of bytes read * * @return the number of bytes read */ diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index 219e5e5fa5..7e3cafa65c 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -703,7 +703,7 @@ public void testGetHeaderComment_NoComment3() throws IOException { @Test public void testGetRecordThreeBytesRead() throws Exception { - String code = "id,date,val5,val4\n" + + final String code = "id,date,val5,val4\n" + "11111111111111,'4017-09-01',きちんと節分近くには咲いてる~,v4\n" + "22222222222222,'4017-01-01',おはよう私の友人~,v4\n" + "33333333333333,'4017-01-01',きる自然の力ってすごいな~,v4\n"; @@ -740,7 +740,7 @@ public void testGetRecordThreeBytesRead() throws Exception { @Test public void testGetRecordFourBytesRead() throws Exception { - String code = "id,a,b,c\n" + + final String code = "id,a,b,c\n" + "1,😊,🤔,😂\n" + "2,😊,🤔,😂\n" + "3,😊,🤔,😂\n";