Skip to content

Commit 5b6cba0

Browse files
committed
[CSV-306] followup to fix deprecated method in user guide
1 parent e0d3660 commit 5b6cba0

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

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)