Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comments #15

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/org/apache/commons/csv/CSVParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static class Builder extends AbstractStreamBuilder<CSVParser, Builder> {
private CSVFormat format;
private long characterOffset;
private long recordNumber = 1;
private boolean enableByteTracking = false;
private boolean enableByteTracking;

/**
* Constructs a new instance.
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/csv/CSVRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
* <p>
* The Unicode characters are divided into two main ranges:
Expand All @@ -166,6 +175,10 @@ public int read() throws IOException {
* </ul>
* </li>
* </ul>
*
* @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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/csv/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ long getCharacterPosition() {
}

/**
* Returns the number of bytes read
* Gets the number of bytes read
*
* @return the number of bytes read
*/
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/commons/csv/CSVParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
Loading