Class CSVFormat
- java.lang.Object
-
- org.apache.commons.csv.CSVFormat
-
- All Implemented Interfaces:
java.io.Serializable
public final class CSVFormat extends java.lang.Object implements java.io.SerializableSpecifies the format of a CSV file for parsing and writing.Using predefined formats
You can use one of the predefined formats:
DEFAULTEXCELINFORMIX_UNLOADINFORMIX_UNLOAD_CSVMONGODB_CSVMONGODB_TSVMYSQLORACLEPOSTGRESQL_CSVPOSTGRESQL_TEXTRFC4180TDF
For example:
CSVParser parser = CSVFormat.EXCEL.parse(reader);
The
CSVParserprovides static methods to parse other input types, for example:CSVParser parser = CSVParser.parse(file, StandardCharsets.US_ASCII, CSVFormat.EXCEL);
Defining formats
You can extend a format by calling the
setmethods. For example:CSVFormat.EXCEL.builder().setNullString("N/A").setIgnoreSurroundingSpaces(true).get();Defining column names
To define the column names you want to use to access records, write:
CSVFormat.EXCEL.builder().setHeader("Col1", "Col2", "Col3").get();Calling
CSVFormat.Builder.setHeader(String...)lets you use the given names to address values in aCSVRecord, and assumes that your CSV source does not contain a first record that also defines column names. If it does, then you are overriding this metadata with your names and you should skip the first record by callingCSVFormat.Builder.setSkipHeaderRecord(boolean)withtrue.Parsing
You can use a format directly to parse a reader. For example, to parse an Excel file with columns header, write:
Reader in = ...; CSVFormat.EXCEL.builder().setHeader("Col1", "Col2", "Col3").get().parse(in);For other input types, like resources, files, and URLs, use the static methods on
CSVParser.Referencing columns safely
If your source contains a header record, you can simplify your code and safely reference columns, by using
CSVFormat.Builder.setHeader(String...)with no arguments:CSVFormat.EXCEL.builder().setHeader().get();
This causes the parser to read the first record and use its values as column names. Then, call one of the
CSVRecordget method that takes a String column name argument:String value = record.get("Col1");This makes your code impervious to changes in column order in the CSV file.
Serialization
This class implements the
Serializableinterface with the following caveats:- This class will no longer implement Serializable in 2.0.
- Serialization is not supported from one version to the next.
The
serialVersionUIDvalues are:- Version 1.10.0:
2L - Version 1.9.0 through 1.0:
1L
Notes
This class is immutable.
Not all settings are used for both parsing and writing.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCSVFormat.BuilderBuilds CSVFormat instances.static classCSVFormat.PredefinedPredefines formats.
-
Field Summary
Fields Modifier and Type Field Description private booleanallowMissingColumnNamesWhether missing column names are allowed when parsing the header line.private booleanautoFlushWhether to flush on close.private java.lang.CharactercommentMarkerSet to null if commenting is disabled.static CSVFormatDEFAULTStandard Comma Separated Value format, as forRFC4180but allowing empty lines.private java.lang.StringdelimiterThe character delimiting the values (typically ";", "," or "\t").private DuplicateHeaderModeduplicateHeaderModeHow duplicate headers are handled.private java.lang.CharacterescapeCharacterSet to null if escaping is disabled.static CSVFormatEXCELMicrosoft Excel file format (using a comma as the value delimiter).private java.lang.String[]headerCommentsArray of header comment lines.private java.lang.String[]headersArray of header column names.private booleanignoreEmptyLinesWhether empty lines between records are ignored when parsing input.private booleanignoreHeaderCaseShould ignore header names case.private booleanignoreSurroundingSpacesShould leading/trailing spaces be ignored around values?.static CSVFormatINFORMIX_UNLOADDefault Informix CSV UNLOAD format used by theUNLOAD TO file_nameoperation.static CSVFormatINFORMIX_UNLOAD_CSVDefault Informix CSV UNLOAD format used by theUNLOAD TO file_nameoperation (escaping is disabled.)private booleanlenientEofWhether reading end-of-file is allowed even when input is malformed, helps Excel compatibility.private longmaxRowsThe maximum number of rows to process, excluding the header row.static CSVFormatMONGODB_CSVDefault MongoDB CSV format used by themongoexportoperation.static CSVFormatMONGODB_TSVDefault MongoDB TSV format used by themongoexportoperation.static CSVFormatMYSQLprivate java.lang.StringnullStringThe string to be used for null values.static CSVFormatORACLEDefault Oracle format used by the SQL*Loader utility.static CSVFormatPOSTGRESQL_CSVDefault PostgreSQL CSV format used by theCOPYoperation.static CSVFormatPOSTGRESQL_TEXTDefault PostgreSQL Text format used by theCOPYoperation.private java.lang.CharacterquoteCharacterSet to null if quoting is disabled.private java.lang.StringquotedNullStringSet toquoteCharacter + nullString + quoteCharacterprivate QuoteModequoteModeThe quote policy output fields.private java.lang.StringrecordSeparatorFor output.static CSVFormatRFC4180Comma separated format as defined by RFC 4180.private static longserialVersionUIDprivate booleanskipHeaderRecordWhether to skip the header record.static CSVFormatTDFTab-delimited format (TDF).private booleantrailingDataWhether reading trailing data is allowed in records, helps Excel compatibility.private booleantrailingDelimiterWhether to add a trailing delimiter.private booleantrimWhether to trim leading and trailing blanks.
-
Constructor Summary
Constructors Modifier Constructor Description privateCSVFormat(CSVFormat.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidappend(char c, java.lang.Appendable appendable)private voidappend(java.lang.CharSequence csq, java.lang.Appendable appendable)CSVFormat.Builderbuilder()Creates a new Builder for this instance.(package private) static <T> T[]clone(T... values)Null-safe clone of an array.private static booleancontains(java.lang.String source, char searchCh)Returns true if the given string contains the search char.private static booleancontainsLineBreak(java.lang.String source)Returns true if the given string contains a line break character.(package private) CSVFormatcopy()Creates a copy of this instance.(package private) static CSVFormatcopy(CSVFormat format)Creates a null-safe copy of the given instance.booleanequals(java.lang.Object obj)private voidescape(char c, java.lang.Appendable appendable)java.lang.Stringformat(java.lang.Object... values)Formats the specified values as a CSV record string.private java.lang.Stringformat_(java.lang.Object... values)booleangetAllowDuplicateHeaderNames()Deprecated.booleangetAllowMissingColumnNames()Gets whether missing column names are allowed when parsing the header line.booleangetAutoFlush()Gets whether to flush on close.java.lang.CharactergetCommentMarker()Gets the comment marker character,nulldisables comments.chargetDelimiter()Deprecated.UsegetDelimiterString().(package private) char[]getDelimiterCharArray()Gets the character delimiting the values (typically ";", "," or "\t").java.lang.StringgetDelimiterString()Gets the character delimiting the values (typically ";", "," or "\t").DuplicateHeaderModegetDuplicateHeaderMode()Gets how duplicate headers are handled.(package private) chargetEscapeChar()Gets the escape character.java.lang.CharactergetEscapeCharacter()Gets the escape character.java.lang.String[]getHeader()Gets a copy of the header array.java.lang.String[]getHeaderComments()Gets a copy of the header comment array to write before the CSV data.booleangetIgnoreEmptyLines()Gets whether empty lines between records are ignored when parsing input.booleangetIgnoreHeaderCase()Gets whether header names will be accessed ignoring case when parsing input.booleangetIgnoreSurroundingSpaces()Gets whether spaces around values are ignored when parsing input.booleangetLenientEof()Gets whether reading end-of-file is allowed even when input is malformed, helps Excel compatibility.longgetMaxRows()Gets the maximum number of rows to process, excluding the header row.java.lang.StringgetNullString()Gets the String to convert to and fromnull.java.lang.CharactergetQuoteCharacter()Gets the character used to encapsulate values containing special characters.QuoteModegetQuoteMode()Gets the quote policy output fields.java.lang.StringgetRecordSeparator()Gets the record separator delimiting output records.booleangetSkipHeaderRecord()Gets whether to skip the header record.booleangetTrailingData()Gets whether reading trailing data is allowed in records, helps Excel compatibility.booleangetTrailingDelimiter()Gets whether to add a trailing delimiter.booleangetTrim()Gets whether to trim leading and trailing blanks.inthashCode()(package private) static booleanisBlank(java.lang.String value)booleanisCommentMarkerSet()Tests whether comments are supported by this format.private booleanisDelimiter(char ch0, java.lang.CharSequence charSeq, int startIndex, char[] delimiter, int delimiterLength)Tests whether the next characters constitute a delimiterbooleanisEscapeCharacterSet()Tests whether escapes are being processed.private static booleanisLineBreak(char c)Returns true if the given character is a line break character.private static booleanisLineBreak(java.lang.Character c)Returns true if the given character is a line break character.booleanisNullStringSet()Tests whether a null string has been defined.booleanisQuoteCharacterSet()Tests whether a quoteChar has been defined.private static booleanisTrimChar(char ch)Same test as in asString.trim().private static booleanisTrimChar(java.lang.CharSequence charSequence, int pos)Same test as in asString.trim().(package private) <T> org.apache.commons.io.function.IOStream<T>limit(org.apache.commons.io.function.IOStream<T> stream)static CSVFormatnewFormat(char delimiter)Creates a new CSV format with the specified delimiter.CSVParserparse(java.io.Reader reader)Parses the specified content.CSVPrinterprint(java.io.File out, java.nio.charset.Charset charset)Prints to the specifiedFilewith givenCharset.private voidprint(java.io.InputStream inputStream, java.lang.Appendable out, boolean newRecord)private voidprint(java.io.Reader reader, java.lang.Appendable out, boolean newRecord)CSVPrinterprint(java.lang.Appendable out)Prints to the specified output.voidprint(java.lang.Object value, java.lang.Appendable out, boolean newRecord)Prints thevalueas the next value on the line toout.private voidprint(java.lang.Object object, java.lang.CharSequence value, java.lang.Appendable out, boolean newRecord)CSVPrinterprint(java.nio.file.Path out, java.nio.charset.Charset charset)Prints to the specifiedPathwith givenCharset, returns aCSVPrinterwhich the caller MUST close.CSVPrinterprinter()Prints to theSystem.out.voidprintln(java.lang.Appendable appendable)Outputs the trailing delimiter (if set) followed by the record separator (if set).voidprintRecord(java.lang.Appendable appendable, java.lang.Object... values)Prints the givenvaluestooutas a single record of delimiter-separated values followed by the record separator.private voidprintWithEscapes(java.io.Reader reader, java.lang.Appendable appendable)private voidprintWithEscapes(java.lang.CharSequence charSeq, java.lang.Appendable appendable)private voidprintWithQuotes(java.io.Reader reader, java.lang.Appendable appendable)Always use quotes unless QuoteMode is NONE, so we do not have to look ahead.private voidprintWithQuotes(java.lang.Object object, java.lang.CharSequence charSeq, java.lang.Appendable out, boolean newRecord)java.lang.StringtoString()(package private) static java.lang.String[]toStringArray(java.lang.Object[] values)(package private) static java.lang.CharSequencetrim(java.lang.CharSequence charSequence)(package private) java.lang.Stringtrim(java.lang.String value)(package private) booleanuseMaxRows()(package private) booleanuseRow(long rowNum)private voidvalidate()Verifies the validity and consistency of the attributes, and throws anIllegalArgumentExceptionif necessary.static CSVFormatvalueOf(java.lang.String format)Gets one of the predefined formats fromCSVFormat.Predefined.CSVFormatwithAllowDuplicateHeaderNames()Deprecated.CSVFormatwithAllowDuplicateHeaderNames(boolean allowDuplicateHeaderNames)Deprecated.CSVFormatwithAllowMissingColumnNames()Deprecated.CSVFormatwithAllowMissingColumnNames(boolean allowMissingColumnNames)Deprecated.CSVFormatwithAutoFlush(boolean autoFlush)Deprecated.CSVFormatwithCommentMarker(char commentMarker)Deprecated.CSVFormatwithCommentMarker(java.lang.Character commentMarker)Deprecated.CSVFormatwithDelimiter(char delimiter)Deprecated.CSVFormatwithEscape(char escape)Deprecated.CSVFormatwithEscape(java.lang.Character escape)Deprecated.CSVFormatwithFirstRecordAsHeader()Deprecated.CSVFormatwithHeader(java.lang.Class<? extends java.lang.Enum<?>> headerEnum)Deprecated.CSVFormatwithHeader(java.lang.String... header)Deprecated.CSVFormatwithHeader(java.sql.ResultSet resultSet)Deprecated.CSVFormatwithHeader(java.sql.ResultSetMetaData resultSetMetaData)Deprecated.CSVFormatwithHeaderComments(java.lang.Object... headerComments)Deprecated.CSVFormatwithIgnoreEmptyLines()Deprecated.CSVFormatwithIgnoreEmptyLines(boolean ignoreEmptyLines)Deprecated.CSVFormatwithIgnoreHeaderCase()Deprecated.CSVFormatwithIgnoreHeaderCase(boolean ignoreHeaderCase)Deprecated.CSVFormatwithIgnoreSurroundingSpaces()Deprecated.CSVFormatwithIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)Deprecated.CSVFormatwithNullString(java.lang.String nullString)Deprecated.CSVFormatwithQuote(char quoteChar)Deprecated.CSVFormatwithQuote(java.lang.Character quoteChar)Deprecated.CSVFormatwithQuoteMode(QuoteMode quoteMode)Deprecated.CSVFormatwithRecordSeparator(char recordSeparator)Deprecated.CSVFormatwithRecordSeparator(java.lang.String recordSeparator)Deprecated.CSVFormatwithSkipHeaderRecord()Deprecated.CSVFormatwithSkipHeaderRecord(boolean skipHeaderRecord)Deprecated.CSVFormatwithSystemRecordSeparator()Deprecated.CSVFormatwithTrailingDelimiter()Deprecated.CSVFormatwithTrailingDelimiter(boolean trailingDelimiter)Deprecated.CSVFormatwithTrim()Deprecated.CSVFormatwithTrim(boolean trim)Deprecated.
-
-
-
Field Detail
-
DEFAULT
public static final CSVFormat DEFAULT
Standard Comma Separated Value format, as forRFC4180but allowing empty lines.The
CSVFormat.Buildersettings are:setDelimiter(',')setQuote('"')setRecordSeparator("\r\n")setIgnoreEmptyLines(true)setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL)
-
EXCEL
public static final CSVFormat EXCEL
Microsoft Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is locale-dependent, it might be necessary to customize this format to accommodate your regional settings.For example for parsing or generating a CSV file on a French system the following format will be used:
CSVFormat format = CSVFormat.EXCEL.builder().setDelimiter(';').get();The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setQuote('"')setRecordSeparator("\r\n")setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL)setIgnoreEmptyLines(false)setAllowMissingColumnNames(true)setTrailingData(true)setLenientEof(true)
Note: This is currently like
RFC4180plusBuilder#setAllowMissingColumnNames(true)andBuilder#setIgnoreEmptyLines(false).
-
INFORMIX_UNLOAD
public static final CSVFormat INFORMIX_UNLOAD
Default Informix CSV UNLOAD format used by theUNLOAD TO file_nameoperation.This is a comma-delimited format with an LF character as the line separator. Values are not quoted and special characters are escaped with
'\'. The default NULL string is"\\N".The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setEscape('\\')setQuote('\"')setRecordSeparator('\n')
- Since:
- 1.3
- See Also:
CSVFormat.Predefined.MySQL, Informix CSV UNLOAD
-
INFORMIX_UNLOAD_CSV
public static final CSVFormat INFORMIX_UNLOAD_CSV
Default Informix CSV UNLOAD format used by theUNLOAD TO file_nameoperation (escaping is disabled.)This is a comma-delimited format with an LF character as the line separator. Values are not quoted and special characters are escaped with
'\'. The default NULL string is"\\N".The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setQuote('\"')setRecordSeparator('\n')
-
MONGODB_CSV
public static final CSVFormat MONGODB_CSV
Default MongoDB CSV format used by themongoexportoperation.Parsing is not supported yet.
This is a comma-delimited format. Values are double quoted only if needed and special characters are escaped with
'"'. A header line with field names is expected.As of 2024-04-05, the MongoDB documentation for
mongoimportstates:The csv parser accepts that data that complies with RFC RFC-4180. 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.
The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setEscape('"')setQuote('"')setQuoteMode(QuoteMode.MINIMAL)
- Since:
- 1.7
- See Also:
CSVFormat.Predefined.MongoDBCsv,QuoteMode.ALL_NON_NULL, MongoDB mongoexport command documentation
-
MONGODB_TSV
public static final CSVFormat MONGODB_TSV
Default MongoDB TSV format used by themongoexportoperation.Parsing is not supported yet.
This is a tab-delimited format. Values are double quoted only if needed and special characters are escaped with
'"'. A header line with field names is expected.The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter('\t')setEscape('"')setQuote('"')setQuoteMode(QuoteMode.MINIMAL)setSkipHeaderRecord(false)
- Since:
- 1.7
- See Also:
CSVFormat.Predefined.MongoDBCsv,QuoteMode.ALL_NON_NULL, MongoDB mongoexport command documentation
-
MYSQL
public static final CSVFormat MYSQL
Default MySQL format used by theSELECT INTO OUTFILEandLOAD DATA INFILEoperations.This is a tab-delimited format with an LF character as the line separator. Values are not quoted and special characters are escaped with
'\'. The default NULL string is"\\N".The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter('\t')setEscape('\\')setIgnoreEmptyLines(false)setQuote(null)setRecordSeparator('\n')setNullString("\\N")setQuoteMode(QuoteMode.ALL_NON_NULL)
- See Also:
CSVFormat.Predefined.MySQL,QuoteMode.ALL_NON_NULL, MySQL
-
ORACLE
public static final CSVFormat ORACLE
Default Oracle format used by the SQL*Loader utility.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
'"'. The default NULL string is"". Values are trimmed.The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')// default isFIELDS TERMINATED BY ','}setEscape('\\')setIgnoreEmptyLines(false)setQuote('"')// default isOPTIONALLY ENCLOSED BY '"'}setNullString("\\N")setTrim(true)setRecordSeparator(System.lineSeparator())setQuoteMode(QuoteMode.MINIMAL)
- Since:
- 1.6
- See Also:
CSVFormat.Predefined.Oracle,QuoteMode.MINIMAL, Oracle CSV Format Specification
-
POSTGRESQL_CSV
public static final CSVFormat POSTGRESQL_CSV
Default PostgreSQL CSV format used by theCOPYoperation.This is a comma-delimited format with an LF character as the line separator. Values are double quoted and special characters are not escaped. The default NULL string is
"".The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setEscape(null)setIgnoreEmptyLines(false)setQuote('"')setRecordSeparator('\n')setNullString("")setQuoteMode(QuoteMode.ALL_NON_NULL)
- Since:
- 1.5
- See Also:
CSVFormat.Predefined.MySQL,QuoteMode.ALL_NON_NULL, PostgreSQL CSV
-
POSTGRESQL_TEXT
public static final CSVFormat POSTGRESQL_TEXT
Default PostgreSQL Text format used by theCOPYoperation.This is a tab-delimited format with an LF character as the line separator. Values are not quoted and special characters are escaped with
'\\'. The default NULL string is"\\N".The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter('\t')setEscape('\\')setIgnoreEmptyLines(false)setQuote(null)setRecordSeparator('\n')setNullString("\\N")setQuoteMode(QuoteMode.ALL_NON_NULL)
- Since:
- 1.5
- See Also:
CSVFormat.Predefined.MySQL,QuoteMode.ALL_NON_NULL, PostgreSQL Text
-
RFC4180
public static final CSVFormat RFC4180
Comma separated format as defined by RFC 4180.The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter(',')setQuote('"')setRecordSeparator("\r\n")setIgnoreEmptyLines(false)
- See Also:
CSVFormat.Predefined.RFC4180, RFC 4180
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
TDF
public static final CSVFormat TDF
Tab-delimited format (TDF).The
CSVFormat.Buildersettings are theDEFAULTwith:setDelimiter('\t')setIgnoreSurroundingSpaces(true)
- See Also:
CSVFormat.Predefined.TDF, TDF
-
duplicateHeaderMode
private final DuplicateHeaderMode duplicateHeaderMode
How duplicate headers are handled.
-
allowMissingColumnNames
private final boolean allowMissingColumnNames
Whether missing column names are allowed when parsing the header line.
-
autoFlush
private final boolean autoFlush
Whether to flush on close.
-
commentMarker
private final java.lang.Character commentMarker
Set to null if commenting is disabled.
-
delimiter
private final java.lang.String delimiter
The character delimiting the values (typically ";", "," or "\t").
-
escapeCharacter
private final java.lang.Character escapeCharacter
Set to null if escaping is disabled.
-
headers
private final java.lang.String[] headers
Array of header column names.
-
headerComments
private final java.lang.String[] headerComments
Array of header comment lines.
-
ignoreEmptyLines
private final boolean ignoreEmptyLines
Whether empty lines between records are ignored when parsing input.
-
ignoreHeaderCase
private final boolean ignoreHeaderCase
Should ignore header names case.
-
ignoreSurroundingSpaces
private final boolean ignoreSurroundingSpaces
Should leading/trailing spaces be ignored around values?.
-
nullString
private final java.lang.String nullString
The string to be used for null values.
-
quoteCharacter
private final java.lang.Character quoteCharacter
Set to null if quoting is disabled.
-
quotedNullString
private final java.lang.String quotedNullString
Set toquoteCharacter + nullString + quoteCharacter
-
quoteMode
private final QuoteMode quoteMode
The quote policy output fields.
-
recordSeparator
private final java.lang.String recordSeparator
For output.
-
skipHeaderRecord
private final boolean skipHeaderRecord
Whether to skip the header record.
-
lenientEof
private final boolean lenientEof
Whether reading end-of-file is allowed even when input is malformed, helps Excel compatibility.
-
trailingData
private final boolean trailingData
Whether reading trailing data is allowed in records, helps Excel compatibility.
-
trailingDelimiter
private final boolean trailingDelimiter
Whether to add a trailing delimiter.
-
trim
private final boolean trim
Whether to trim leading and trailing blanks.
-
maxRows
private final long maxRows
The maximum number of rows to process, excluding the header row.
-
-
Constructor Detail
-
CSVFormat
private CSVFormat(CSVFormat.Builder builder)
-
-
Method Detail
-
clone
@SafeVarargs static <T> T[] clone(T... values)
Null-safe clone of an array.- Type Parameters:
T- The array element type.- Parameters:
values- the source array- Returns:
- the cloned array.
-
contains
private static boolean contains(java.lang.String source, char searchCh)Returns true if the given string contains the search char.- Parameters:
source- the string to check.searchCh- the character to search.- Returns:
- true if
ccontains a line break character
-
containsLineBreak
private static boolean containsLineBreak(java.lang.String source)
Returns true if the given string contains a line break character.- Parameters:
source- the string to check.- Returns:
- true if
ccontains a line break character.
-
copy
static CSVFormat copy(CSVFormat format)
Creates a null-safe copy of the given instance.- Returns:
- a copy of the given instance or null if the input is null.
-
isBlank
static boolean isBlank(java.lang.String value)
-
isLineBreak
private static boolean isLineBreak(char c)
Returns true if the given character is a line break character.- Parameters:
c- the character to check.- Returns:
- true if
cis a line break character.
-
isLineBreak
private static boolean isLineBreak(java.lang.Character c)
Returns true if the given character is a line break character.- Parameters:
c- the character to check, may be null.- Returns:
- true if
cis a line break character (and not null).
-
isTrimChar
private static boolean isTrimChar(char ch)
Same test as in asString.trim().
-
isTrimChar
private static boolean isTrimChar(java.lang.CharSequence charSequence, int pos)Same test as in asString.trim().
-
newFormat
public static CSVFormat newFormat(char delimiter)
Creates a new CSV format with the specified delimiter.Use this method if you want to create a CSVFormat from scratch. All fields but the delimiter will be initialized with null/false.
-
toStringArray
static java.lang.String[] toStringArray(java.lang.Object[] values)
-
trim
static java.lang.CharSequence trim(java.lang.CharSequence charSequence)
-
valueOf
public static CSVFormat valueOf(java.lang.String format)
Gets one of the predefined formats fromCSVFormat.Predefined.- Parameters:
format- name- Returns:
- one of the predefined formats
- Since:
- 1.2
-
append
private void append(char c, java.lang.Appendable appendable) throws java.io.IOException- Throws:
java.io.IOException
-
append
private void append(java.lang.CharSequence csq, java.lang.Appendable appendable) throws java.io.IOException- Throws:
java.io.IOException
-
builder
public CSVFormat.Builder builder()
Creates a new Builder for this instance.- Returns:
- a new Builder.
-
copy
CSVFormat copy()
Creates a copy of this instance.- Returns:
- a copy of this instance.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
escape
private void escape(char c, java.lang.Appendable appendable) throws java.io.IOException- Throws:
java.io.IOException
-
format
public java.lang.String format(java.lang.Object... values)
Formats the specified values as a CSV record string.- Parameters:
values- the values to format.- Returns:
- the formatted values.
-
format_
private java.lang.String format_(java.lang.Object... values) throws java.io.IOException- Throws:
java.io.IOException
-
getAllowDuplicateHeaderNames
@Deprecated public boolean getAllowDuplicateHeaderNames()
Deprecated.Gets whether duplicate names are allowed in the headers.- Returns:
- whether duplicate header names are allowed
- Since:
- 1.7
-
getAllowMissingColumnNames
public boolean getAllowMissingColumnNames()
Gets whether missing column names are allowed when parsing the header line.- Returns:
trueif missing column names are allowed when parsing the header line,falseto throw anIllegalArgumentException.
-
getAutoFlush
public boolean getAutoFlush()
Gets whether to flush on close.- Returns:
- whether to flush on close.
- Since:
- 1.6
-
getCommentMarker
public java.lang.Character getCommentMarker()
Gets the comment marker character,nulldisables comments.The comment start character is only recognized at the start of a line.
Comments are printed first, before headers.
Use
CSVFormat.Builder.setCommentMarker(char)orCSVFormat.Builder.setCommentMarker(Character)to set the comment marker written at the start of each comment line.If the comment marker is not set, then the header comments are ignored.
For example:
builder.setCommentMarker('#').setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));writes:
# Generated by Apache Commons CSV. # 1970-01-01T00:00:00Z
- Returns:
- the comment start marker, may be
null
-
getDelimiter
@Deprecated public char getDelimiter()
Deprecated.UsegetDelimiterString().Gets the first character delimiting the values (typically ';', ',' or '\t').- Returns:
- the first delimiter character.
-
getDelimiterCharArray
char[] getDelimiterCharArray()
Gets the character delimiting the values (typically ";", "," or "\t").- Returns:
- the delimiter.
-
getDelimiterString
public java.lang.String getDelimiterString()
Gets the character delimiting the values (typically ";", "," or "\t").- Returns:
- the delimiter.
- Since:
- 1.9.0
-
getDuplicateHeaderMode
public DuplicateHeaderMode getDuplicateHeaderMode()
Gets how duplicate headers are handled.- Returns:
- if duplicate header values are allowed, allowed conditionally, or disallowed.
- Since:
- 1.10.0
-
getEscapeChar
char getEscapeChar()
Gets the escape character.- Returns:
- the escape character, may be
0
-
getEscapeCharacter
public java.lang.Character getEscapeCharacter()
Gets the escape character.- Returns:
- the escape character, may be
null
-
getHeader
public java.lang.String[] getHeader()
Gets a copy of the header array.- Returns:
- a copy of the header array;
nullif disabled, the empty array if to be read from the file
-
getHeaderComments
public java.lang.String[] getHeaderComments()
Gets a copy of the header comment array to write before the CSV data.This setting is ignored by the parser.
Comments are printed first, before headers.
Use
CSVFormat.Builder.setCommentMarker(char)orCSVFormat.Builder.setCommentMarker(Character)to set the comment marker written at the start of each comment line.If the comment marker is not set, then the header comments are ignored.
For example:
builder.setCommentMarker('#').setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));writes:
# Generated by Apache Commons CSV. # 1970-01-01T00:00:00Z
- Returns:
- a copy of the header comment array;
nullif disabled.
-
getIgnoreEmptyLines
public boolean getIgnoreEmptyLines()
Gets whether empty lines between records are ignored when parsing input.- Returns:
trueif empty lines between records are ignored,falseif they are turned into empty records.
-
getIgnoreHeaderCase
public boolean getIgnoreHeaderCase()
Gets whether header names will be accessed ignoring case when parsing input.- Returns:
trueif header names cases are ignored,falseif they are case-sensitive.- Since:
- 1.3
-
getIgnoreSurroundingSpaces
public boolean getIgnoreSurroundingSpaces()
Gets whether spaces around values are ignored when parsing input.- Returns:
trueif spaces around values are ignored,falseif they are treated as part of the value.
-
getLenientEof
public boolean getLenientEof()
Gets whether reading end-of-file is allowed even when input is malformed, helps Excel compatibility.- Returns:
- whether reading end-of-file is allowed even when input is malformed, helps Excel compatibility.
- Since:
- 1.11.0
-
getMaxRows
public long getMaxRows()
Gets the maximum number of rows to process, excluding the header row.Values less than or equal to 0 mean no limit.
- Returns:
- The maximum number of rows to process, excluding the header row.
- Since:
- 1.14.0
-
getNullString
public java.lang.String getNullString()
Gets the String to convert to and fromnull.- Reading: Converts strings equal to the given
nullStringtonullwhen reading records. - Writing: Writes
nullas the givennullStringwhen writing records.
- Returns:
- the String to convert to and from
null. No substitution occurs ifnull
- Reading: Converts strings equal to the given
-
getQuoteCharacter
public java.lang.Character getQuoteCharacter()
Gets the character used to encapsulate values containing special characters.- Returns:
- the quoteChar character, may be
null
-
getQuoteMode
public QuoteMode getQuoteMode()
Gets the quote policy output fields.- Returns:
- the quote policy
-
getRecordSeparator
public java.lang.String getRecordSeparator()
Gets the record separator delimiting output records.- Returns:
- the record separator
-
getSkipHeaderRecord
public boolean getSkipHeaderRecord()
Gets whether to skip the header record.- Returns:
- whether to skip the header record.
-
getTrailingData
public boolean getTrailingData()
Gets whether reading trailing data is allowed in records, helps Excel compatibility.- Returns:
- whether reading trailing data is allowed in records, helps Excel compatibility.
- Since:
- 1.11.0
-
getTrailingDelimiter
public boolean getTrailingDelimiter()
Gets whether to add a trailing delimiter.- Returns:
- whether to add a trailing delimiter.
- Since:
- 1.3
-
getTrim
public boolean getTrim()
Gets whether to trim leading and trailing blanks. This is used byprint(Object, Appendable, boolean)Also by {CSVParser#addRecordValue(boolean)}- Returns:
- whether to trim leading and trailing blanks.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isCommentMarkerSet
public boolean isCommentMarkerSet()
Tests whether comments are supported by this format. Note that the comment introducer character is only recognized at the start of a line.- Returns:
trueis comments are supported,falseotherwise
-
isDelimiter
private boolean isDelimiter(char ch0, java.lang.CharSequence charSeq, int startIndex, char[] delimiter, int delimiterLength)Tests whether the next characters constitute a delimiter- Parameters:
ch0- the first char (index 0).charSeq- the match char sequencestartIndex- where start to matchdelimiter- the delimiterdelimiterLength- the delimiter length- Returns:
- true if the match is successful
-
isEscapeCharacterSet
public boolean isEscapeCharacterSet()
Tests whether escapes are being processed.- Returns:
trueif escapes are processed
-
isNullStringSet
public boolean isNullStringSet()
Tests whether a null string has been defined.- Returns:
trueif a nullString is defined
-
isQuoteCharacterSet
public boolean isQuoteCharacterSet()
Tests whether a quoteChar has been defined.- Returns:
trueif a quoteChar is defined
-
limit
<T> org.apache.commons.io.function.IOStream<T> limit(org.apache.commons.io.function.IOStream<T> stream)
-
parse
public CSVParser parse(java.io.Reader reader) throws java.io.IOException
Parses the specified content.See also the various static parse methods on
CSVParser.- Parameters:
reader- the input stream- Returns:
- a parser over a stream of
CSVRecords. - Throws:
java.io.IOException- If an I/O error occursCSVException- Thrown on invalid input.
-
print
public CSVPrinter print(java.lang.Appendable out) throws java.io.IOException
Prints to the specified output.See also
CSVPrinter.- Parameters:
out- the output.- Returns:
- a printer to an output.
- Throws:
java.io.IOException- thrown if the optional header cannot be printed.
-
print
public CSVPrinter print(java.io.File out, java.nio.charset.Charset charset) throws java.io.IOException
- Parameters:
out- the output.charset- A charset.- Returns:
- a printer to an output.
- Throws:
java.io.IOException- thrown if the optional header cannot be printed.- Since:
- 1.5
-
print
private void print(java.io.InputStream inputStream, java.lang.Appendable out, boolean newRecord) throws java.io.IOException- Throws:
java.io.IOException
-
print
public void print(java.lang.Object value, java.lang.Appendable out, boolean newRecord) throws java.io.IOExceptionPrints thevalueas the next value on the line toout. The value will be escaped or encapsulated as needed. Useful when one wants to avoid creating CSVPrinters. Trims the value ifgetTrim()is true.- Parameters:
value- value to output.out- where to print the value.newRecord- if this a new record.- Throws:
java.io.IOException- If an I/O error occurs.- Since:
- 1.4
-
print
private void print(java.lang.Object object, java.lang.CharSequence value, java.lang.Appendable out, boolean newRecord) throws java.io.IOException- Throws:
java.io.IOException
-
print
public CSVPrinter print(java.nio.file.Path out, java.nio.charset.Charset charset) throws java.io.IOException
Prints to the specifiedPathwith givenCharset, returns aCSVPrinterwhich the caller MUST close.See also
CSVPrinter.- Parameters:
out- the output.charset- A charset.- Returns:
- a printer to an output.
- Throws:
java.io.IOException- thrown if the optional header cannot be printed.- Since:
- 1.5
-
print
private void print(java.io.Reader reader, java.lang.Appendable out, boolean newRecord) throws java.io.IOException- Throws:
java.io.IOException
-
printer
public CSVPrinter printer() throws java.io.IOException
Prints to theSystem.out.See also
CSVPrinter.- Returns:
- a printer to
System.out. - Throws:
java.io.IOException- thrown if the optional header cannot be printed.- Since:
- 1.5
-
println
public void println(java.lang.Appendable appendable) throws java.io.IOExceptionOutputs the trailing delimiter (if set) followed by the record separator (if set).- Parameters:
appendable- where to write- Throws:
java.io.IOException- If an I/O error occurs.- Since:
- 1.4
-
printRecord
public void printRecord(java.lang.Appendable appendable, java.lang.Object... values) throws java.io.IOExceptionPrints the givenvaluestooutas a single record of delimiter-separated values followed by the record separator.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
println(Appendable).- Parameters:
appendable- where to write.values- values to output.- Throws:
java.io.IOException- If an I/O error occurs.- Since:
- 1.4
-
printWithEscapes
private void printWithEscapes(java.lang.CharSequence charSeq, java.lang.Appendable appendable) throws java.io.IOException- Throws:
java.io.IOException
-
printWithEscapes
private void printWithEscapes(java.io.Reader reader, java.lang.Appendable appendable) throws java.io.IOException- Throws:
java.io.IOException
-
printWithQuotes
private void printWithQuotes(java.lang.Object object, java.lang.CharSequence charSeq, java.lang.Appendable out, boolean newRecord) throws java.io.IOException- Throws:
java.io.IOException
-
printWithQuotes
private void printWithQuotes(java.io.Reader reader, java.lang.Appendable appendable) throws java.io.IOExceptionAlways use quotes unless QuoteMode is NONE, so we do not have to look ahead.- Parameters:
reader- What to printappendable- Where to print it- Throws:
java.io.IOException- If an I/O error occurs
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
trim
java.lang.String trim(java.lang.String value)
-
useMaxRows
boolean useMaxRows()
-
useRow
boolean useRow(long rowNum)
-
validate
private void validate() throws java.lang.IllegalArgumentExceptionVerifies the validity and consistency of the attributes, and throws anIllegalArgumentExceptionif necessary.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.
- Throws:
java.lang.IllegalArgumentException- Throw when any attribute is invalid or inconsistent with other attributes.
-
withAllowDuplicateHeaderNames
@Deprecated public CSVFormat withAllowDuplicateHeaderNames()
Deprecated.Builds a newCSVFormatthat allows duplicate header names.- Returns:
- a new
CSVFormatthat allows duplicate header names - Since:
- 1.7
-
withAllowDuplicateHeaderNames
@Deprecated public CSVFormat withAllowDuplicateHeaderNames(boolean allowDuplicateHeaderNames)
Deprecated.Builds a newCSVFormatwith duplicate header names behavior set to the given value.- Parameters:
allowDuplicateHeaderNames- the duplicate header names behavior, true to allow, false to disallow.- Returns:
- a new
CSVFormatwith duplicate header names behavior set to the given value. - Since:
- 1.7
-
withAllowMissingColumnNames
@Deprecated public CSVFormat withAllowMissingColumnNames()
Deprecated.Builds a newCSVFormatwith the missing column names behavior of the format set totrue.- Returns:
- A new CSVFormat that is equal to this but with the specified missing column names behavior.
- Since:
- 1.1
- See Also:
CSVFormat.Builder.setAllowMissingColumnNames(boolean)
-
withAllowMissingColumnNames
@Deprecated public CSVFormat withAllowMissingColumnNames(boolean allowMissingColumnNames)
Deprecated.Builds a newCSVFormatwith the missing column names behavior of the format set to the given value.- Parameters:
allowMissingColumnNames- the missing column names behavior,trueto allow missing column names in the header line,falseto cause anIllegalArgumentExceptionto be thrown.- Returns:
- A new CSVFormat that is equal to this but with the specified missing column names behavior.
-
withAutoFlush
@Deprecated public CSVFormat withAutoFlush(boolean autoFlush)
Deprecated.Builds a newCSVFormatwith whether to flush on close.- Parameters:
autoFlush- whether to flush on close.- Returns:
- A new CSVFormat that is equal to this but with the specified autoFlush setting.
- Since:
- 1.6
-
withCommentMarker
@Deprecated public CSVFormat withCommentMarker(char commentMarker)
Deprecated.Builds a newCSVFormatwith 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.- Parameters:
commentMarker- the comment start marker- Returns:
- A new CSVFormat that is equal to this one but with the specified character as the comment start marker
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withCommentMarker
@Deprecated public CSVFormat withCommentMarker(java.lang.Character commentMarker)
Deprecated.Builds a newCSVFormatwith 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.- Parameters:
commentMarker- the comment start marker, usenullto disable- Returns:
- A new CSVFormat that is equal to this one but with the specified character as the comment start marker
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withDelimiter
@Deprecated public CSVFormat withDelimiter(char delimiter)
Deprecated.Builds a newCSVFormatwith the delimiter of the format set to the specified character.- Parameters:
delimiter- the delimiter character- Returns:
- A new CSVFormat that is equal to this with the specified character as a delimiter
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withEscape
@Deprecated public CSVFormat withEscape(char escape)
Deprecated.Builds a newCSVFormatwith the escape character of the format set to the specified character.- Parameters:
escape- the escape character- Returns:
- A new CSVFormat that is equal to this but with the specified character as the escape character
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withEscape
@Deprecated public CSVFormat withEscape(java.lang.Character escape)
Deprecated.Builds a newCSVFormatwith the escape character of the format set to the specified character.- Parameters:
escape- the escape character, usenullto disable- Returns:
- A new CSVFormat that is equal to this but with the specified character as the escape character
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withFirstRecordAsHeader
@Deprecated public CSVFormat withFirstRecordAsHeader()
Deprecated.Builds a newCSVFormatusing the first record as header.Calling this method is equivalent to calling:
CSVFormat format = aFormat.builder() .setHeader() .setSkipHeaderRecord(true) .get();- Returns:
- A new CSVFormat that is equal to this but using the first record as header.
- Since:
- 1.3
- See Also:
CSVFormat.Builder.setSkipHeaderRecord(boolean),CSVFormat.Builder.setHeader(String...)
-
withHeader
@Deprecated public CSVFormat withHeader(java.lang.Class<? extends java.lang.Enum<?>> headerEnum)
Deprecated.Builds a newCSVFormatwith the header of the format defined by the enum class.Example:
public enum MyHeader { Name, Email, Phone } ... CSVFormat format = aFormat.builder().setHeader(MyHeader.class).get();The header is also used by the
CSVPrinter.- Parameters:
headerEnum- the enum defining the header,nullif disabled, empty if parsed automatically, user specified otherwise.- Returns:
- A new CSVFormat that is equal to this but with the specified header
- Since:
- 1.3
- See Also:
CSVFormat.Builder.setHeader(String...),CSVFormat.Builder.setSkipHeaderRecord(boolean)
-
withHeader
@Deprecated public CSVFormat withHeader(java.sql.ResultSet resultSet) throws java.sql.SQLException
Deprecated.Builds a newCSVFormatwith the header of the format set from the result set metadata. The header can either be parsed automatically from the input file with:CSVFormat format = aFormat.builder().setHeader().get();
or specified manually with:CSVFormat format = aFormat.builder().setHeader(resultSet).get();
The header is also used by the
CSVPrinter.- Parameters:
resultSet- the resultSet for the header,nullif disabled, empty if parsed automatically, user-specified otherwise.- Returns:
- A new CSVFormat that is equal to this but with the specified header
- Throws:
java.sql.SQLException- SQLException if a database access error occurs or this method is called on a closed result set.- Since:
- 1.1
-
withHeader
@Deprecated public CSVFormat withHeader(java.sql.ResultSetMetaData resultSetMetaData) throws java.sql.SQLException
Deprecated.Builds a newCSVFormatwith the header of the format set from the result set metadata. The header can either be parsed automatically from the input file with:CSVFormat format = aFormat.builder().setHeader().get()
or specified manually with:CSVFormat format = aFormat.builder().setHeader(resultSetMetaData).get()
The header is also used by the
CSVPrinter.- Parameters:
resultSetMetaData- the metaData for the header,nullif disabled, empty if parsed automatically, user specified otherwise.- Returns:
- A new CSVFormat that is equal to this but with the specified header
- Throws:
java.sql.SQLException- SQLException if a database access error occurs or this method is called on a closed result set.- Since:
- 1.1
-
withHeader
@Deprecated public CSVFormat withHeader(java.lang.String... header)
Deprecated.Builds a newCSVFormatwith the header of the format set to the given values. The header can either be parsed automatically from the input file with:CSVFormat format = aFormat.builder().setHeader().get();
or specified manually with:CSVFormat format = aFormat.builder().setHeader("name", "email", "phone").get();The header is also used by the
CSVPrinter.- Parameters:
header- the header,nullif disabled, empty if parsed automatically, user-specified otherwise.- Returns:
- A new CSVFormat that is equal to this but with the specified header
- See Also:
CSVFormat.Builder.setSkipHeaderRecord(boolean)
-
withHeaderComments
@Deprecated public CSVFormat withHeaderComments(java.lang.Object... headerComments)
Deprecated.Builds a newCSVFormatwith the header comments of the format set to the given values. The comments will be printed first, before the headers. This setting is ignored by the parser.CSVFormat format = aFormat.builder().setHeaderComments("Generated by Apache Commons CSV.", Instant.now()).get();- Parameters:
headerComments- the headerComments which will be printed by the Printer before the actual CSV data.- Returns:
- A new CSVFormat that is equal to this but with the specified header
- Since:
- 1.1
- See Also:
CSVFormat.Builder.setSkipHeaderRecord(boolean)
-
withIgnoreEmptyLines
@Deprecated public CSVFormat withIgnoreEmptyLines()
Deprecated.Builds a newCSVFormatwith the empty line skipping behavior of the format set totrue.- Returns:
- A new CSVFormat that is equal to this but with the specified empty line skipping behavior.
- Since:
- 1.1
- See Also:
CSVFormat.Builder.setIgnoreEmptyLines(boolean)
-
withIgnoreEmptyLines
@Deprecated public CSVFormat withIgnoreEmptyLines(boolean ignoreEmptyLines)
Deprecated.Builds a newCSVFormatwith the empty line skipping behavior of the format set to the given value.- Parameters:
ignoreEmptyLines- the empty line skipping behavior,trueto ignore the empty lines between the records,falseto translate empty lines to empty records.- Returns:
- A new CSVFormat that is equal to this but with the specified empty line skipping behavior.
-
withIgnoreHeaderCase
@Deprecated public CSVFormat withIgnoreHeaderCase()
Deprecated.Builds a newCSVFormatwith the header ignore case behavior set totrue.- Returns:
- A new CSVFormat that will ignore the new case header name behavior.
- Since:
- 1.3
- See Also:
CSVFormat.Builder.setIgnoreHeaderCase(boolean)
-
withIgnoreHeaderCase
@Deprecated public CSVFormat withIgnoreHeaderCase(boolean ignoreHeaderCase)
Deprecated.Builds a newCSVFormatwith whether header names should be accessed ignoring case.- Parameters:
ignoreHeaderCase- the case mapping behavior,trueto access name/values,falseto leave the mapping as is.- Returns:
- A new CSVFormat that will ignore case header name if specified as
true - Since:
- 1.3
-
withIgnoreSurroundingSpaces
@Deprecated public CSVFormat withIgnoreSurroundingSpaces()
Deprecated.Builds a newCSVFormatwith the parser trimming behavior of the format set totrue.- Returns:
- A new CSVFormat that is equal to this but with the specified parser trimming behavior.
- Since:
- 1.1
- See Also:
CSVFormat.Builder.setIgnoreSurroundingSpaces(boolean)
-
withIgnoreSurroundingSpaces
@Deprecated public CSVFormat withIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)
Deprecated.Builds a newCSVFormatwith the parser trimming behavior of the format set to the given value.- Parameters:
ignoreSurroundingSpaces- the parser trimming behavior,trueto remove the surrounding spaces,falseto leave the spaces as is.- Returns:
- A new CSVFormat that is equal to this but with the specified trimming behavior.
-
withNullString
@Deprecated public CSVFormat withNullString(java.lang.String nullString)
Deprecated.Builds a newCSVFormatwith conversions to and from null for strings on input and output.- Reading: Converts strings equal to the given
nullStringtonullwhen reading records. - Writing: Writes
nullas the givennullStringwhen writing records.
- Parameters:
nullString- the String to convert to and fromnull. No substitution occurs ifnull- Returns:
- A new CSVFormat that is equal to this but with the specified null conversion string.
- Reading: Converts strings equal to the given
-
withQuote
@Deprecated public CSVFormat withQuote(char quoteChar)
Deprecated.Builds a newCSVFormatwith the quoteChar of the format set to the specified character.- Parameters:
quoteChar- the quote character- Returns:
- A new CSVFormat that is equal to this but with the specified character as quoteChar
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withQuote
@Deprecated public CSVFormat withQuote(java.lang.Character quoteChar)
Deprecated.Builds a newCSVFormatwith the quoteChar of the format set to the specified character.- Parameters:
quoteChar- the quote character, usenullto disable.- Returns:
- A new CSVFormat that is equal to this but with the specified character as quoteChar
- Throws:
java.lang.IllegalArgumentException- thrown if the specified character is a line break
-
withQuoteMode
@Deprecated public CSVFormat withQuoteMode(QuoteMode quoteMode)
Deprecated.Builds a newCSVFormatwith the output quote policy of the format set to the specified value.- Parameters:
quoteMode- the quote policy to use for output.- Returns:
- A new CSVFormat that is equal to this but with the specified quote policy
-
withRecordSeparator
@Deprecated public CSVFormat withRecordSeparator(char recordSeparator)
Deprecated.Builds a newCSVFormatwith the record separator of the format set to the specified character.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"
- Parameters:
recordSeparator- the record separator to use for output.- Returns:
- A new CSVFormat that is equal to this but with the specified output record separator
-
withRecordSeparator
@Deprecated public CSVFormat withRecordSeparator(java.lang.String recordSeparator)
Deprecated.Builds a newCSVFormatwith the record separator of the format set to the specified String.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"
- Parameters:
recordSeparator- the record separator to use for output.- Returns:
- A new CSVFormat that is equal to this but with the specified output record separator
- Throws:
java.lang.IllegalArgumentException- if recordSeparator is none of CR, LF or CRLF
-
withSkipHeaderRecord
@Deprecated public CSVFormat withSkipHeaderRecord()
Deprecated.Builds a newCSVFormatwith skipping the header record set totrue.- Returns:
- A new CSVFormat that is equal to this but with the specified skipHeaderRecord setting.
- Since:
- 1.1
- See Also:
CSVFormat.Builder.setSkipHeaderRecord(boolean),CSVFormat.Builder.setHeader(String...)
-
withSkipHeaderRecord
@Deprecated public CSVFormat withSkipHeaderRecord(boolean skipHeaderRecord)
Deprecated.Builds a newCSVFormatwith whether to skip the header record.- Parameters:
skipHeaderRecord- whether to skip the header record.- Returns:
- A new CSVFormat that is equal to this but with the specified skipHeaderRecord setting.
- See Also:
CSVFormat.Builder.setHeader(String...)
-
withSystemRecordSeparator
@Deprecated public CSVFormat withSystemRecordSeparator()
Deprecated.Builds a newCSVFormatwith the record separator of the format set to the operating system's line separator string, typically CR+LF on Windows and LF on Linux.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"
- Returns:
- A new CSVFormat that is equal to this but with the operating system's line separator string.
- Since:
- 1.6
-
withTrailingDelimiter
@Deprecated public CSVFormat withTrailingDelimiter()
Deprecated.Builds a newCSVFormatto add a trailing delimiter.- Returns:
- A new CSVFormat that is equal to this but with the trailing delimiter setting.
- Since:
- 1.3
-
withTrailingDelimiter
@Deprecated public CSVFormat withTrailingDelimiter(boolean trailingDelimiter)
Deprecated.Builds a newCSVFormatwith whether to add a trailing delimiter.- Parameters:
trailingDelimiter- whether to add a trailing delimiter.- Returns:
- A new CSVFormat that is equal to this but with the specified trailing delimiter setting.
- Since:
- 1.3
-
withTrim
@Deprecated public CSVFormat withTrim()
Deprecated.Builds a newCSVFormatto trim leading and trailing blanks. SeegetTrim()for details of where this is used.- Returns:
- A new CSVFormat that is equal to this but with the trim setting on.
- Since:
- 1.3
-
withTrim
@Deprecated public CSVFormat withTrim(boolean trim)
Deprecated.Builds a newCSVFormatwith whether to trim leading and trailing blanks. SeegetTrim()for details of where this is used.- Parameters:
trim- whether to trim leading and trailing blanks.- Returns:
- A new CSVFormat that is equal to this but with the specified trim setting.
- Since:
- 1.3
-
-