Skip to content

Commit 96427fc

Browse files
committed
Migrate from deprecated code
CSVParser.Builder.recordNumber should default to 1
1 parent 20edd47 commit 96427fc

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,7 @@ public boolean isQuoteCharacterSet() {
20942094
* @throws CSVException Thrown on invalid input.
20952095
*/
20962096
public CSVParser parse(final Reader reader) throws IOException {
2097-
return new CSVParser(reader, this);
2097+
return CSVParser.builder().setReader(reader).setFormat(this).get();
20982098
}
20992099

21002100
/**

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static class Builder extends AbstractStreamBuilder<CSVParser, Builder> {
152152

153153
private CSVFormat format;
154154
private long characterOffset;
155-
private long recordNumber;
155+
private long recordNumber = 1;
156156

157157
/**
158158
* Constructs a new instance.
@@ -190,7 +190,7 @@ public Builder setFormat(final CSVFormat format) {
190190
}
191191

192192
/**
193-
* Sets the next record number to assign.
193+
* Sets the next record number to assign, defaults to {@code 1}.
194194
*
195195
* @param recordNumber the next record number to assign.
196196
* @return this instance.
@@ -377,7 +377,7 @@ public static CSVParser parse(final Path path, final Charset charset, final CSVF
377377
* @since 1.5
378378
*/
379379
public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException {
380-
return new CSVParser(reader, format);
380+
return builder().setReader(reader).setFormat(format).get();
381381
}
382382

383383
/**
@@ -397,8 +397,7 @@ public static CSVParser parse(final Reader reader, final CSVFormat format) throw
397397
public static CSVParser parse(final String string, final CSVFormat format) throws IOException {
398398
Objects.requireNonNull(string, "string");
399399
Objects.requireNonNull(format, "format");
400-
401-
return new CSVParser(new StringReader(string), format);
400+
return parse(new StringReader(string), format);
402401
}
403402

404403
/**
@@ -425,10 +424,7 @@ public static CSVParser parse(final String string, final CSVFormat format) throw
425424
@SuppressWarnings("resource")
426425
public static CSVParser parse(final URL url, final Charset charset, final CSVFormat format) throws IOException {
427426
Objects.requireNonNull(url, "url");
428-
Objects.requireNonNull(charset, "charset");
429-
Objects.requireNonNull(format, "format");
430-
431-
return new CSVParser(new InputStreamReader(url.openStream(), charset), format);
427+
return parse(url.openStream(), charset, format);
432428
}
433429

434430
private String headerComment;

0 commit comments

Comments
 (0)