Class CsvPreference.Builder
java.lang.Object
org.supercsv.prefs.CsvPreference.Builder
- Enclosing class:
CsvPreference
Builds immutable CsvPreference instances. The builder pattern allows for additional preferences to be
added in the future.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CommentMatcherprivate final intprivate CsvEncoderprivate final Stringprivate booleanprivate intprivate final charprivate QuoteModeprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a Builder with the mandatory preference values.Builder(CsvPreference preference) Constructs a Builder with all of the values from an existing CsvPreference instance. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the CsvPreference instance.ignoreEmptyLines(boolean ignoreEmptyLines) Flag indicating whether empty lines (i.e.maxLinesPerRow(int maxLinesPerRow) The maximum number of lines that a row can span before an exception is thrown (only applicable when reading CSV).skipComments(CommentMatcher commentMatcher) Enables the skipping of comments.surroundingSpacesNeedQuotes(boolean surroundingSpacesNeedQuotes) Flag indicating whether spaces at the beginning or end of a cell should be ignored if they're not surrounded by quotes (applicable to both reading and writing CSV).useEncoder(CsvEncoder encoder) Uses a custom CsvEncoder to escape CSV for writing.useQuoteMode(QuoteMode quoteMode) Uses a custom QuoteMode to determine if surrounding quotes should be applied when writing (only applicable if a column doesn't contain any special characters and wouldn't otherwise be quoted).
-
Field Details
-
quoteChar
private final char quoteChar -
delimiterChar
private final int delimiterChar -
endOfLineSymbols
-
surroundingSpacesNeedQuotes
private boolean surroundingSpacesNeedQuotes -
ignoreEmptyLines
private boolean ignoreEmptyLines -
encoder
-
quoteMode
-
commentMatcher
-
maxLinesPerRow
private int maxLinesPerRow
-
-
Constructor Details
-
Builder
Constructs a Builder with all of the values from an existing CsvPreference instance. Useful if you want to base your preferences off one of the existing CsvPreference constants.- Parameters:
preference- the existing preference
-
Builder
Constructs a Builder with the mandatory preference values.- Parameters:
quoteChar- matching pairs of this character are used to escape columns containing the delimiterdelimiterChar- the character separating each columnendOfLineSymbols- one or more symbols terminating the line, e.g. "\n". Only used for writing.- Throws:
IllegalArgumentException- if quoteChar and delimiterChar are the same characterNullPointerException- if endOfLineSymbols is null
-
-
Method Details
-
surroundingSpacesNeedQuotes
Flag indicating whether spaces at the beginning or end of a cell should be ignored if they're not surrounded by quotes (applicable to both reading and writing CSV). The default is false, as spaces "are considered part of a field and should not be ignored" according to RFC 4180.- Parameters:
surroundingSpacesNeedQuotes- flag indicating whether spaces at the beginning or end of a cell should be ignored if they're not surrounded by quotes- Returns:
- the updated Builder
- Since:
- 2.0.0
-
ignoreEmptyLines
Flag indicating whether empty lines (i.e. containing only end of line symbols) should be ignored. The default is true.- Parameters:
ignoreEmptyLines- flag indicating whether empty lines should be ignored- Returns:
- the updated Builder
- Since:
- 2.2.1
-
skipComments
Enables the skipping of comments. You can supply your own comment matcher or use one of the predefined ones:CommentStartsWithorCommentMatches- Parameters:
commentMatcher- the comment matcher to use- Returns:
- the updated Builder
- Throws:
NullPointerException- if commentMatcher is null- Since:
- 2.1.0
-
useEncoder
Uses a custom CsvEncoder to escape CSV for writing.- Parameters:
encoder- the custom encoder- Returns:
- the updated Builder
- Throws:
NullPointerException- if encoder is null- Since:
- 2.1.0
-
useQuoteMode
Uses a custom QuoteMode to determine if surrounding quotes should be applied when writing (only applicable if a column doesn't contain any special characters and wouldn't otherwise be quoted). You can supply your own quote mode or use one of the predefined ones:AlwaysQuoteModeorColumnQuoteMode- Parameters:
quoteMode- the quote mode- Returns:
- the updated Builder
- Throws:
NullPointerException- if quoteMode is null- Since:
- 2.1.0
-
maxLinesPerRow
The maximum number of lines that a row can span before an exception is thrown (only applicable when reading CSV). This option allows CSV readers to fail fast when encountering CSV with mismatching quotes - the normal behaviour would be to continue reading until the matching quote is found, which could potentially mean reading the whole file (and exhausting all available memory). Zero or a negative value will disable this option. The default is 0.- Parameters:
maxLinesPerRow- the maximum number of lines a row can span before an exception is thrown- Returns:
- the updated Builder
- Since:
- 2.4.0
-
build
Builds the CsvPreference instance.- Returns:
- the immutable CsvPreference instance
-