Skip to content

Commit 6583991

Browse files
committed
Merge branch 'pr-325'
This closes apache#325
2 parents e0d3660 + 2835005 commit 6583991

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<action type="fix" dev="ggregory" due-to="Mykola Faryma">Validate input to setDelimiter(String) for empty string #266.</action>
5757
<action type="fix" dev="ggregory" due-to="Dependabot">Bump CSVFormat#serialVersionUID from 1 to 2.</action>
5858
<action type="fix" dev="ggregory" due-to="Alex Herbert">CSVParser: Identify duplicates in null, empty and blank header names #279.</action>
59-
<action issue="CSV-306" type="fix" dev="ggregory" due-to="Sam Ng, Bruno P. Kinoshita">Replace deprecated method in user guide, update external link #324.</action>
59+
<action issue="CSV-306" type="fix" dev="ggregory" due-to="Sam Ng, Bruno P. Kinoshita">Replace deprecated method in user guide, update external link #324, #325.</action>
6060
<!-- REMOVE -->
6161
<action type="remove" dev="ggregory">Serialization in CSVFormat is not supported from one version to the next.</action>
6262
<!-- ADD -->

src/site/xdoc/user-guide.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ for (CSVRecord record : records) {
7272
</p>
7373
<source>final URL url = ...;
7474
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
75-
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
75+
final CSVParser parser = CSVFormat.EXCEL.builder().setHeader().build().parse(reader);
7676
try {
7777
for (final CSVRecord record : parser) {
7878
final String string = record.get("SomeColumn");
@@ -118,7 +118,7 @@ for (CSVRecord record : records) {
118118
Indices may not be the most intuitive way to access record values. For this reason it is possible to
119119
assign names to each column in the file:
120120
<source>Reader in = new FileReader(&quot;path/to/file.csv&quot;);
121-
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.withHeader("ID", "CustomerNo", "Name").parse(in);
121+
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.builder().setHeader("ID", "CustomerNo", "Name").build().parse(in);
122122
for (CSVRecord record : records) {
123123
String id = record.get("ID");
124124
String customerNo = record.get("CustomerNo");
@@ -136,7 +136,7 @@ for (CSVRecord record : records) {
136136
ID, CustomerNo, Name
137137
}
138138
Reader in = new FileReader(&quot;path/to/file.csv&quot;);
139-
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.withHeader(Headers.class).parse(in);
139+
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.builder().setHeader(Headers.class).build().parse(in);
140140
for (CSVRecord record : records) {
141141
String id = record.get(Headers.ID);
142142
String customerNo = record.get(Headers.CustomerNo);
@@ -149,7 +149,7 @@ for (CSVRecord record : records) {
149149
Some CSV files define header names in their first record. If configured, Apache Commons CSV can parse
150150
the header names from the first record:
151151
<source>Reader in = new FileReader(&quot;path/to/file.csv&quot;);
152-
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.withHeader().withSkipHeaderRecord(true).parse(in);
152+
Iterable&lt;CSVRecord&gt; records = CSVFormat.RFC4180.builder().setHeader().setSkipHeaderRecord(true).build().parse(in);
153153
for (CSVRecord record : records) {
154154
String id = record.get("ID");
155155
String customerNo = record.get("CustomerNo");
@@ -163,13 +163,13 @@ for (CSVRecord record : records) {
163163
To print a CSV file with headers, you specify the headers in the format:
164164
</p>
165165
<source>final Appendable out = ...;
166-
final CSVPrinter printer = CSVFormat.DEFAULT.withHeader("H1", "H2").print(out)
166+
final CSVPrinter printer = CSVFormat.DEFAULT.builder().setHeader("H1", "H2").build().print(out);
167167
</source>
168168
<p>
169169
To print a CSV file with JDBC column labels, you specify the ResultSet in the format:
170170
</p>
171171
<source>final ResultSet resultSet = ...;
172-
final CSVPrinter printer = CSVFormat.DEFAULT.withHeader(resultSet).print(out)
172+
final CSVPrinter printer = CSVFormat.DEFAULT.builder().setHeader(resultSet).build().print(out);
173173
</source>
174174
</subsection>
175175
</section>

0 commit comments

Comments
 (0)