Skip to content

Commit b63a788

Browse files
committed
2 parents e100d62 + 15a38a4 commit b63a788

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
* </p>
9494
*
9595
* <pre>{@code
96-
* CSVFormat.EXCEL.withNullString("N/A").withIgnoreSurroundingSpaces(true);
96+
* CSVFormat.EXCEL.builder().setNullString("N/A").setIgnoreSurroundingSpaces(true).get();
9797
* }</pre>
9898
*
9999
* <h2>Defining column names</h2>
@@ -103,7 +103,7 @@
103103
* </p>
104104
*
105105
* <pre>{@code
106-
* CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3");
106+
* CSVFormat.EXCEL.builder().setHeader("Col1", "Col2", "Col3").get();
107107
* }</pre>
108108
*
109109
* <p>
@@ -122,7 +122,7 @@
122122
*
123123
* <pre>{@code
124124
* Reader in = ...;
125-
* CSVFormat.EXCEL.withHeader("Col1", "Col2", "Col3").parse(in);
125+
* CSVFormat.EXCEL.builder().setHeader("Col1", "Col2", "Col3").get().parse(in);
126126
* }</pre>
127127
*
128128
* <p>
@@ -137,7 +137,7 @@
137137
* </p>
138138
*
139139
* <pre>
140-
* CSVFormat.EXCEL.withHeader();
140+
* CSVFormat.EXCEL.builder().setHeader().get();
141141
* </pre>
142142
*
143143
* <p>
@@ -993,7 +993,7 @@ public CSVFormat getFormat() {
993993
* </p>
994994
*
995995
* <pre>
996-
* CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';');
996+
* CSVFormat fmt = CSVFormat.EXCEL.builder().setDelimiter(';').get();
997997
* </pre>
998998
*
999999
* <p>
@@ -2693,6 +2693,7 @@ public CSVFormat withEscape(final Character escape) {
26932693
return builder().setEscape(escape).get();
26942694
}
26952695

