public static class CSVFormat.Builder extends Object
Modifier and Type | Method and Description |
---|---|
CSVFormat |
build()
Builds a new CSVFormat instance.
|
static CSVFormat.Builder |
create()
Creates a new default builder.
|
static CSVFormat.Builder |
create(CSVFormat csvFormat)
Creates a new builder for the given format.
|
CSVFormat.Builder |
setAllowDuplicateHeaderNames(boolean allowDuplicateHeaderNames)
Deprecated.
|
CSVFormat.Builder |
setAllowMissingColumnNames(boolean allowMissingColumnNames)
Sets the parser missing column names behavior,
true to allow missing column names in the header line, false to cause an
IllegalArgumentException to be thrown. |
CSVFormat.Builder |
setAutoFlush(boolean autoFlush)
Sets whether to flush on close.
|
CSVFormat.Builder |
setCommentMarker(char commentMarker)
Sets the comment start marker, use
null to disable. |
CSVFormat.Builder |
setCommentMarker(Character commentMarker)
Sets the comment start marker, use
null to disable. |
CSVFormat.Builder |
setDelimiter(char delimiter)
Sets the delimiter character.
|
CSVFormat.Builder |
setDelimiter(String delimiter)
Sets the delimiter character.
|
CSVFormat.Builder |
setDuplicateHeaderMode(DuplicateHeaderMode duplicateHeaderMode)
Sets the duplicate header names behavior.
|
CSVFormat.Builder |
setEscape(char escapeCharacter)
Sets the escape character.
|
CSVFormat.Builder |
setEscape(Character escapeCharacter)
Sets the escape character.
|
CSVFormat.Builder |
setHeader(Class<? extends Enum<?>> headerEnum)
Sets the header defined by the given
Enum class. |
CSVFormat.Builder |
setHeader(ResultSet resultSet)
Sets the header from the result set metadata.
|
CSVFormat.Builder |
setHeader(ResultSetMetaData resultSetMetaData)
Sets the header from the result set metadata.
|
CSVFormat.Builder |
setHeader(String... header)
Sets the header to the given values.
|
CSVFormat.Builder |
setHeaderComments(Object... headerComments)
Sets the header comments set to the given values.
|
CSVFormat.Builder |
setHeaderComments(String... headerComments)
Sets the header comments set to the given values.
|
CSVFormat.Builder |
setIgnoreEmptyLines(boolean ignoreEmptyLines)
Sets the empty line skipping behavior,
true to ignore the empty lines between the records, false to translate empty lines to empty
records. |
CSVFormat.Builder |
setIgnoreHeaderCase(boolean ignoreHeaderCase)
Sets the parser case mapping behavior,
true to access name/values, false to leave the mapping as is. |
CSVFormat.Builder |
setIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)
Sets the parser trimming behavior,
true to remove the surrounding spaces, false to leave the spaces as is. |
CSVFormat.Builder |
setNullString(String nullString)
Sets the String to convert to and from
null . |
CSVFormat.Builder |
setQuote(char quoteCharacter)
Sets the quote character.
|
CSVFormat.Builder |
setQuote(Character quoteCharacter)
Sets the quote character, use
null to disable. |
CSVFormat.Builder |
setQuoteMode(QuoteMode quoteMode)
Sets the quote policy to use for output.
|
CSVFormat.Builder |
setRecordSeparator(char recordSeparator)
Sets the record separator to use for output.
|
CSVFormat.Builder |
setRecordSeparator(String recordSeparator)
Sets the record separator to use for output.
|
CSVFormat.Builder |
setSkipHeaderRecord(boolean skipHeaderRecord)
Sets whether to skip the header record.
|
CSVFormat.Builder |
setTrailingDelimiter(boolean trailingDelimiter)
Sets whether to add a trailing delimiter.
|
CSVFormat.Builder |
setTrim(boolean trim)
Sets whether to trim leading and trailing blanks.
|
public static CSVFormat.Builder create()
public static CSVFormat.Builder create(CSVFormat csvFormat)
csvFormat
- the source format.@Deprecated public CSVFormat.Builder setAllowDuplicateHeaderNames(boolean allowDuplicateHeaderNames)
setDuplicateHeaderMode(DuplicateHeaderMode)
.allowDuplicateHeaderNames
- the duplicate header names behavior, true to allow, false to disallow.public CSVFormat.Builder setAllowMissingColumnNames(boolean allowMissingColumnNames)
true
to allow missing column names in the header line, false
to cause an
IllegalArgumentException
to be thrown.allowMissingColumnNames
- the missing column names behavior, true
to allow missing column names in the header line, false
to
cause an IllegalArgumentException
to be thrown.public CSVFormat.Builder setAutoFlush(boolean autoFlush)
autoFlush
- whether to flush on close.public CSVFormat.Builder setCommentMarker(char commentMarker)
null
to disable.
Note that the comment start character is only recognized at the start of a line.commentMarker
- the comment start marker, use null
to disable.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat.Builder setCommentMarker(Character commentMarker)
null
to disable.
Note that the comment start character is only recognized at the start of a line.commentMarker
- the comment start marker, use null
to disable.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat.Builder setDelimiter(char delimiter)
delimiter
- the delimiter character.public CSVFormat.Builder setDelimiter(String delimiter)
delimiter
- the delimiter character.public CSVFormat.Builder setDuplicateHeaderMode(DuplicateHeaderMode duplicateHeaderMode)
duplicateHeaderMode
- the duplicate header names behaviorpublic CSVFormat.Builder setEscape(char escapeCharacter)
escapeCharacter
- the escape character.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat.Builder setEscape(Character escapeCharacter)
escapeCharacter
- the escape character.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat.Builder setHeader(Class<? extends Enum<?>> headerEnum)
Enum
class.
Example:
public enum HeaderEnum { Name, Email, Phone } Builder builder = builder.setHeader(HeaderEnum.class);
The header is also used by the CSVPrinter
.
headerEnum
- the enum defining the header, null
if disabled, empty if parsed automatically, user specified otherwise.public CSVFormat.Builder setHeader(ResultSet resultSet) throws SQLException
builder.setHeader();or specified manually with:
builder.setHeader(resultSet);
The header is also used by the CSVPrinter
.
resultSet
- the resultSet for the header, null
if disabled, empty if parsed automatically, user specified otherwise.SQLException
- SQLException if a database access error occurs or this method is called on a closed result set.public CSVFormat.Builder setHeader(ResultSetMetaData resultSetMetaData) throws SQLException
builder.setHeader();or specified manually with:
builder.setHeader(resultSetMetaData);
The header is also used by the CSVPrinter
.
resultSetMetaData
- the metaData for the header, null
if disabled, empty if parsed automatically, user specified otherwise.SQLException
- SQLException if a database access error occurs or this method is called on a closed result set.public CSVFormat.Builder setHeader(String... header)
builder.setHeader();or specified manually with:
builder.setHeader("name", "email", "phone");
The header is also used by the CSVPrinter
.
header
- the header, null
if disabled, empty if parsed automatically, user specified otherwise.public CSVFormat.Builder setHeaderComments(Object... headerComments)
builder.setHeaderComments("Generated by Apache Commons CSV.", Instant.now());
headerComments
- the headerComments which will be printed by the Printer before the actual CSV data.public CSVFormat.Builder setHeaderComments(String... headerComments)
Builder.setHeaderComments("Generated by Apache Commons CSV.", Instant.now());
headerComments
- the headerComments which will be printed by the Printer before the actual CSV data.public CSVFormat.Builder setIgnoreEmptyLines(boolean ignoreEmptyLines)
true
to ignore the empty lines between the records, false
to translate empty lines to empty
records.ignoreEmptyLines
- the empty line skipping behavior, true
to ignore the empty lines between the records, false
to translate
empty lines to empty records.public CSVFormat.Builder setIgnoreHeaderCase(boolean ignoreHeaderCase)
true
to access name/values, false
to leave the mapping as is.ignoreHeaderCase
- the case mapping behavior, true
to access name/values, false
to leave the mapping as is.public CSVFormat.Builder setIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)
true
to remove the surrounding spaces, false
to leave the spaces as is.ignoreSurroundingSpaces
- the parser trimming behavior, true
to remove the surrounding spaces, false
to leave the spaces as is.public CSVFormat.Builder setNullString(String nullString)
null
. No substitution occurs if null
.
nullString
to null
when reading records.null
as the given nullString
when writing records.nullString
- the String to convert to and from null
. No substitution occurs if null
.public CSVFormat.Builder setQuote(char quoteCharacter)
quoteCharacter
- the quote character.public CSVFormat.Builder setQuote(Character quoteCharacter)
null
to disable.quoteCharacter
- the quote character, use null
to disable.public CSVFormat.Builder setQuoteMode(QuoteMode quoteMode)
quoteMode
- the quote policy to use for output.public CSVFormat.Builder setRecordSeparator(char recordSeparator)
Note: This setting is only used during printing and does not affect parsing. Parsing currently only works for inputs with '\n', '\r' and "\r\n"
recordSeparator
- the record separator to use for output.public CSVFormat.Builder setRecordSeparator(String recordSeparator)
Note: This setting is only used during printing and does not affect parsing. Parsing currently only works for inputs with '\n', '\r' and "\r\n"
recordSeparator
- the record separator to use for output.public CSVFormat.Builder setSkipHeaderRecord(boolean skipHeaderRecord)
skipHeaderRecord
- whether to skip the header record.public CSVFormat.Builder setTrailingDelimiter(boolean trailingDelimiter)
trailingDelimiter
- whether to add a trailing delimiter.public CSVFormat.Builder setTrim(boolean trim)
trim
- whether to trim leading and trailing blanks.Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.