Skip to content

Commit d403084

Browse files
authored
CSV-196: Comments changes on Dec30 (#17)
1 parent 110fea8 commit d403084

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public Builder setRecordNumber(final long recordNumber) {
208208
*
209209
* @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it.
210210
* @return this instance.
211+
* @since 1.13.0
211212
*/
212213
public Builder setEnableByteTracking(final boolean enableByteTracking) {
213214
this.enableByteTracking = enableByteTracking;
@@ -885,7 +886,7 @@ CSVRecord nextRecord() throws IOException {
885886
recordList.clear();
886887
StringBuilder sb = null;
887888
final long startCharPosition = lexer.getCharacterPosition() + characterOffset;
888-
final long startCharByte = lexer.getBytesRead() + this.characterOffset;
889+
final long startBytePosition = lexer.getBytesRead() + this.characterOffset;
889890
do {
890891
reusableToken.reset();
891892
lexer.nextToken(reusableToken);
@@ -923,7 +924,7 @@ CSVRecord nextRecord() throws IOException {
923924
recordNumber++;
924925
final String comment = Objects.toString(sb, null);
925926
result = new CSVRecord(this, recordList.toArray(Constants.EMPTY_STRING_ARRAY), comment,
926-
recordNumber, startCharPosition, startCharByte);
927+
recordNumber, startCharPosition, startBytePosition);
927928
}
928929
return result;
929930
}

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
5151
private final long characterPosition;
5252

5353
/**
54-
* The start byte of this record as a character byte in the source stream.
54+
* The starting position of this record in the source stream, measured in bytes.
5555
*/
5656
private final long bytePosition;
5757

@@ -152,9 +152,10 @@ public long getCharacterPosition() {
152152
}
153153

154154
/**
155-
* Gets the start byte of this record as a character byte in the source stream
155+
* Returns the starting position of this record in the source stream, measured in bytes.
156156
*
157-
* @return the start byte of this record as a character byte in the source stream.
157+
* @return the byte position of this record in the source stream.
158+
* @since 1.13.0
158159
*/
159160
public long getBytePosition() {
160161
return bytePosition;

src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ private int getEncodedCharLength(int current) throws CharacterCodingException {
195195
} else if (Character.isSurrogatePair(lChar, cChar)) {
196196
return encoder.encode(
197197
CharBuffer.wrap(new char[] {lChar, cChar})).limit();
198-
} else throw new CharacterCodingException();
198+
} else {
199+
throw new CharacterCodingException();
200+
}
199201
}
200202
}
201203

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,7 @@ public void testGetRecordThreeBytesRead() throws Exception {
736736
assertEquals(4, record.getRecordNumber());
737737
assertEquals(code.indexOf('3'), record.getCharacterPosition());
738738
assertEquals(record.getBytePosition(), 154);
739-
};
740-
739+
}
741740
}
742741

743742
@Test

src/test/java/org/apache/commons/csv/JiraCsv196Test.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
89
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* https://www.apache.org/licenses/LICENSE-2.0
1011
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
1618
*/
1719
package org.apache.commons.csv;
1820
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,13 +35,13 @@ public void parseThreeBytes() throws IOException {
3335
.setDelimiter(',')
3436
.setQuote('\'')
3537
.get();
36-
CSVParser parser = new CSVParser.Builder()
38+
final CSVParser parser = new CSVParser.Builder()
3739
.setFormat(format)
3840
.setReader(getTestInput("org/apache/commons/csv/CSV-196/japanese.csv"))
3941
.setCharset(StandardCharsets.UTF_8)
4042
.setEnableByteTracking(true)
4143
.get();
42-
long[] charByteKey = {0, 89, 242, 395};
44+
final long[] charByteKey = {0, 89, 242, 395};
4345
int idx = 0;
4446
for (CSVRecord record : parser) {
4547
assertEquals(charByteKey[idx++], record.getBytePosition());
@@ -54,13 +56,13 @@ public void parseFourBytes() throws IOException {
5456
.setDelimiter(',')
5557
.setQuote('\'')
5658
.get();
57-
CSVParser parser = new CSVParser.Builder()
59+
final CSVParser parser = new CSVParser.Builder()
5860
.setFormat(format)
5961
.setReader(getTestInput("org/apache/commons/csv/CSV-196/emoji.csv"))
6062
.setCharset(StandardCharsets.UTF_8)
6163
.setEnableByteTracking(true)
6264
.get();
63-
long[] charByteKey = {0, 84, 701, 1318, 1935};
65+
final long[] charByteKey = {0, 84, 701, 1318, 1935};
6466
int idx = 0;
6567
for (CSVRecord record : parser) {
6668
assertEquals(charByteKey[idx++], record.getBytePosition());

0 commit comments

Comments
 (0)