This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new 4bd1b5ce Correct and complete CSVFormat Javadoc
4bd1b5ce is described below
commit 4bd1b5cecec72a7af05fa13d49c882cf2f855a48
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Nov 29 12:03:20 2026 -0500
Correct and complete CSVFormat Javadoc
Match predefined format descriptions to their configured settings.
Clarify null conversion, duplicate headers, trimming, streamed values,
and header and comment output.
Fix examples, exception documentation, and cross-references. Complete
private member documentation and normalize wording, punctuation,
paragraph formatting, and block-tag order.
---
.../java/org/apache/commons/csv/CSVFormat.java | 919 +++++++++++++++------
1 file changed, 673 insertions(+), 246 deletions(-)
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 8ae1f74e..43c8abcb 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -121,12 +121,12 @@ import
org.apache.commons.io.output.AppendableOutputStream;
* <h2>Parsing</h2>
*
* <p>
- * You can use a format directly to parse a reader. For example, to parse an
Excel file with columns header, write:
+ * You can use a format directly to parse a reader. For example, to parse an
Excel CSV file whose first record contains column names, write:
* </p>
*
* <pre>{@code
* Reader in = ...;
- * CSVFormat.EXCEL.builder().setHeader("Col1", "Col2", "Col3").get().parse(in);
+ * CSVFormat.EXCEL.builder().setHeader().get().parse(in);
* }</pre>
*
* <p>
@@ -147,7 +147,7 @@ import org.apache.commons.io.output.AppendableOutputStream;
* <p>
* This causes the parser to read the first record and use its values as
column names.
*
- * Then, call one of the {@link CSVRecord} get method that takes a String
column name argument:
+ * Then, call {@link CSVRecord#get(String)} with a column name:
* </p>
*
* <pre>{@code
@@ -159,25 +159,31 @@ import
org.apache.commons.io.output.AppendableOutputStream;
* </p>
*
* <h2>Serialization</h2>
+ *
* <p>
* This class implements the {@link Serializable} interface with the following
caveats:
* </p>
+ *
* <ul>
* <li>This class will no longer implement Serializable in 2.0.</li>
* <li>Serialization is not supported from one version to the next.</li>
* </ul>
+ *
* <p>
* The {@code serialVersionUID} values are:
* </p>
+ *
* <ul>
* <li>Version 1.10.0: {@code 2L}</li>
* <li>Version 1.9.0 through 1.0: {@code 1L}</li>
* </ul>
*
* <h2>Notes</h2>
+ *
* <p>
* This class is immutable.
* </p>
+ *
* <p>
* Not all settings are used for both parsing and writing.
* </p>
@@ -197,6 +203,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code
(',')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('"')}</li>
@@ -206,10 +213,9 @@ public final class CSVFormat implements Serializable {
* <li>All other values take their Java defaults, {@code false} for
booleans, {@code null} for object references.</li>
* </ul>
*
+ * @return A new builder with the default settings.
* @see Predefined#Default
* @see DuplicateHeaderMode#ALLOW_ALL
- *
- * @return A copy of the builder
*/
public static Builder create() {
// @formatter:off
@@ -232,55 +238,128 @@ public final class CSVFormat implements Serializable {
return new Builder(csvFormat);
}
+ /**
+ * Whether missing column names are allowed when parsing headers.
+ */
private boolean allowMissingColumnNames;
+ /**
+ * Whether printers flush before closing.
+ */
private boolean autoFlush;
+ /**
+ * The comment marker, or null if comments are disabled.
+ */
private Character commentMarker;
+ /**
+ * The string separating field values.
+ */
private String delimiter;
+ /**
+ * How duplicate header names are handled.
+ */
private DuplicateHeaderMode duplicateHeaderMode;
+ /**
+ * The escape character, or null if no separate escape character is
configured.
+ */
private Character escapeCharacter;
+ /**
+ * The comment lines to print before the header and data.
+ */
private String[] headerComments;
+ /**
+ * The column names, null if disabled, or an empty array to read names
from the input.
+ */
private String[] headers;
+ /**
+ * Whether empty input lines are ignored.
+ */
private boolean ignoreEmptyLines;
+ /**
+ * Whether header names are matched ignoring case.
+ */
private boolean ignoreHeaderCase;
+ /**
+ * Whether surrounding spaces are ignored while parsing unquoted
values.
+ */
private boolean ignoreSurroundingSpaces;
+ /**
+ * The string representing null values, or null if unset.
+ */
private String nullString;
+ /**
+ * The quote character, or null if quoting is disabled.
+ */
private Character quoteCharacter;
+ /**
+ * The cached null string enclosed in quote characters.
+ */
private String quotedNullString;
+ /**
+ * The quote policy for output and null-value parsing.
+ */
private QuoteMode quoteMode;
+ /**
+ * The separator written between records, or null if unset.
+ */
private String recordSeparator;
+ /**
+ * Whether to skip an input header when names are supplied and
suppress the printed header.
+ */
private boolean skipHeaderRecord;
+ /**
+ * Whether end-of-file is accepted inside a quoted value.
+ */
private boolean lenientEof;
+ /**
+ * Whether data after the closing quote of a field is accepted.
+ */
private boolean trailingData;
+ /**
+ * Whether to write trailing delimiters and drop the resulting empty
field when parsing.
+ */
private boolean trailingDelimiter;
+ /**
+ * Whether parsed and non-streamed printed values are trimmed.
+ */
private boolean trim;
- /** The maximum number of rows to process, excluding the header row. */
+ /**
+ * The maximum number of rows to process, excluding the header row.
+ */
private long maxRows;
+ /**
+ * Creates a builder with Java default values for all settings.
+ */
private Builder() {
// empty
}
+ /**
+ * Creates a builder initialized from a format.
+ *
+ * @param csvFormat The source format.
+ */
private Builder(final CSVFormat csvFormat) {
this.allowMissingColumnNames = csvFormat.allowMissingColumnNames;
this.autoFlush = csvFormat.autoFlush;
@@ -310,6 +389,7 @@ public final class CSVFormat implements Serializable {
* Builds a new CSVFormat instance.
*
* @return A new CSVFormat instance.
+ * @throws IllegalArgumentException Thrown when any attribute is
invalid or inconsistent with other attributes.
* @deprecated Use {@link #get()}.
*/
@Deprecated
@@ -330,9 +410,15 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the duplicate header names behavior, true to allow, false to
disallow.
+ * Sets whether all duplicate header names are allowed.
*
- * @param allowDuplicateHeaderNames The duplicate header names
behavior, true to allow, false to disallow.
+ * <p>
+ * A value of {@code true} selects {@link
DuplicateHeaderMode#ALLOW_ALL}; {@code false} selects
+ * {@link DuplicateHeaderMode#ALLOW_EMPTY}, which still permits
duplicate null, empty, or blank names.
+ * Allowing missing names while parsing is controlled separately by
{@link #setAllowMissingColumnNames(boolean)}.
+ * </p>
+ *
+ * @param allowDuplicateHeaderNames {@code true} to allow all
duplicates, {@code false} to allow only duplicate missing names.
* @return This instance.
* @deprecated Use {@link
#setDuplicateHeaderMode(DuplicateHeaderMode)}.
*/
@@ -367,19 +453,24 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the comment marker character, use {@code null} to disable
comments.
+ * Sets the comment marker character.
+ *
* <p>
* The comment start character is only recognized at the start of a
line.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link #setCommentMarker(char)} or {@link
#setCommentMarker(Character)} to set the comment marker written at the start of
each comment line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are
ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -387,18 +478,20 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by
Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
*
- * @param commentMarker The comment start marker, use {@code null} to
disable.
+ * @param commentMarker The comment start marker.
* @return This instance.
- * @throws IllegalArgumentException thrown if the specified character
is a line break
+ * @throws IllegalArgumentException thrown if the specified character
is a line break.
+ * @see #setCommentMarker(Character)
*/
public Builder setCommentMarker(final char commentMarker) {
setCommentMarker(Character.valueOf(commentMarker));
@@ -407,18 +500,23 @@ public final class CSVFormat implements Serializable {
/**
* Sets the comment marker character, use {@code null} to disable
comments.
+ *
* <p>
* The comment start character is only recognized at the start of a
line.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link #setCommentMarker(char)} or {@link
#setCommentMarker(Character)} to set the comment marker written at the start of
each comment line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are
ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -426,18 +524,19 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by
Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
*
* @param commentMarker The comment start marker, use {@code null} to
disable.
* @return This instance.
- * @throws IllegalArgumentException thrown if the specified character
is a line break
+ * @throws IllegalArgumentException thrown if the specified character
is a line break.
*/
public Builder setCommentMarker(final Character commentMarker) {
if (isLineBreak(commentMarker)) {
@@ -459,11 +558,12 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the delimiter character.
+ * Sets the delimiter string.
*
- * @param delimiter The delimiter character.
+ * @param delimiter The non-empty delimiter string.
* @return This instance.
- * @throws IllegalArgumentException if the delimiter is a line break
or is empty.
+ * @throws IllegalArgumentException if the delimiter contains a line
break or is empty.
+ * @throws NullPointerException if the delimiter is {@code null}.
*/
public Builder setDelimiter(final String delimiter) {
if (containsLineBreak(delimiter)) {
@@ -479,7 +579,7 @@ public final class CSVFormat implements Serializable {
/**
* Sets the duplicate header names behavior.
*
- * @param duplicateHeaderMode The duplicate header names behavior
+ * @param duplicateHeaderMode The duplicate header names behavior.
* @return This instance.
* @throws NullPointerException if duplicateHeaderMode is null.
* @since 1.10.0
@@ -494,7 +594,7 @@ public final class CSVFormat implements Serializable {
*
* @param escapeCharacter The escape character.
* @return This instance.
- * @throws IllegalArgumentException thrown if the specified character
is a line break
+ * @throws IllegalArgumentException thrown if the specified character
is a line break.
*/
public Builder setEscape(final char escapeCharacter) {
setEscape(Character.valueOf(escapeCharacter));
@@ -506,7 +606,7 @@ public final class CSVFormat implements Serializable {
*
* @param escapeCharacter The escape character.
* @return This instance.
- * @throws IllegalArgumentException thrown if the specified character
is a line break
+ * @throws IllegalArgumentException thrown if the specified character
is a line break.
*/
public Builder setEscape(final Character escapeCharacter) {
if (isLineBreak(escapeCharacter)) {
@@ -528,13 +628,14 @@ public final class CSVFormat implements Serializable {
* Name, Email, Phone
* }
*
- * Builder builder = builder.setHeader(HeaderEnum.class);
+ * Builder builder =
CSVFormat.DEFAULT.builder().setHeader(HeaderEnum.class);
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param headerEnum The enum defining the header, {@code null} if
disabled, empty if parsed automatically, user-specified otherwise.
+ * @param headerEnum The enum defining the header, {@code null} to
disable the header, or an enum with no constants to read the header from the
input.
* @return This instance.
*/
public Builder setHeader(final Class<? extends Enum<?>> headerEnum) {
@@ -559,13 +660,14 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setHeader(resultSet);
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param resultSet The resultSet for the header, {@code null} if
disabled, empty if parsed automatically, user-specified otherwise.
+ * @param resultSet The result set whose column labels define the
header, or {@code null} to disable the header.
* @return This instance.
- * @throws SQLException SQLException if a database access error occurs
or this method is called on a closed result set.
+ * @throws SQLException if a database access error occurs or this
method is called on a closed result set.
*/
public Builder setHeader(final ResultSet resultSet) throws
SQLException {
return setHeader(resultSet != null ? resultSet.getMetaData() :
null);
@@ -583,13 +685,14 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setHeader(resultSetMetaData);
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param resultSetMetaData The metaData for the header, {@code null}
if disabled, empty if parsed automatically, user-specified otherwise.
+ * @param resultSetMetaData The metadata whose column labels define
the header, or {@code null} to disable the header.
* @return This instance.
- * @throws SQLException SQLException if a database access error occurs
or this method is called on a closed result set.
+ * @throws SQLException if a database access error occurs or this
method is called on a closed result set.
*/
public Builder setHeader(final ResultSetMetaData resultSetMetaData)
throws SQLException {
String[] labels = null;
@@ -615,9 +718,11 @@ public final class CSVFormat implements Serializable {
* <pre>{@code
* builder.setHeader("name", "email", "phone");
* }</pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
+ *
* <p>
* This method keeps a copy of the input array.
* </p>
@@ -632,18 +737,23 @@ public final class CSVFormat implements Serializable {
/**
* Sets the header comments to write before the CSV data.
+ *
* <p>
* This setting is ignored by the parser.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link #setCommentMarker(char)} or {@link
#setCommentMarker(Character)} to set the comment marker written at the start of
each comment line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are
ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -651,14 +761,16 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by
Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
+ *
* <p>
* This method keeps a copy of the input array.
* </p>
@@ -673,18 +785,23 @@ public final class CSVFormat implements Serializable {
/**
* Sets the header comments to write before the CSV data.
+ *
* <p>
* This setting is ignored by the parser.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link #setCommentMarker(char)} or {@link
#setCommentMarker(Character)} to set the comment marker written at the start of
each comment line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are
ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -692,14 +809,16 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by
Apache Commons CSV", Instant.ofEpochMilli(0).toString());
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
+ *
* <p>
* This method keeps a copy of the input array.
* </p>
@@ -726,9 +845,9 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the parser case mapping behavior, {@code true} to access
name/values, {@code false} to leave the mapping as is.
+ * Sets whether header names are matched ignoring case when parsing.
*
- * @param ignoreHeaderCase The case mapping behavior, {@code true} to
access name/values, {@code false} to leave the mapping as is.
+ * @param ignoreHeaderCase Whether header names are matched ignoring
case.
* @return This instance.
*/
public Builder setIgnoreHeaderCase(final boolean ignoreHeaderCase) {
@@ -761,6 +880,7 @@ public final class CSVFormat implements Serializable {
/**
* Sets the maximum number of rows to process, excluding the header
row.
+ *
* <p>
* Values less than or equal to 0 mean no limit.
* </p>
@@ -775,14 +895,14 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the String to convert to and from {@code null}. No
substitution occurs if {@code null}.
+ * Sets the string used to represent {@code null} values.
*
- * <ul>
- * <li><strong>Reading:</strong> Converts strings equal to the given
{@code nullString} to {@code null} when reading records.</li>
- * <li><strong>Writing:</strong> Writes {@code null} as the given
{@code nullString} when writing records.</li>
- * </ul>
+ * <p>
+ * See {@link CSVFormat#getNullString()} for the conversion rules,
including how quoting and escaping affect parsing. Leaving the null string
unset does
+ * not disable the conversion of unquoted empty fields to {@code null}
with {@link QuoteMode#ALL_NON_NULL} or {@link QuoteMode#NON_NUMERIC}.
+ * </p>
*
- * @param nullString The String to convert to and from {@code null}.
No substitution occurs if {@code null}.
+ * @param nullString The null string, or {@code null} to leave the
null string unset.
* @return This instance.
*/
public Builder setNullString(final String nullString) {
@@ -795,6 +915,7 @@ public final class CSVFormat implements Serializable {
*
* @param quoteCharacter The quote character.
* @return This instance.
+ * @throws IllegalArgumentException If the quote character is a line
break.
*/
public Builder setQuote(final char quoteCharacter) {
setQuote(Character.valueOf(quoteCharacter));
@@ -806,6 +927,7 @@ public final class CSVFormat implements Serializable {
*
* @param quoteCharacter The quote character, use {@code null} to
disable.
* @return This instance.
+ * @throws IllegalArgumentException If the quote character is a line
break.
*/
public Builder setQuote(final Character quoteCharacter) {
if (isLineBreak(quoteCharacter)) {
@@ -815,6 +937,11 @@ public final class CSVFormat implements Serializable {
return setQuotedNullString();
}
+ /**
+ * Resets the quoted null string from the current settings, using
double quotes if no quote character is configured.
+ *
+ * @return This instance.
+ */
private Builder setQuotedNullString() {
final Character quote = quoteCharacter != null ? quoteCharacter :
Constants.DOUBLE_QUOTE_CHAR;
this.quotedNullString = quote + nullString + quote;
@@ -822,9 +949,14 @@ public final class CSVFormat implements Serializable {
}
/**
- * Sets the quote policy to use for output.
+ * Sets the quote policy used for output and null-value parsing.
+ *
+ * <p>
+ * This policy also affects null-value parsing with {@link
QuoteMode#ALL_NON_NULL} and {@link QuoteMode#NON_NUMERIC}.
+ * See {@link CSVFormat#getNullString()} for details.
+ * </p>
*
- * @param quoteMode The quote policy to use for output.
+ * @param quoteMode The quote policy, or {@code null} to use {@link
QuoteMode#MINIMAL} for output.
* @return This instance.
*/
public Builder setQuoteMode(final QuoteMode quoteMode) {
@@ -895,6 +1027,7 @@ public final class CSVFormat implements Serializable {
* that such a trailing delimiter produces is dropped so the output
round-trips back to the original record;
* a quoted empty trailing field ({@code ""}) is a real value rather
than a trailing delimiter and is kept.
* </p>
+ *
* <p>
* This is unrelated to {@link #setTrailingData(boolean) trailing
data}, which controls whether characters
* after the closing quote of an encapsulated value are tolerated when
reading.
@@ -914,6 +1047,7 @@ public final class CSVFormat implements Serializable {
*
* @param trim whether to trim leading and trailing blanks.
* @return This instance.
+ * @see CSVFormat#getTrim()
*/
public Builder setTrim(final boolean trim) {
this.trim = trim;
@@ -922,7 +1056,7 @@ public final class CSVFormat implements Serializable {
}
/**
- * Enumerates predefines formats.
+ * Enumerates predefined formats.
*
* @since 1.2
*/
@@ -945,32 +1079,32 @@ public final class CSVFormat implements Serializable {
/**
* The INFORMIX_UNLOAD predefined format.
*
- * @see CSVFormat#INFORMIX_UNLOAD
* @since 1.3
+ * @see CSVFormat#INFORMIX_UNLOAD
*/
InformixUnload(INFORMIX_UNLOAD),
/**
* The INFORMIX_UNLOAD_CSV predefined format.
*
- * @see CSVFormat#INFORMIX_UNLOAD_CSV
* @since 1.3
+ * @see CSVFormat#INFORMIX_UNLOAD_CSV
*/
InformixUnloadCsv(INFORMIX_UNLOAD_CSV),
/**
* The MONGODB_CSV predefined format.
*
- * @see CSVFormat#MONGODB_CSV
* @since 1.7
+ * @see CSVFormat#MONGODB_CSV
*/
MongoDBCsv(MONGODB_CSV),
/**
* The MONGODB_TSV predefined format.
*
- * @see CSVFormat#MONGODB_TSV
* @since 1.7
+ * @see CSVFormat#MONGODB_TSV
*/
MongoDBTsv(MONGODB_TSV),
@@ -991,8 +1125,8 @@ public final class CSVFormat implements Serializable {
/**
* The POSTGRESQL_CSV predefined format.
*
- * @see CSVFormat#POSTGRESQL_CSV
* @since 1.5
+ * @see CSVFormat#POSTGRESQL_CSV
*/
PostgreSQLCsv(POSTGRESQL_CSV),
@@ -1017,8 +1151,16 @@ public final class CSVFormat implements Serializable {
*/
TDF(CSVFormat.TDF);
+ /**
+ * The format represented by this enum constant.
+ */
private final CSVFormat format;
+ /**
+ * Creates a predefined format constant.
+ *
+ * @param format The represented format.
+ */
Predefined(final CSVFormat format) {
this.format = format;
}
@@ -1039,6 +1181,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('"')}</li>
@@ -1068,6 +1211,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('"')}</li>
@@ -1078,9 +1222,9 @@ public final class CSVFormat implements Serializable {
* <li>{@link Builder#setTrailingData(boolean) setTrailingData}{@code
(true)}</li>
* <li>{@link Builder#setLenientEof(boolean) setLenientEof}{@code
(true)}</li>
* </ul>
+ *
* <p>
- * Note: This is currently like {@link #RFC4180} plus {@link
Builder#setAllowMissingColumnNames(boolean)
Builder#setAllowMissingColumnNames(true)} and
- * {@link Builder#setIgnoreEmptyLines(boolean)
Builder#setIgnoreEmptyLines(false)}.
+ * Compared with {@link #RFC4180}, this format allows missing column
names, trailing data after quoted values, and end-of-file inside quoted values.
* </p>
*
* @see Predefined#Excel
@@ -1102,23 +1246,24 @@ public final class CSVFormat implements Serializable {
* format used by the {@code UNLOAD TO file_name} operation.
*
* <p>
- * This is a comma-delimited format with an LF character as the line
separator. Values are not quoted and special characters are escaped with {@code
'\'}.
- * The default NULL string is {@code "\\N"}.
+ * This is a pipe-delimited format with an LF character as the record
separator. Values are double quoted when needed, and special characters are
+ * escaped with {@code '\\'}. No null string is configured.
* </p>
*
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
- * <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
+ * <li>{@link Builder#setDelimiter(char) setDelimiter}{@code ('|')}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('\\')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('\"')}</li>
* <li>{@link Builder#setRecordSeparator(char) setRecordSeparator}{@code
('\n')}</li>
* </ul>
*
+ * @since 1.3
* @see Predefined#InformixUnload
* @see <a
href="https://www.ibm.com/docs/en/informix-servers/14.10?topic=statements-unload-statement">Informix
CSV UNLOAD</a>
- * @since 1.3
*/
// @formatter:off
public static final CSVFormat INFORMIX_UNLOAD = DEFAULT.builder()
@@ -1131,26 +1276,27 @@ public final class CSVFormat implements Serializable {
/**
* Default <a
href="https://www.ibm.com/docs/en/informix-servers/14.10?topic=statements-unload-statement">Informix
CSV UNLOAD</a>
- * format used by the {@code UNLOAD TO file_name} operation (escaping is
disabled.)
+ * format used by the {@code UNLOAD TO file_name} operation (no separate
escape character is configured).
*
* <p>
- * This is a comma-delimited format with an LF character as the line
separator. Values are not quoted and special characters are escaped with {@code
'\'}.
- * The default NULL string is {@code "\\N"}.
+ * This is a comma-delimited format with an LF character as the record
separator. Values are double quoted when needed, and embedded double quotes
+ * are doubled. No separate escape character or null string is configured.
* </p>
*
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('\"')}</li>
* <li>{@link Builder#setRecordSeparator(char) setRecordSeparator}{@code
('\n')}</li>
* </ul>
*
+ * @since 1.3
* @see Predefined#InformixUnloadCsv
* @see <a href=
"http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm">
*
http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm</a>
- * @since 1.3
*/
// @formatter:off
public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT.builder()
@@ -1162,6 +1308,7 @@ public final class CSVFormat implements Serializable {
/**
* Default MongoDB CSV format used by the {@code mongoexport} operation.
+ *
* <p>
* <strong>Parsing is not supported yet.</strong>
* </p>
@@ -1170,15 +1317,19 @@ public final class CSVFormat implements Serializable {
* This is a comma-delimited format. Values are double quoted only if
needed and special characters are escaped with {@code '"'}. A header line with
field
* names is expected.
* </p>
+ *
* <p>
* As of 2024-04-05, the MongoDB documentation for {@code mongoimport}
states:
* </p>
+ *
* <blockquote>The csv parser accepts that data that complies with RFC <a
href="https://tools.ietf.org/html/4180">RFC-4180</a>. As a result, backslashes
are
* not a valid escape character. If you use double-quotes to enclose
fields in the CSV data, you must escape internal double-quote marks by
prepending
* another double-quote. </blockquote>
+ *
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('"')}</li>
@@ -1186,10 +1337,10 @@ public final class CSVFormat implements Serializable {
* <li>{@link Builder#setQuoteMode(QuoteMode) setQuoteMode}{@code
(QuoteMode.MINIMAL)}</li>
* </ul>
*
- * @see Predefined#MongoDBTsv
- * @see QuoteMode#ALL_NON_NULL
- * @see <a
href="https://docs.mongodb.com/manual/reference/program/mongoexport/">MongoDB
mongoexport command documentation</a>
* @since 1.7
+ * @see Predefined#MongoDBCsv
+ * @see QuoteMode#MINIMAL
+ * @see <a
href="https://docs.mongodb.com/manual/reference/program/mongoexport/">MongoDB
mongoexport command documentation</a>
*/
// @formatter:off
public static final CSVFormat MONGODB_CSV = DEFAULT.builder()
@@ -1202,6 +1353,7 @@ public final class CSVFormat implements Serializable {
/**
* Default MongoDB TSV format used by the {@code mongoexport} operation.
+ *
* <p>
* <strong>Parsing is not supported yet.</strong>
* </p>
@@ -1214,6 +1366,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code ('\t')}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('"')}</li>
@@ -1222,11 +1375,11 @@ public final class CSVFormat implements Serializable {
* <li>{@link Builder#setSkipHeaderRecord(boolean)
setSkipHeaderRecord}{@code (false)}</li>
* </ul>
*
- * @see Predefined#MongoDBCsv
- * @see QuoteMode#ALL_NON_NULL
+ * @since 1.7
+ * @see Predefined#MongoDBTsv
+ * @see QuoteMode#MINIMAL
* @see <a
href="https://docs.mongodb.com/manual/reference/program/mongoexport/">MongoDB
mongoexport command
* documentation</a>
- * @since 1.7
*/
// @formatter:off
public static final CSVFormat MONGODB_TSV = DEFAULT.builder()
@@ -1250,6 +1403,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code ('\t')}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('\\')}</li>
@@ -1282,29 +1436,29 @@ public final class CSVFormat implements Serializable {
* format used by the SQL*Loader utility.
*
* <p>
- * This is a comma-delimited format with the system line separator
character as the record separator. Values are
- * double quoted when needed and special characters are escaped with
{@code '"'}. The default NULL string is
- * {@code ""}. Values are trimmed.
+ * This is a comma-delimited format with the system line separator as the
record separator. Values are double quoted when needed, and special
+ * characters are escaped with {@code '\\'}. The default null string is
{@code "\\N"}. Values are trimmed.
* </p>
*
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
- * <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')} //
default is {@code FIELDS TERMINATED BY ','}}</li>
+ * <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')} //
default is {@code FIELDS TERMINATED BY ','}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('\\')}</li>
* <li>{@link Builder#setIgnoreEmptyLines(boolean)
setIgnoreEmptyLines}{@code (false)}</li>
- * <li>{@link Builder#setQuote(char) setQuote}{@code ('"')} // default is
{@code OPTIONALLY ENCLOSED BY '"'}}</li>
+ * <li>{@link Builder#setQuote(char) setQuote}{@code ('"')} // default is
{@code OPTIONALLY ENCLOSED BY '"'}</li>
* <li>{@link Builder#setNullString(String) setNullString}{@code
("\\N")}</li>
* <li>{@link Builder#setTrim(boolean) setTrim}{@code (true)}</li>
* <li>{@link Builder#setRecordSeparator(String) setRecordSeparator}{@code
(System.lineSeparator())}</li>
* <li>{@link Builder#setQuoteMode(QuoteMode) setQuoteMode}{@code
(QuoteMode.MINIMAL)}</li>
* </ul>
*
+ * @since 1.6
* @see Predefined#Oracle
* @see QuoteMode#MINIMAL
* @see <a
href="https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-D1762699-8154-40F6-90DE-EFB8EB6A9AB0">Oracle
CSV Format Specification</a>
- * @since 1.6
*/
// @formatter:off
public static final CSVFormat ORACLE = DEFAULT.builder()
@@ -1330,6 +1484,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setEscape(Character) setEscape}{@code (null)}</li>
@@ -1340,10 +1495,10 @@ public final class CSVFormat implements Serializable {
* <li>{@link Builder#setQuoteMode(QuoteMode) setQuoteMode}{@code
(QuoteMode.ALL_NON_NULL)}</li>
* </ul>
*
+ * @since 1.5
* @see Predefined#PostgreSQLCsv
* @see QuoteMode#ALL_NON_NULL
* @see <a
href="https://www.postgresql.org/docs/current/static/sql-copy.html">PostgreSQL
CSV</a>
- * @since 1.5
*/
// @formatter:off
public static final CSVFormat POSTGRESQL_CSV = DEFAULT.builder()
@@ -1368,6 +1523,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code ('\t')}</li>
* <li>{@link Builder#setEscape(char) setEscape}{@code ('\\')}</li>
@@ -1378,10 +1534,10 @@ public final class CSVFormat implements Serializable {
* <li>{@link Builder#setQuoteMode(QuoteMode) setQuoteMode}{@code
(QuoteMode.ALL_NON_NULL)}</li>
* </ul>
*
+ * @since 1.5
* @see Predefined#PostgreSQLText
* @see QuoteMode#ALL_NON_NULL
* @see <a
href="https://www.postgresql.org/docs/current/static/sql-copy.html">PostgreSQL
Text</a>
- * @since 1.5
*/
// @formatter:off
public static final CSVFormat POSTGRESQL_TEXT = DEFAULT.builder()
@@ -1401,6 +1557,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code (',')}</li>
* <li>{@link Builder#setQuote(char) setQuote}{@code ('"')}</li>
@@ -1413,6 +1570,9 @@ public final class CSVFormat implements Serializable {
*/
public static final CSVFormat RFC4180 =
DEFAULT.builder().setIgnoreEmptyLines(false).get();
+ /**
+ * The serialization version identifier.
+ */
private static final long serialVersionUID = 2L;
/**
@@ -1421,6 +1581,7 @@ public final class CSVFormat implements Serializable {
* <p>
* The {@link Builder} settings are the {@link #DEFAULT} <em>with</em>:
* </p>
+ *
* <ul>
* <li>{@link Builder#setDelimiter(char) setDelimiter}{@code ('\t')}</li>
* <li>{@link Builder#setIgnoreSurroundingSpaces(boolean)
setIgnoreSurroundingSpaces}{@code (true)}</li>
@@ -1440,7 +1601,7 @@ public final class CSVFormat implements Serializable {
* Null-safe clone of an array.
*
* @param <T> The array element type.
- * @param values The source array
+ * @param values The source array.
* @return The cloned array.
*/
@SafeVarargs
@@ -1453,7 +1614,7 @@ public final class CSVFormat implements Serializable {
*
* @param source The string to check.
* @param searchCh The character to search.
- * @return true if {@code c} contains a line break character
+ * @return {@code true} if {@code source} contains {@code searchCh}.
*/
private static boolean contains(final String source, final char searchCh) {
return Objects.requireNonNull(source, "source").indexOf(searchCh) >= 0;
@@ -1463,7 +1624,7 @@ public final class CSVFormat implements Serializable {
* Returns true if the given string contains a line break character.
*
* @param source The string to check.
- * @return true if {@code c} contains a line break character.
+ * @return {@code true} if {@code source} contains CR or LF.
*/
private static boolean containsLineBreak(final String source) {
return contains(source, Constants.CR) || contains(source,
Constants.LF);
@@ -1472,12 +1633,19 @@ public final class CSVFormat implements Serializable {
/**
* Creates a null-safe copy of the given instance.
*
+ * @param format The source format, which may be null.
* @return A copy of the given instance or null if the input is null.
*/
static CSVFormat copy(final CSVFormat format) {
return format != null ? format.copy() : null;
}
+ /**
+ * Tests whether a value is null or empty after {@link String#trim()}.
+ *
+ * @param value The value to test.
+ * @return Whether the value is null, empty, or contains only characters
removed by {@link String#trim()}.
+ */
static boolean isBlank(final String value) {
return value == null || value.trim().isEmpty();
}
@@ -1486,6 +1654,9 @@ public final class CSVFormat implements Serializable {
* Tests whether every character of the delimiter stays itself when
individually escaped and read back. The letters used by control-character escape
* sequences ({@code r}, {@code n}, {@code t}, {@code b}, {@code f})
unescape to the control character, not to the letter, so a delimiter containing
one of
* them cannot have a straddling prefix escaped losslessly and keeps the
historical unescaped output.
+ *
+ * @param delimiter The delimiter characters.
+ * @return Whether each delimiter character can be escaped without
changing its value when parsed.
*/
private static boolean isDelimiterStraddleEscapable(final char[]
delimiter) {
for (final char ch : delimiter) {
@@ -1516,12 +1687,23 @@ public final class CSVFormat implements Serializable {
return c != null && isLineBreak(c.charValue()); // Explicit unboxing
is intentional
}
- /** Same test as in as {@link String#trim()}. */
+ /**
+ * Tests whether {@link String#trim()} removes the character.
+ *
+ * @param ch The character to test.
+ * @return Whether the character is at most U+0020.
+ */
private static boolean isTrimChar(final char ch) {
return ch <= Constants.SP;
}
- /** Same test as in as {@link String#trim()}. */
+ /**
+ * Tests whether {@link String#trim()} removes the character at the
specified position.
+ *
+ * @param charSequence The character sequence.
+ * @param pos The position to test.
+ * @return Whether the character at the position is at most U+0020.
+ */
private static boolean isTrimChar(final CharSequence charSequence, final
int pos) {
return isTrimChar(charSequence.charAt(pos));
}
@@ -1530,10 +1712,11 @@ public final class CSVFormat implements Serializable {
* Creates a new CSV format with the specified delimiter.
*
* <p>
- * Use this method if you want to create a CSVFormat from scratch. All
fields but the delimiter will be initialized with null/false.
+ * Use this method if you want to create a CSVFormat from scratch. All
settings except the delimiter take their Java defaults:
+ * {@code null}, {@code false}, or zero.
* </p>
*
- * @param delimiter The char used for value separation, must not be a line
break character
+ * @param delimiter The char used for value separation, must not be a line
break character.
* @return A new CSV format.
* @throws IllegalArgumentException if the delimiter is a line break
character.
* @see #DEFAULT
@@ -1546,6 +1729,12 @@ public final class CSVFormat implements Serializable {
return new CSVFormat(new Builder().setDelimiter(delimiter));
}
+ /**
+ * Converts an object array to strings, preserving null elements.
+ *
+ * @param values The values to convert, which may be null.
+ * @return A new string array, or null if the input is null.
+ */
static String[] toStringArray(final Object[] values) {
if (values == null) {
return null;
@@ -1555,6 +1744,12 @@ public final class CSVFormat implements Serializable {
return strings;
}
+ /**
+ * Trims leading and trailing characters as defined by {@link
String#trim()}.
+ *
+ * @param charSequence The character sequence to trim.
+ * @return The trimmed sequence, or the original sequence if no trimming
is required.
+ */
static CharSequence trim(final CharSequence charSequence) {
if (charSequence instanceof String) {
return ((String) charSequence).trim();
@@ -1575,80 +1770,129 @@ public final class CSVFormat implements Serializable {
/**
* Gets one of the predefined formats from {@link CSVFormat.Predefined}.
*
- * @param format name
- * @return one of the predefined formats
+ * @param format The case-sensitive enum constant name, such as {@code
"Default"} or {@code "Excel"}.
+ * @return The corresponding predefined format.
+ * @throws IllegalArgumentException If the name does not match a
predefined enum constant.
+ * @throws NullPointerException If the name is {@code null}.
* @since 1.2
*/
public static CSVFormat valueOf(final String format) {
return CSVFormat.Predefined.valueOf(format).getFormat();
}
- /** How duplicate headers are handled. */
+ /**
+ * How duplicate headers are handled.
+ */
private final DuplicateHeaderMode duplicateHeaderMode;
- /** Whether missing column names are allowed when parsing the header line.
*/
+ /**
+ * Whether missing column names are allowed when parsing the header line.
+ */
private final boolean allowMissingColumnNames;
- /** Whether to flush on close. */
+ /**
+ * Whether to flush on close.
+ */
private final boolean autoFlush;
- /** Set to null if commenting is disabled. */
+ /**
+ * Set to null if commenting is disabled.
+ */
private final Character commentMarker;
- /** The character delimiting the values (typically ";", "," or "\t"). */
+ /**
+ * The string delimiting the values (typically ";", "," or "\t").
+ */
private final String delimiter;
- /** Set to null if escaping is disabled. */
+ /**
+ * Set to null if escaping is disabled.
+ */
private final Character escapeCharacter;
- /** Array of header column names. */
+ /**
+ * Array of header column names.
+ */
private final String[] headers;
- /** Array of header comment lines. */
+ /**
+ * Array of header comment lines.
+ */
private final String[] headerComments;
- /** Whether empty lines between records are ignored when parsing input. */
+ /**
+ * Whether empty lines between records are ignored when parsing input.
+ */
private final boolean ignoreEmptyLines;
- /** Should ignore header names case. */
+ /**
+ * Should ignore header names case.
+ */
private final boolean ignoreHeaderCase;
- /** Should leading/trailing spaces be ignored around values?. */
+ /**
+ * Whether leading and trailing spaces around values are ignored.
+ */
private final boolean ignoreSurroundingSpaces;
- /** The string to be used for null values. */
+ /**
+ * The string to be used for null values.
+ */
private final String nullString;
- /** Set to null if quoting is disabled. */
+ /**
+ * Set to null if quoting is disabled.
+ */
private final Character quoteCharacter;
- /** Set to {@code quoteCharacter + nullString + quoteCharacter} */
+ /**
+ * The cached quoted null string, using double quotes when no quote
character is configured.
+ */
private final String quotedNullString;
- /** The quote policy output fields. */
+ /**
+ * The quote policy for output and null-value parsing.
+ */
private final QuoteMode quoteMode;
- /** For output. */
+ /**
+ * For output.
+ */
private final String recordSeparator;
- /** Whether to skip the header record. */
+ /**
+ * Whether to skip the header record.
+ */
private final boolean skipHeaderRecord;
- /** Whether reading end-of-file is allowed even when input is malformed,
helps Excel compatibility. */
+ /**
+ * Whether reading end-of-file is allowed even when input is malformed,
helps Excel compatibility.
+ */
private final boolean lenientEof;
- /** Whether reading trailing data is allowed in records, helps Excel
compatibility. */
+ /**
+ * Whether reading trailing data is allowed in records, helps Excel
compatibility.
+ */
private final boolean trailingData;
- /** Whether to add a trailing delimiter. */
+ /**
+ * Whether to add a trailing delimiter.
+ */
private final boolean trailingDelimiter;
- /** Whether to trim leading and trailing blanks. */
+ /**
+ * Whether to trim leading and trailing blanks.
+ */
private final boolean trim;
- /** The maximum number of rows to process, excluding the header row. */
+ /**
+ * The maximum number of rows to process, excluding the header row.
+ */
private final long maxRows;
+ /**
+ * The monitor used to serialize writes, recreated after deserialization.
+ */
private transient Object writeLock = new Object();
/**
@@ -1683,6 +1927,13 @@ public final class CSVFormat implements Serializable {
validate();
}
+ /**
+ * Appends a character to the output.
+ *
+ * @param c The value to append.
+ * @param appendable The output.
+ * @throws IOException If an I/O error occurs.
+ */
private void append(final char c, final Appendable appendable) throws
IOException {
// try {
appendable.append(c);
@@ -1691,6 +1942,13 @@ public final class CSVFormat implements Serializable {
// }
}
+ /**
+ * Appends a character sequence to the output.
+ *
+ * @param csq The value to append.
+ * @param appendable The output.
+ * @throws IOException If an I/O error occurs.
+ */
private void append(final CharSequence csq, final Appendable appendable)
throws IOException {
// try {
appendable.append(csq);
@@ -1721,6 +1979,11 @@ public final class CSVFormat implements Serializable {
* Tests whether appending the delimiter after {@code charSeq} would let
the parser match the delimiter starting inside the value. This happens with a
* multi-character delimiter when the value ends with a straddling prefix
of it (for delimiter {@code ||}, a value ending in {@code |} followed by the
* delimiter yields {@code |||}, which the greedy lexer splits one
character early). Such a value must be encapsulated so the field boundary is
unambiguous.
+ *
+ * @param charSeq The value to test.
+ * @param delimiter The delimiter characters.
+ * @param delimiterLength The number of delimiter characters.
+ * @return Whether a delimiter match would start inside the value.
*/
private boolean endsWithDelimiterPrefix(final CharSequence charSeq, final
char[] delimiter, final int delimiterLength) {
return indexOfDelimiterPrefix(charSeq, delimiter, delimiterLength) >=
0;
@@ -1747,21 +2010,42 @@ public final class CSVFormat implements Serializable {
trim == other.trim;
}
+ /**
+ * Appends the configured escape character followed by the given character.
+ *
+ * @param c The character to escape.
+ * @param appendable The output.
+ * @throws IOException If an I/O error occurs.
+ */
private void escape(final char c, final Appendable appendable) throws
IOException {
append(escapeCharacter.charValue(), appendable); // Explicit unboxing
is intentional
append(c, appendable);
}
/**
- * Formats the specified values as a CSV record string.
+ * Formats the specified values using this format.
+ *
+ * <p>
+ * When a comment marker is configured, the result starts with any
configured header comments. Unless {@link #getSkipHeaderRecord()} is {@code
true},
+ * it then includes the configured header. The supplied values follow as
one record, with the final record separator removed. Any configured trailing
+ * delimiter is retained.
+ * </p>
*
* @param values The values to format.
- * @return The formatted values.
+ * @return The formatted output without its final record separator.
+ * @throws java.io.UncheckedIOException If an I/O error occurs while
reading a streamed value.
*/
public String format(final Object... values) {
return Uncheck.get(() -> format_(values));
}
+ /**
+ * Formats values and any configured header comments and header, removing
the final record separator.
+ *
+ * @param values The values to format.
+ * @return The formatted output without its final record separator.
+ * @throws IOException If an I/O error occurs while reading a streamed
value.
+ */
private String format_(final Object... values) throws IOException {
final StringWriter out = new StringWriter();
try (CSVPrinter csvPrinter = new CSVPrinter(out, this)) {
@@ -1773,9 +2057,14 @@ public final class CSVFormat implements Serializable {
}
/**
- * Gets whether duplicate names are allowed in the headers.
+ * Gets whether all duplicate header names are allowed.
*
- * @return whether duplicate header names are allowed
+ * <p>
+ * A return value of {@code false} does not distinguish {@link
DuplicateHeaderMode#ALLOW_EMPTY} from
+ * {@link DuplicateHeaderMode#DISALLOW}. Use {@link
#getDuplicateHeaderMode()} to determine whether duplicate missing names are
allowed.
+ * </p>
+ *
+ * @return {@code true} if the duplicate header mode is {@link
DuplicateHeaderMode#ALLOW_ALL}, {@code false} otherwise.
* @since 1.7
* @deprecated Use {@link #getDuplicateHeaderMode()}.
*/
@@ -1805,19 +2094,24 @@ public final class CSVFormat implements Serializable {
/**
* Gets the comment marker character, {@code null} disables comments.
+ *
* <p>
* The comment start character is only recognized at the start of a line.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link
Builder#setCommentMarker(Character)} to set the comment marker written at the
start of each comment
* line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -1825,16 +2119,17 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by Apache
Commons CSV", Instant.ofEpochMilli(0));
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
*
- * @return The comment start marker, may be {@code null}
+ * @return The comment start marker, may be {@code null}.
*/
public Character getCommentMarker() {
return commentMarker;
@@ -1852,7 +2147,7 @@ public final class CSVFormat implements Serializable {
}
/**
- * Gets the character delimiting the values (typically ";", "," or "\t").
+ * Gets the delimiter characters (typically ";", "," or "\t").
*
* @return The delimiter.
*/
@@ -1861,7 +2156,7 @@ public final class CSVFormat implements Serializable {
}
/**
- * Gets the character delimiting the values (typically ";", "," or "\t").
+ * Gets the delimiter string (typically ";", "," or "\t").
*
* @return The delimiter.
* @since 1.9.0
@@ -1883,7 +2178,7 @@ public final class CSVFormat implements Serializable {
/**
* Gets the escape character.
*
- * @return The escape character, may be {@code 0}
+ * @return The escape character, may be {@code 0}.
*/
char getEscapeChar() {
return escapeCharacter != null ? escapeCharacter.charValue() : 0; //
Explicit unboxing is intentional
@@ -1892,7 +2187,7 @@ public final class CSVFormat implements Serializable {
/**
* Gets the escape character.
*
- * @return The escape character, may be {@code null}
+ * @return The escape character, may be {@code null}.
*/
public Character getEscapeCharacter() {
return escapeCharacter;
@@ -1901,7 +2196,7 @@ public final class CSVFormat implements Serializable {
/**
* Gets a copy of the header array.
*
- * @return A copy of the header array; {@code null} if disabled, the empty
array if to be read from the file
+ * @return A copy of the header array; {@code null} if disabled, the empty
array if to be read from the file.
*/
public String[] getHeader() {
return headers != null ? headers.clone() : null;
@@ -1909,19 +2204,24 @@ public final class CSVFormat implements Serializable {
/**
* Gets a copy of the header comment array to write before the CSV data.
+ *
* <p>
* This setting is ignored by the parser.
* </p>
+ *
* <p>
* Comments are printed first, before headers.
* </p>
+ *
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link
Builder#setCommentMarker(Character)} to set the comment marker written at the
start of each comment
* line.
* </p>
+ *
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
+ *
* <p>
* For example:
* </p>
@@ -1929,12 +2229,13 @@ public final class CSVFormat implements Serializable {
* <pre>
* builder.setCommentMarker('#').setHeaderComments("Generated by Apache
Commons CSV", Instant.ofEpochMilli(0));
* </pre>
+ *
* <p>
* writes:
* </p>
*
* <pre>
- * # Generated by Apache Commons CSV.
+ * # Generated by Apache Commons CSV
* # 1970-01-01T00:00:00Z
* </pre>
*
@@ -1984,6 +2285,7 @@ public final class CSVFormat implements Serializable {
/**
* Gets the maximum number of rows to process, excluding the header row.
+ *
* <p>
* Values less than or equal to 0 mean no limit.
* </p>
@@ -1996,13 +2298,25 @@ public final class CSVFormat implements Serializable {
}
/**
- * Gets the String to convert to and from {@code null}.
- * <ul>
- * <li><strong>Reading:</strong> Converts strings equal to the given
{@code nullString} to {@code null} when reading records.</li>
- * <li><strong>Writing:</strong> Writes {@code null} as the given {@code
nullString} when writing records.</li>
- * </ul>
+ * Gets the string used to represent {@code null} values.
*
- * @return The String to convert to and from {@code null}. No substitution
occurs if {@code null}
+ * <p>
+ * When reading, a value equal to this string after parsing and trimming
is converted to {@code null}, unless the parser decoded an escape sequence using
+ * the configured escape character. Doubled quote characters are handled
separately and do not by themselves prevent null conversion.
+ * With {@link QuoteMode#ALL_NON_NULL} or {@link QuoteMode#NON_NUMERIC}, a
quoted value equal to this string is also preserved as a string.
+ * </p>
+ *
+ * <p>
+ * When no null string is configured, {@link QuoteMode#ALL_NON_NULL} and
{@link QuoteMode#NON_NUMERIC} still convert unquoted empty fields to {@code
null}.
+ * Other empty fields remain empty strings.
+ * </p>
+ *
+ * <p>
+ * When writing, {@code null} values use the configured null string, or an
empty value if no null string is configured. Quoting depends on the quote mode.
+ * </p>
+ *
+ * @return The null string, or {@code null} if no null string is
configured.
+ * @see #getQuoteMode()
*/
public String getNullString() {
return nullString;
@@ -2011,16 +2325,21 @@ public final class CSVFormat implements Serializable {
/**
* Gets the character used to encapsulate values containing special
characters.
*
- * @return The quoteChar character, may be {@code null}
+ * @return The quoteChar character, may be {@code null}.
*/
public Character getQuoteCharacter() {
return quoteCharacter;
}
/**
- * Gets the quote policy output fields.
+ * Gets the quote policy used for output and null-value parsing.
+ *
+ * <p>
+ * This policy also affects null-value parsing with {@link
QuoteMode#ALL_NON_NULL} and {@link QuoteMode#NON_NUMERIC}.
+ * See {@link CSVFormat#getNullString()} for details.
+ * </p>
*
- * @return The quote policy
+ * @return The quote policy, or {@code null} if unset, in which case
output uses {@link QuoteMode#MINIMAL}.
*/
public QuoteMode getQuoteMode() {
return quoteMode;
@@ -2029,7 +2348,7 @@ public final class CSVFormat implements Serializable {
/**
* Gets the record separator delimiting output records.
*
- * @return The record separator
+ * @return The record separator.
*/
public String getRecordSeparator() {
return recordSeparator;
@@ -2062,6 +2381,7 @@ public final class CSVFormat implements Serializable {
* that such a trailing delimiter produces is dropped so the output
round-trips back to the original record;
* a quoted empty trailing field ({@code ""}) is a real value rather than
a trailing delimiter and is kept.
* </p>
+ *
* <p>
* This is unrelated to {@link #getTrailingData() trailing data}, which
controls whether characters after the
* closing quote of an encapsulated value are tolerated when reading.
@@ -2075,9 +2395,14 @@ public final class CSVFormat implements Serializable {
}
/**
- * Gets whether to trim leading and trailing blanks. This is used by
{@link #print(Object, Appendable, boolean)} Also by
{CSVParser#addRecordValue(boolean)}
+ * Gets whether to trim leading and trailing characters as defined by
{@link String#trim()}.
+ *
+ * <p>
+ * Trimming applies to parsed values, including quoted values, and to
non-streamed values written by {@link #print(Object, Appendable, boolean)}.
+ * Values supplied by a {@link Reader} or {@link InputStream} are not
trimmed when writing.
+ * </p>
*
- * @return whether to trim leading and trailing blanks.
+ * @return Whether trimming is enabled.
*/
public boolean getTrim() {
return trim;
@@ -2099,6 +2424,11 @@ public final class CSVFormat implements Serializable {
* Returns the index within {@code charSeq} where a straddling prefix of
the delimiter begins, or -1 if the value does not end with one. Every character
* from the returned index to the end of the value takes part in a
delimiter match that would start inside the value once the delimiter is
appended, so an
* escaping printer must escape each of them individually. See {@link
#endsWithDelimiterPrefix(CharSequence, char[], int)}.
+ *
+ * @param charSeq The value to test.
+ * @param delimiter The delimiter characters.
+ * @param delimiterLength The number of delimiter characters.
+ * @return The start of the straddling prefix, or -1 if there is none.
*/
private int indexOfDelimiterPrefix(final CharSequence charSeq, final
char[] delimiter, final int delimiterLength) {
if (delimiterLength < 2) {
@@ -2125,9 +2455,11 @@ public final class CSVFormat implements Serializable {
/**
* Tests whether comments are supported by this format.
*
- * Note that the comment introducer character is only recognized at the
start of a line.
+ * <p>
+ * The comment introducer character is only recognized at the start of a
line.
+ * </p>
*
- * @return {@code true} is comments are supported, {@code false} otherwise
+ * @return {@code true} if comments are supported, {@code false} otherwise.
*/
public boolean isCommentMarkerSet() {
return commentMarker != null;
@@ -2137,11 +2469,11 @@ public final class CSVFormat implements Serializable {
* Tests whether the next characters constitute a delimiter
*
* @param ch0 The first char (index 0).
- * @param charSeq The match char sequence
- * @param startIndex where start to match
- * @param delimiter The delimiter
- * @param delimiterLength The delimiter length
- * @return true if the match is successful
+ * @param charSeq The match char sequence.
+ * @param startIndex where start to match.
+ * @param delimiter The delimiter.
+ * @param delimiterLength The delimiter length.
+ * @return true if the match is successful.
*/
private boolean isDelimiter(final char ch0, final CharSequence charSeq,
final int startIndex, final char[] delimiter, final int delimiterLength) {
if (ch0 != delimiter[0]) {
@@ -2162,7 +2494,7 @@ public final class CSVFormat implements Serializable {
/**
* Tests whether escapes are being processed.
*
- * @return {@code true} if escapes are processed
+ * @return {@code true} if escapes are processed.
*/
public boolean isEscapeCharacterSet() {
return escapeCharacter != null;
@@ -2180,7 +2512,7 @@ public final class CSVFormat implements Serializable {
/**
* Tests whether a null string has been defined.
*
- * @return {@code true} if a nullString is defined
+ * @return {@code true} if a nullString is defined.
*/
public boolean isNullStringSet() {
return nullString != null;
@@ -2189,12 +2521,19 @@ public final class CSVFormat implements Serializable {
/**
* Tests whether a quoteChar has been defined.
*
- * @return {@code true} if a quoteChar is defined
+ * @return {@code true} if a quoteChar is defined.
*/
public boolean isQuoteCharacterSet() {
return quoteCharacter != null;
}
+ /**
+ * Applies the configured row limit to a stream.
+ *
+ * @param <T> The element type.
+ * @param stream The stream to limit.
+ * @return The limited stream, or the original stream if no limit is
configured.
+ */
<T> IOStream<T> limit(final IOStream<T> stream) {
return useMaxRows() ? stream.limit(getMaxRows()) : stream;
}
@@ -2206,9 +2545,10 @@ public final class CSVFormat implements Serializable {
* See also the various static parse methods on {@link CSVParser}.
* </p>
*
- * @param reader The input stream
+ * @param reader The input stream.
* @return A parser over a stream of {@link CSVRecord}s.
- * @throws IOException If an I/O error occurs
+ * @throws IllegalArgumentException If the header contains missing or
duplicate names prohibited by this format.
+ * @throws IOException If an I/O error occurs.
* @throws CSVException Thrown on invalid input.
*/
public CSVParser parse(final Reader reader) throws IOException {
@@ -2240,13 +2580,21 @@ public final class CSVFormat implements Serializable {
* @param out The output.
* @param charset A charset.
* @return A printer to an output.
- * @throws IOException thrown if the optional header cannot be printed.
+ * @throws IOException If the output cannot be opened or the optional
header comments or header cannot be printed.
* @since 1.5
*/
public CSVPrinter print(final File out, final Charset charset) throws
IOException {
return print(out.toPath(), charset);
}
+ /**
+ * Prints the input as Base64, enclosing it in quotes if a quote character
is configured.
+ *
+ * @param inputStream The binary data to read.
+ * @param out The output.
+ * @param newRecord Whether this is the first value in a record.
+ * @throws IOException If an I/O error occurs.
+ */
private void print(final InputStream inputStream, final Appendable out,
final boolean newRecord) throws IOException {
// InputStream is never null here
// There is nothing to escape when quoting is used which is the
default.
@@ -2268,12 +2616,23 @@ public final class CSVFormat implements Serializable {
}
/**
- * Prints the {@code value} as the next value on the line to {@code out}.
The value will be escaped or encapsulated as needed. Useful when one wants to
- * avoid creating CSVPrinters. Trims the value if {@link #getTrim()} is
true.
+ * Prints the {@code value} as the next value on the line to {@code out}.
+ *
+ * <p>
+ * The value is escaped or encapsulated according to this format. This
method can be used without creating a {@link CSVPrinter}.
+ * A delimiter is written before the value unless {@code newRecord} is
{@code true}.
+ * </p>
+ *
+ * <p>
+ * A {@link Reader} supplies character data, and an {@link InputStream}
supplies binary data that is Base64-encoded. These streamed values are not
trimmed.
+ * Reader values are quoted whenever a quote character is set unless the
quote mode is {@link QuoteMode#NONE}. InputStream values are quoted whenever a
+ * quote character is set. Other values use their {@link CharSequence}
content or string representation, trimmed if {@link #getTrim()} is {@code true}.
+ * Null values use the rules described by {@link #getNullString()}.
+ * </p>
*
- * @param value value to output.
- * @param out where to print the value.
- * @param newRecord if this a new record.
+ * @param value The value to output.
+ * @param out Where to print the value.
+ * @param newRecord Whether this is the first value in a record.
* @throws IOException If an I/O error occurs.
* @since 1.4
*/
@@ -2307,6 +2666,15 @@ public final class CSVFormat implements Serializable {
}
}
+ /**
+ * Prints a converted value using this format's null, quoting, and
escaping rules.
+ *
+ * @param object The original value, used to distinguish nulls and numbers.
+ * @param value The converted and, if requested, trimmed value.
+ * @param out The output.
+ * @param newRecord Whether this is the first value in a record.
+ * @throws IOException If an I/O error occurs.
+ */
private void print(final Object object, final CharSequence value, final
Appendable out, final boolean newRecord) throws IOException {
synchronized (writeLock) {
final int offset = 0;
@@ -2347,7 +2715,7 @@ public final class CSVFormat implements Serializable {
* @param out The output.
* @param charset A charset.
* @return A printer to an output.
- * @throws IOException thrown if the optional header cannot be printed.
+ * @throws IOException If the output cannot be opened or the optional
header comments or header cannot be printed.
* @since 1.5
*/
@SuppressWarnings("resource")
@@ -2355,6 +2723,14 @@ public final class CSVFormat implements Serializable {
return print(Files.newBufferedWriter(out, charset));
}
+ /**
+ * Prints character data without trimming it.
+ *
+ * @param reader The character data to read.
+ * @param out The output.
+ * @param newRecord Whether this is the first value in a record.
+ * @throws IOException If an I/O error occurs.
+ */
private void print(final Reader reader, final Appendable out, final
boolean newRecord) throws IOException {
// Reader is never null here
if (!newRecord) {
@@ -2389,7 +2765,7 @@ public final class CSVFormat implements Serializable {
/**
* Outputs the trailing delimiter (if set) followed by the record
separator (if set).
*
- * @param appendable where to write
+ * @param appendable where to write.
* @throws IOException If an I/O error occurs.
* @since 1.4
*/
@@ -2405,15 +2781,16 @@ public final class CSVFormat implements Serializable {
}
/**
- * Prints the given {@code values} to {@code out} as a single record of
delimiter-separated values followed by the record separator.
+ * Prints the given {@code values} to {@code appendable} as a single
record.
*
* <p>
- * The values will be quoted if needed. Quotes and new-line characters
will be escaped. This method adds the record separator to the output after
printing
- * the record, so there is no need to call {@link #println(Appendable)}.
+ * Values are printed according to {@link #print(Object, Appendable,
boolean)}. Quoting and escaping depend on this format; with quoting enabled,
embedded
+ * line breaks can remain literal characters inside quoted values. This
method then calls {@link #println(Appendable)} to append any configured trailing
+ * delimiter and record separator, so the caller does not need to call it
separately.
* </p>
*
- * @param appendable where to write.
- * @param values values to output.
+ * @param appendable Where to write.
+ * @param values The values to output.
* @throws IOException If an I/O error occurs.
* @since 1.4
*/
@@ -2426,8 +2803,12 @@ public final class CSVFormat implements Serializable {
}
}
- /*
- * This method must only be called if escaping is enabled, otherwise can
throw exceptions.
+ /**
+ * Prints a character sequence using the configured escape character,
which must be set.
+ *
+ * @param charSeq The character sequence to print.
+ * @param appendable The output.
+ * @throws IOException If an I/O error occurs.
*/
private void printWithEscapes(final CharSequence charSeq, final Appendable
appendable) throws IOException {
int start = 0;
@@ -2480,8 +2861,12 @@ public final class CSVFormat implements Serializable {
}
}
- /*
- * This method must only be called if escaping is enabled, otherwise can
throw exceptions.
+ /**
+ * Prints character data using the configured escape character, which must
be set.
+ *
+ * @param reader The character data to read.
+ * @param appendable The output.
+ * @throws IOException If an I/O error occurs.
*/
private void printWithEscapes(final Reader reader, final Appendable
appendable) throws IOException {
int start = 0;
@@ -2551,9 +2936,14 @@ public final class CSVFormat implements Serializable {
}
}
- /*
- * This method must only be called if quoting is enabled, otherwise will
generate NPE.
- * The original object is needed so can check for Number
+ /**
+ * Prints a value according to the quote policy, with a quote character
required to be set.
+ *
+ * @param object The original value, used to distinguish numbers from
other objects.
+ * @param charSeq The character sequence to print.
+ * @param out The output.
+ * @param newRecord Whether this is the first value in a record.
+ * @throws IOException If an I/O error occurs.
*/
private void printWithQuotes(final Object object, final CharSequence
charSeq, final Appendable out, final boolean newRecord) throws IOException {
boolean quote = false;
@@ -2659,9 +3049,9 @@ public final class CSVFormat implements Serializable {
/**
* Always use quotes unless QuoteMode is NONE, so we do not have to look
ahead.
*
- * @param reader What to print
- * @param appendable Where to print it
- * @throws IOException If an I/O error occurs
+ * @param reader What to print.
+ * @param appendable Where to print it.
+ * @throws IOException If an I/O error occurs.
*/
private void printWithQuotes(final Reader reader, final Appendable
appendable) throws IOException {
if (getQuoteMode() == QuoteMode.NONE) {
@@ -2754,20 +3144,38 @@ public final class CSVFormat implements Serializable {
return sb.toString();
}
+ /**
+ * Trims a string if trimming is enabled.
+ *
+ * @param value The string to process.
+ * @return The trimmed string if trimming is enabled, otherwise the
original string.
+ */
String trim(final String value) {
return getTrim() ? value.trim() : value;
}
+ /**
+ * Tests whether a positive row limit is configured.
+ *
+ * @return Whether the row limit is greater than zero.
+ */
boolean useMaxRows() {
return getMaxRows() > 0;
}
+ /**
+ * Tests whether a row is within the configured limit.
+ *
+ * @param rowNum The one-based row number, excluding the header.
+ * @return Whether no limit is configured or the row number is at most the
limit.
+ */
boolean useRow(final long rowNum) {
return !useMaxRows() || rowNum <= getMaxRows();
}
/**
* Verifies the validity and consistency of the attributes, and throws an
{@link IllegalArgumentException} if necessary.
+ *
* <p>
* Because an instance can be used for both writing and parsing, not all
conditions can be tested here. For example, allowMissingColumnNames is only used
* for parsing, so it cannot be used here.
@@ -2814,10 +3222,10 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} that allows duplicate header names.
*
- * @return A new {@code CSVFormat} that allows duplicate header names
+ * @return A new {@code CSVFormat} that allows duplicate header names.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.7
- * @deprecated Use {@link Builder#setAllowDuplicateHeaderNames(boolean)
Builder#setAllowDuplicateHeaderNames(true)}
+ * @deprecated Use {@link
Builder#setDuplicateHeaderMode(DuplicateHeaderMode)} with {@link
DuplicateHeaderMode#ALLOW_ALL}.
*/
@Deprecated
public CSVFormat withAllowDuplicateHeaderNames() {
@@ -2825,13 +3233,20 @@ public final class CSVFormat implements Serializable {
}
/**
- * Builds a new {@code CSVFormat} with duplicate header names behavior set
to the given value.
+ * Builds a new {@code CSVFormat} with the specified duplicate header
names behavior.
*
- * @param allowDuplicateHeaderNames The duplicate header names behavior,
true to allow, false to disallow.
- * @return A new {@code CSVFormat} with duplicate header names behavior
set to the given value.
+ * <p>
+ * A value of {@code true} selects {@link DuplicateHeaderMode#ALLOW_ALL};
{@code false} selects
+ * {@link DuplicateHeaderMode#ALLOW_EMPTY}, which still permits duplicate
null, empty, or blank names.
+ * Allowing missing names while parsing is controlled separately by {@link
Builder#setAllowMissingColumnNames(boolean)}.
+ * </p>
+ *
+ * @param allowDuplicateHeaderNames {@code true} to allow all duplicates,
{@code false} to allow only duplicate missing names.
+ * @return A new {@code CSVFormat} with the specified duplicate header
names behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.7
- * @deprecated Use {@link Builder#setAllowDuplicateHeaderNames(boolean)}
+ * @deprecated Use {@link
Builder#setDuplicateHeaderMode(DuplicateHeaderMode)} with {@link
DuplicateHeaderMode#ALLOW_ALL} or
+ * {@link DuplicateHeaderMode#ALLOW_EMPTY}, respectively.
*/
@Deprecated
public CSVFormat withAllowDuplicateHeaderNames(final boolean
allowDuplicateHeaderNames) {
@@ -2844,9 +3259,9 @@ public final class CSVFormat implements Serializable {
*
* @return A new CSVFormat that is equal to this but with the specified
missing column names behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @see Builder#setAllowMissingColumnNames(boolean)
* @since 1.1
- * @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)
Builder#setAllowMissingColumnNames(true)}
+ * @see Builder#setAllowMissingColumnNames(boolean)
+ * @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)
Builder#setAllowMissingColumnNames(true)}.
*/
@Deprecated
public CSVFormat withAllowMissingColumnNames() {
@@ -2860,7 +3275,7 @@ public final class CSVFormat implements Serializable {
* an {@link IllegalArgumentException} to
be thrown.
* @return A new CSVFormat that is equal to this but with the specified
missing column names behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)}
+ * @deprecated Use {@link Builder#setAllowMissingColumnNames(boolean)}.
*/
@Deprecated
public CSVFormat withAllowMissingColumnNames(final boolean
allowMissingColumnNames) {
@@ -2874,7 +3289,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the specified
autoFlush setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.6
- * @deprecated Use {@link Builder#setAutoFlush(boolean)}
+ * @deprecated Use {@link Builder#setAutoFlush(boolean)}.
*/
@Deprecated
public CSVFormat withAutoFlush(final boolean autoFlush) {
@@ -2885,11 +3300,11 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character. Note that the comment start character is
only
* recognized at the start of a line.
*
- * @param commentMarker The comment start marker
- * @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker
+ * @param commentMarker The comment start marker.
+ * @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
* attributes.
- * @deprecated Use {@link Builder#setCommentMarker(char)}
+ * @deprecated Use {@link Builder#setCommentMarker(char)}.
*/
@Deprecated
public CSVFormat withCommentMarker(final char commentMarker) {
@@ -2900,11 +3315,11 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the comment start marker of the
format set to the specified character. Note that the comment start character is
only
* recognized at the start of a line.
*
- * @param commentMarker The comment start marker, use {@code null} to
disable
- * @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker
+ * @param commentMarker The comment start marker, use {@code null} to
disable.
+ * @return A new CSVFormat that is equal to this one but with the
specified character as the comment start marker.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
* attributes.
- * @deprecated Use {@link Builder#setCommentMarker(Character)}
+ * @deprecated Use {@link Builder#setCommentMarker(Character)}.
*/
@Deprecated
public CSVFormat withCommentMarker(final Character commentMarker) {
@@ -2914,11 +3329,11 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the delimiter of the format set to
the specified character.
*
- * @param delimiter The delimiter character
- * @return A new CSVFormat that is equal to this with the specified
character as a delimiter
+ * @param delimiter The delimiter character.
+ * @return A new CSVFormat that is equal to this with the specified
character as a delimiter.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
* attributes.
- * @deprecated Use {@link Builder#setDelimiter(char)}
+ * @deprecated Use {@link Builder#setDelimiter(char)}.
*/
@Deprecated
public CSVFormat withDelimiter(final char delimiter) {
@@ -2928,11 +3343,11 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the escape character of the format
set to the specified character.
*
- * @param escape The escape character
- * @return A new CSVFormat that is equal to this but with the specified
character as the escape character
+ * @param escape The escape character.
+ * @return A new CSVFormat that is equal to this but with the specified
character as the escape character.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
* attributes.
- * @deprecated Use {@link Builder#setEscape(char)}
+ * @deprecated Use {@link Builder#setEscape(char)}.
*/
@Deprecated
public CSVFormat withEscape(final char escape) {
@@ -2942,11 +3357,11 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the escape character of the format
set to the specified character.
*
- * @param escape The escape character, use {@code null} to disable
- * @return A new CSVFormat that is equal to this but with the specified
character as the escape character
+ * @param escape The escape character, use {@code null} to disable.
+ * @return A new CSVFormat that is equal to this but with the specified
character as the escape character.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or when any attribute is invalid or inconsistent with other
* attributes.
- * @deprecated Use {@link Builder#setEscape(Character)}
+ * @deprecated Use {@link Builder#setEscape(Character)}.
*/
@Deprecated
public CSVFormat withEscape(final Character escape) {
@@ -2968,14 +3383,15 @@ public final class CSVFormat implements Serializable {
* .get();
* </pre>
*
- * <p>Any previously set headers are reset to empty.
- * The resulting format will have {@code skipHeaderRecord = true}.</p>
+ * <p>
+ * Any previously set headers are reset to empty. The resulting format
will have {@code skipHeaderRecord = true}.
+ * </p>
*
* @return A new CSVFormat that is equal to this but using the first
record as header.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
+ * @since 1.3
* @see Builder#setSkipHeaderRecord(boolean)
* @see Builder#setHeader(String...)
- * @since 1.3
* @deprecated Use {@link Builder#setHeader(String...)
Builder#setHeader()}.{@link Builder#setSkipHeaderRecord(boolean)
setSkipHeaderRecord(true)}.
*/
// @formatter:on
@@ -3003,17 +3419,18 @@ public final class CSVFormat implements Serializable {
* ...
* CSVFormat format = aFormat.builder().setHeader(MyHeader.class).get();
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param headerEnum The enum defining the header, {@code null} if
disabled, empty if parsed automatically, user specified otherwise.
- * @return A new CSVFormat that is equal to this but with the specified
header
+ * @param headerEnum The enum defining the header, {@code null} to disable
the header, or an enum with no constants to read the header from the input.
+ * @return A new CSVFormat that is equal to this but with the specified
header.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
+ * @since 1.3
* @see Builder#setHeader(String...)
* @see Builder#setSkipHeaderRecord(boolean)
- * @since 1.3
- * @deprecated Use {@link Builder#setHeader(Class)}
+ * @deprecated Use {@link Builder#setHeader(Class)}.
*/
@Deprecated
public CSVFormat withHeader(final Class<? extends Enum<?>> headerEnum) {
@@ -3033,16 +3450,17 @@ public final class CSVFormat implements Serializable {
* <pre>
* CSVFormat format = aFormat.builder().setHeader(resultSet).get();
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param resultSet The resultSet for the header, {@code null} if
disabled, empty if parsed automatically, user-specified otherwise.
- * @return A new CSVFormat that is equal to this but with the specified
header
+ * @param resultSet The result set whose column labels define the header,
or {@code null} to disable the header.
+ * @return A new CSVFormat that is equal to this but with the specified
header.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @throws SQLException SQLException if a database access error occurs or
this method is called on a closed result set.
+ * @throws SQLException if a database access error occurs or this method
is called on a closed result set.
* @since 1.1
- * @deprecated Use {@link Builder#setHeader(ResultSet)}
+ * @deprecated Use {@link Builder#setHeader(ResultSet)}.
*/
@Deprecated
public CSVFormat withHeader(final ResultSet resultSet) throws SQLException
{
@@ -3054,24 +3472,25 @@ public final class CSVFormat implements Serializable {
* input file with:
*
* <pre>
- * CSVFormat format = aFormat.builder().setHeader().get()
+ * CSVFormat format = aFormat.builder().setHeader().get();
* </pre>
*
* or specified manually with:
*
* <pre>
- * CSVFormat format = aFormat.builder().setHeader(resultSetMetaData).get()
+ * CSVFormat format = aFormat.builder().setHeader(resultSetMetaData).get();
* </pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
- * @param resultSetMetaData The metaData for the header, {@code null} if
disabled, empty if parsed automatically, user specified otherwise.
- * @return A new CSVFormat that is equal to this but with the specified
header
+ * @param resultSetMetaData The metadata whose column labels define the
header, or {@code null} to disable the header.
+ * @return A new CSVFormat that is equal to this but with the specified
header.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @throws SQLException SQLException if a database access error occurs or
this method is called on a closed result set.
+ * @throws SQLException if a database access error occurs or this method
is called on a closed result set.
* @since 1.1
- * @deprecated Use {@link Builder#setHeader(ResultSetMetaData)}
+ * @deprecated Use {@link Builder#setHeader(ResultSetMetaData)}.
*/
@Deprecated
public CSVFormat withHeader(final ResultSetMetaData resultSetMetaData)
throws SQLException {
@@ -3091,15 +3510,16 @@ public final class CSVFormat implements Serializable {
* <pre>{@code
* CSVFormat format = aFormat.builder().setHeader("name", "email",
"phone").get();
* }</pre>
+ *
* <p>
* The header is also used by the {@link CSVPrinter}.
* </p>
*
* @param header The header, {@code null} if disabled, empty if parsed
automatically, user-specified otherwise.
- * @return A new CSVFormat that is equal to this but with the specified
header
+ * @return A new CSVFormat that is equal to this but with the specified
header.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setSkipHeaderRecord(boolean)
- * @deprecated Use {@link Builder#setHeader(String...)}
+ * @deprecated Use {@link Builder#setHeader(String...)}.
*/
@Deprecated
public CSVFormat withHeader(final String... header) {
@@ -3115,11 +3535,11 @@ public final class CSVFormat implements Serializable {
* }</pre>
*
* @param headerComments The headerComments which will be printed by the
Printer before the actual CSV data.
- * @return A new CSVFormat that is equal to this but with the specified
header
+ * @return A new CSVFormat that is equal to this but with the specified
header comments.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @see Builder#setSkipHeaderRecord(boolean)
* @since 1.1
- * @deprecated Use {@link Builder#setHeaderComments(Object...)}
+ * @see Builder#setSkipHeaderRecord(boolean)
+ * @deprecated Use {@link Builder#setHeaderComments(Object...)}.
*/
@Deprecated
public CSVFormat withHeaderComments(final Object... headerComments) {
@@ -3131,9 +3551,9 @@ public final class CSVFormat implements Serializable {
*
* @return A new CSVFormat that is equal to this but with the specified
empty line skipping behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @see Builder#setIgnoreEmptyLines(boolean)
* @since 1.1
- * @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)
Builder#setIgnoreEmptyLines(true)}
+ * @see Builder#setIgnoreEmptyLines(boolean)
+ * @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)
Builder#setIgnoreEmptyLines(true)}.
*/
@Deprecated
public CSVFormat withIgnoreEmptyLines() {
@@ -3147,7 +3567,7 @@ public final class CSVFormat implements Serializable {
* lines to empty records.
* @return A new CSVFormat that is equal to this but with the specified
empty line skipping behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)}
+ * @deprecated Use {@link Builder#setIgnoreEmptyLines(boolean)}.
*/
@Deprecated
public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
@@ -3157,11 +3577,11 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the header ignore case behavior set
to {@code true}.
*
- * @return A new CSVFormat that will ignore the new case header name
behavior.
+ * @return A new CSVFormat that ignores case when looking up header names.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @see Builder#setIgnoreHeaderCase(boolean)
* @since 1.3
- * @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)
Builder#setIgnoreHeaderCase(true)}
+ * @see Builder#setIgnoreHeaderCase(boolean)
+ * @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)
Builder#setIgnoreHeaderCase(true)}.
*/
@Deprecated
public CSVFormat withIgnoreHeaderCase() {
@@ -3171,11 +3591,11 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with whether header names should be
accessed ignoring case.
*
- * @param ignoreHeaderCase The case mapping behavior, {@code true} to
access name/values, {@code false} to leave the mapping as is.
- * @return A new CSVFormat that will ignore case header name if specified
as {@code true}
+ * @param ignoreHeaderCase Whether header names are matched ignoring case.
+ * @return A new CSVFormat that will ignore case header name if specified
as {@code true}.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
- * @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)}
+ * @deprecated Use {@link Builder#setIgnoreHeaderCase(boolean)}.
*/
@Deprecated
public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) {
@@ -3187,9 +3607,9 @@ public final class CSVFormat implements Serializable {
*
* @return A new CSVFormat that is equal to this but with the specified
parser trimming behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @see Builder#setIgnoreSurroundingSpaces(boolean)
* @since 1.1
- * @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)
Builder#setIgnoreSurroundingSpaces(true)}
+ * @see Builder#setIgnoreSurroundingSpaces(boolean)
+ * @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)
Builder#setIgnoreSurroundingSpaces(true)}.
*/
@Deprecated
public CSVFormat withIgnoreSurroundingSpaces() {
@@ -3202,7 +3622,7 @@ public final class CSVFormat implements Serializable {
* @param ignoreSurroundingSpaces The parser trimming behavior, {@code
true} to remove the surrounding spaces, {@code false} to leave the spaces as is.
* @return A new CSVFormat that is equal to this but with the specified
trimming behavior.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)}
+ * @deprecated Use {@link Builder#setIgnoreSurroundingSpaces(boolean)}.
*/
@Deprecated
public CSVFormat withIgnoreSurroundingSpaces(final boolean
ignoreSurroundingSpaces) {
@@ -3210,16 +3630,17 @@ public final class CSVFormat implements Serializable {
}
/**
- * Builds a new {@code CSVFormat} with conversions to and from null for
strings on input and output.
- * <ul>
- * <li><strong>Reading:</strong> Converts strings equal to the given
{@code nullString} to {@code null} when reading records.</li>
- * <li><strong>Writing:</strong> Writes {@code null} as the given {@code
nullString} when writing records.</li>
- * </ul>
+ * Builds a new {@code CSVFormat} with the specified null string.
+ *
+ * <p>
+ * See {@link #getNullString()} for the conversion rules, including how
quoting and escaping affect parsing. Leaving the null string unset does not
disable
+ * the conversion of unquoted empty fields to {@code null} with {@link
QuoteMode#ALL_NON_NULL} or {@link QuoteMode#NON_NUMERIC}.
+ * </p>
*
- * @param nullString The String to convert to and from {@code null}. No
substitution occurs if {@code null}
- * @return A new CSVFormat that is equal to this but with the specified
null conversion string.
+ * @param nullString The null string, or {@code null} to leave the null
string unset.
+ * @return A new CSVFormat with the specified null string.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setNullString(String)}
+ * @deprecated Use {@link Builder#setNullString(String)}.
*/
@Deprecated
public CSVFormat withNullString(final String nullString) {
@@ -3229,10 +3650,10 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the quoteChar of the format set to
the specified character.
*
- * @param quoteChar The quote character
- * @return A new CSVFormat that is equal to this but with the specified
character as quoteChar
+ * @param quoteChar The quote character.
+ * @return A new CSVFormat that is equal to this but with the specified
character as quoteChar.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or any attribute is invalid or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setQuote(char)}
+ * @deprecated Use {@link Builder#setQuote(char)}.
*/
@Deprecated
public CSVFormat withQuote(final char quoteChar) {
@@ -3243,9 +3664,9 @@ public final class CSVFormat implements Serializable {
* Builds a new {@code CSVFormat} with the quoteChar of the format set to
the specified character.
*
* @param quoteChar The quote character, use {@code null} to disable.
- * @return A new CSVFormat that is equal to this but with the specified
character as quoteChar
+ * @return A new CSVFormat that is equal to this but with the specified
character as quoteChar.
* @throws IllegalArgumentException thrown if the specified character is a
line break, or any attribute is invalid or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setQuote(Character)}
+ * @deprecated Use {@link Builder#setQuote(Character)}.
*/
@Deprecated
public CSVFormat withQuote(final Character quoteChar) {
@@ -3253,12 +3674,17 @@ public final class CSVFormat implements Serializable {
}
/**
- * Builds a new {@code CSVFormat} with the output quote policy of the
format set to the specified value.
+ * Builds a new {@code CSVFormat} with the specified quote policy.
*
- * @param quoteMode The quote policy to use for output.
- * @return A new CSVFormat that is equal to this but with the specified
quote policy
+ * <p>
+ * This policy also affects null-value parsing with {@link
QuoteMode#ALL_NON_NULL} and {@link QuoteMode#NON_NUMERIC}.
+ * See {@link CSVFormat#getNullString()} for details.
+ * </p>
+ *
+ * @param quoteMode The quote policy, or {@code null} to use {@link
QuoteMode#MINIMAL} for output.
+ * @return A new CSVFormat with the specified quote policy.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setQuoteMode(QuoteMode)}
+ * @deprecated Use {@link Builder#setQuoteMode(QuoteMode)}.
*/
@Deprecated
public CSVFormat withQuoteMode(final QuoteMode quoteMode) {
@@ -3274,9 +3700,9 @@ public final class CSVFormat implements Serializable {
* </p>
*
* @param recordSeparator The record separator to use for output.
- * @return A new CSVFormat that is equal to this but with the specified
output record separator
+ * @return A new CSVFormat that is equal to this but with the specified
output record separator.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setRecordSeparator(char)}
+ * @deprecated Use {@link Builder#setRecordSeparator(char)}.
*/
@Deprecated
public CSVFormat withRecordSeparator(final char recordSeparator) {
@@ -3285,15 +3711,16 @@ public final class CSVFormat implements Serializable {
/**
* Builds a new {@code CSVFormat} with the record separator of the format
set to the specified String.
+ *
* <p>
* <strong>Note:</strong> This setting is only used during printing and
does not affect parsing. Parsing currently only works for inputs with '\n',
'\r' and
* "\r\n"
* </p>
*
* @param recordSeparator The record separator to use for output.
- * @return A new CSVFormat that is equal to this but with the specified
output record separator
+ * @return A new CSVFormat that is equal to this but with the specified
output record separator.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
- * @deprecated Use {@link Builder#setRecordSeparator(String)}
+ * @deprecated Use {@link Builder#setRecordSeparator(String)}.
*/
@Deprecated
public CSVFormat withRecordSeparator(final String recordSeparator) {
@@ -3305,10 +3732,10 @@ public final class CSVFormat implements Serializable {
*
* @return A new CSVFormat that is equal to this but with the specified
skipHeaderRecord setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
+ * @since 1.1
* @see Builder#setSkipHeaderRecord(boolean)
* @see Builder#setHeader(String...)
- * @since 1.1
- * @deprecated Use {@link Builder#setSkipHeaderRecord(boolean)
Builder#setSkipHeaderRecord(true)}
+ * @deprecated Use {@link Builder#setSkipHeaderRecord(boolean)
Builder#setSkipHeaderRecord(true)}.
*/
@Deprecated
public CSVFormat withSkipHeaderRecord() {
@@ -3322,7 +3749,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the specified
skipHeaderRecord setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @see Builder#setHeader(String...)
- * @deprecated Use {@link Builder#setSkipHeaderRecord(boolean)}
+ * @deprecated Use {@link Builder#setSkipHeaderRecord(boolean)}.
*/
@Deprecated
public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
@@ -3341,7 +3768,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the operating
system's line separator string.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.6
- * @deprecated Use {@link Builder#setRecordSeparator(String)
setRecordSeparator(System.lineSeparator())}
+ * @deprecated Use {@link Builder#setRecordSeparator(String)
setRecordSeparator(System.lineSeparator())}.
*/
@Deprecated
public CSVFormat withSystemRecordSeparator() {
@@ -3354,7 +3781,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the trailing
delimiter setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
- * @deprecated Use {@link Builder#setTrailingDelimiter(boolean)
Builder#setTrailingDelimiter(true)}
+ * @deprecated Use {@link Builder#setTrailingDelimiter(boolean)
Builder#setTrailingDelimiter(true)}.
*/
@Deprecated
public CSVFormat withTrailingDelimiter() {
@@ -3368,7 +3795,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the specified
trailing delimiter setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
- * @deprecated Use {@link Builder#setTrailingDelimiter(boolean)}
+ * @deprecated Use {@link Builder#setTrailingDelimiter(boolean)}.
*/
@Deprecated
public CSVFormat withTrailingDelimiter(final boolean trailingDelimiter) {
@@ -3381,7 +3808,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the trim setting
on.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
- * @deprecated Use {@link Builder#setTrim(boolean) Builder#setTrim(true)}
+ * @deprecated Use {@link Builder#setTrim(boolean) Builder#setTrim(true)}.
*/
@Deprecated
public CSVFormat withTrim() {
@@ -3395,7 +3822,7 @@ public final class CSVFormat implements Serializable {
* @return A new CSVFormat that is equal to this but with the specified
trim setting.
* @throws IllegalArgumentException Thrown when any attribute is invalid
or inconsistent with other attributes.
* @since 1.3
- * @deprecated Use {@link Builder#setTrim(boolean)}
+ * @deprecated Use {@link Builder#setTrim(boolean)}.
*/
@Deprecated
public CSVFormat withTrim(final boolean trim) {