2696+
// @formatter:off
26962697
/**
26972698
* Builds a new {@code CSVFormat} using the first record as header.
26982699
*
@@ -2701,7 +2702,10 @@ public CSVFormat withEscape(final Character escape) {
27012702
* </p>
27022703
*
27032704
* <pre>
2704-
* CSVFormat format = aFormat.withHeader().withSkipHeaderRecord();
2705+
* CSVFormat format = aFormat.builder()
2706+
* .setHeader()
2707+
* .setSkipHeaderRecord(true)
2708+
* .get();
27052709
* </pre>
27062710
*
27072711
* @return A new CSVFormat that is equal to this but using the first record as header.
@@ -2710,6 +2714,7 @@ public CSVFormat withEscape(final Character escape) {
27102714
* @since 1.3
27112715
* @deprecated Use {@link Builder#setHeader(String...) Builder#setHeader()}.{@link Builder#setSkipHeaderRecord(boolean) setSkipHeaderRecord(true)}.
27122716
*/
2717+
// @formatter:on
27132718
@Deprecated
27142719
public CSVFormat withFirstRecordAsHeader() {
27152720
// @formatter:off
@@ -2728,11 +2733,11 @@ public CSVFormat withFirstRecordAsHeader() {
27282733
* </p>
27292734
*
27302735
* <pre>
2731-
* public enum Header {
2736+
* public enum MyHeader {
27322737
* Name, Email, Phone
27332738
* }
2734-
*
2735-
* CSVFormat format = aformat.withHeader(Header.class);
2739+
* ...
2740+
* CSVFormat format = aFormat.builder().setHeader(MyHeader.class).get();
27362741
* </pre>
27372742
* <p>
27382743
* The header is also used by the {@link CSVPrinter}.
@@ -2755,13 +2760,13 @@ public CSVFormat withHeader(final Class<? extends Enum<?>> headerEnum) {
27552760
* input file with:
27562761
*
27572762
* <pre>
2758-
* CSVFormat format = aformat.withHeader();
2763+
* CSVFormat format = aFormat.builder().setHeader().get();
27592764
* </pre>
27602765
*
27612766
* or specified manually with:
27622767
*
27632768
* <pre>
2764-
* CSVFormat format = aformat.withHeader(resultSet);
2769+
* CSVFormat format = aFormat.builder().setHeader(resultSet).get();
27652770
* </pre>
27662771
* <p>
27672772
* The header is also used by the {@link CSVPrinter}.
@@ -2783,13 +2788,13 @@ public CSVFormat withHeader(final ResultSet resultSet) throws SQLException {
27832788
* input file with:
27842789
*
27852790
* <pre>
2786-
* CSVFormat format = aformat.withHeader();
2791+
* CSVFormat format = aFormat.builder().setHeader().get()
27872792
* </pre>
27882793
*
27892794
* or specified manually with:
27902795
*
27912796
* <pre>
2792-
* CSVFormat format = aformat.withHeader(metaData);
2797+
* CSVFormat format = aFormat.builder().setHeader(resultSetMetaData).get()
27932798
* </pre>
27942799
* <p>
27952800
* The header is also used by the {@link CSVPrinter}.
@@ -2811,13 +2816,13 @@ public CSVFormat withHeader(final ResultSetMetaData resultSetMetaData) throws SQ
28112816
* with:
28122817
*
28132818
* <pre>
2814-
* CSVFormat format = aformat.withHeader();
2819+
* CSVFormat format = aFormat.builder().setHeader().get();
28152820
* </pre>
28162821
*
28172822
* or specified manually with:
28182823
*
28192824
* <pre>{@code
2820-
* CSVFormat format = aformat.withHeader("name", "email", "phone");
2825+
* CSVFormat format = aFormat.builder().setHeader("name", "email", "phone").get();
28212826
* }</pre>
28222827
* <p>
28232828
* The header is also used by the {@link CSVPrinter}.
@@ -2838,7 +2843,7 @@ public CSVFormat withHeader(final String... header) {
28382843
* This setting is ignored by the parser.
28392844
*
28402845
* <pre>{@code
2841-
* CSVFormat format = aformat.withHeaderComments("Generated by Apache Commons CSV.", Instant.now());
2846+
* CSVFormat format = aFormat.builder().setHeaderComments("Generated by Apache Commons CSV.", Instant.now()).get();
28422847
* }</pre>
28432848
*
28442849
* @param headerComments the headerComments which will be printed by the Printer before the actual CSV data.

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
6060
private long bytesReadMark;
6161

6262
/** Encoder for calculating the number of bytes for each character read. */
63-
private CharsetEncoder encoder;
63+
private final CharsetEncoder encoder;
6464

6565
/**
6666
* Constructs a new instance using the default buffer size.
6767
*/
6868
ExtendedBufferedReader(final Reader reader) {
69-
super(reader);
69+
this(reader, null, false);
7070
}
7171

7272
/**
@@ -80,9 +80,7 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
8080
*/
8181
ExtendedBufferedReader(final Reader reader, final Charset charset, final boolean trackBytes) {
8282
super(reader);
83-
if (charset != null && trackBytes) {
84-
encoder = charset.newEncoder();
85-
}
83+
encoder = charset != null && trackBytes ? charset.newEncoder() : null;
8684
}
8785

8886
/**
@@ -137,15 +135,13 @@ private int getEncodedCharLength(final int current) throws CharacterCodingExcept
137135
final char cChar = (char) current;
138136
final char lChar = (char) lastChar;
139137
if (!Character.isSurrogate(cChar)) {
140-
return encoder.encode(
141-
CharBuffer.wrap(new char[] {cChar})).limit();
138+
return encoder.encode(CharBuffer.wrap(new char[] { cChar })).limit();
142139
}
143140
if (Character.isHighSurrogate(cChar)) {
144141
// Move on to the next char (low surrogate)
145142
return 0;
146143
} else if (Character.isSurrogatePair(lChar, cChar)) {
147-
return encoder.encode(
148-
CharBuffer.wrap(new char[] {lChar, cChar})).limit();
144+
return encoder.encode(CharBuffer.wrap(new char[] { lChar, cChar })).limit();
149145
} else {
150146
throw new CharacterCodingException();
151147
}

0 commit comments

Comments
 (0)