public class CSVFormat
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static CSVFormat |
DEFAULT
Standard comma separated format, as for
RFC4180 but allowing blank lines. |
static CSVFormat |
EXCEL
Excel file format (using a comma as the value delimiter).
|
static CSVFormat |
MYSQL
Default MySQL format used by the SELECT INTO OUTFILE and LOAD DATA INFILE operations.
|
static CSVFormat |
RFC4180
Comma separated format as defined by RFC 4180.
|
static CSVFormat |
TDF
Tab-delimited format, with quote; leading and trailing spaces ignored.
|
Constructor and Description |
---|
CSVFormat(char delimiter)
Creates a basic CSV format.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.lang.Object... values)
Format the specified values.
|
java.lang.Character |
getCommentStart()
Returns the character marking the start of a line comment.
|
char |
getDelimiter()
Returns the character delimiting the values (typically ';', ',' or '\t').
|
java.lang.Character |
getEscape()
Returns the escape character.
|
boolean |
getIgnoreEmptyLines()
Specifies whether empty lines between records are ignored when parsing input.
|
boolean |
getIgnoreSurroundingSpaces()
Specifies whether spaces around values are ignored when parsing input.
|
java.lang.Character |
getQuoteChar()
Returns the character used to encapsulate values containing special characters.
|
Quote |
getQuotePolicy()
Returns the quote policy output fields.
|
java.lang.String |
getRecordSeparator()
Returns the line separator delimiting output records.
|
boolean |
isCommentingEnabled()
Specifies whether comments are supported by this format.
|
boolean |
isEscaping()
Returns whether escape are being processed.
|
boolean |
isQuoting()
Returns whether an quoteChar has been defined.
|
java.lang.Iterable<CSVRecord> |
parse(java.io.Reader in)
Parses the specified content.
|
java.lang.String |
toString() |
CSVFormat |
withCommentStart(char commentStart)
Returns a copy of this format using the specified character as the comment start marker.
|
CSVFormat |
withCommentStart(java.lang.Character commentStart)
Returns a copy of this format using the specified character as the comment start marker.
|
CSVFormat |
withDelimiter(char delimiter)
Returns a copy of this format using the specified delimiter character.
|
CSVFormat |
withEscape(char escape)
Returns a copy of this format using the specified escape character.
|
CSVFormat |
withEscape(java.lang.Character escape)
Returns a copy of this format using the specified escape character.
|
CSVFormat |
withHeader(java.lang.String... header)
Returns a copy of this format using the specified header.
|
CSVFormat |
withIgnoreEmptyLines(boolean ignoreEmptyLines)
Returns a copy of this format with the specified empty line skipping behavior.
|
CSVFormat |
withIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)
Returns a copy of this format with the specified trimming behavior.
|
CSVFormat |
withQuoteChar(char quoteChar)
Returns a copy of this format using the specified quoteChar character.
|
CSVFormat |
withQuoteChar(java.lang.Character quoteChar)
Returns a copy of this format using the specified quoteChar character.
|
CSVFormat |
withQuotePolicy(Quote quotePolicy)
Returns a copy of this format using the specified output quote policy.
|
CSVFormat |
withRecordSeparator(char recordSeparator)
Returns a copy of this format using the specified output record separator.
|
CSVFormat |
withRecordSeparator(java.lang.String recordSeparator)
Returns a copy of this format using the specified output record separator.
|
public static final CSVFormat RFC4180
public static final CSVFormat DEFAULT
RFC4180
but allowing blank lines.
public static final CSVFormat EXCEL
CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';');Settings are:
public static final CSVFormat TDF
public static final CSVFormat MYSQL
public CSVFormat(char delimiter)
delimiter
- the char used for value separation, must not be a line break characterjava.lang.IllegalArgumentException
- if the delimiter is a line break characterpublic char getDelimiter()
public CSVFormat withDelimiter(char delimiter)
delimiter
- the delimiter characterjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic java.lang.Character getQuoteChar()
public CSVFormat withQuoteChar(char quoteChar)
quoteChar
- the quoteChar characterjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat withQuoteChar(java.lang.Character quoteChar)
quoteChar
- the quoteChar characterjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic boolean isQuoting()
true
if an quoteChar is definedpublic java.lang.Character getCommentStart()
public CSVFormat withCommentStart(char commentStart)
commentStart
- the comment start markerjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat withCommentStart(java.lang.Character commentStart)
commentStart
- the comment start markerjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic boolean isCommentingEnabled()
public java.lang.Character getEscape()
public CSVFormat withEscape(char escape)
escape
- the escape characterjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic CSVFormat withEscape(java.lang.Character escape)
escape
- the escape characterjava.lang.IllegalArgumentException
- thrown if the specified character is a line breakpublic boolean isEscaping()
true
if escapes are processedpublic boolean getIgnoreSurroundingSpaces()
public CSVFormat withIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces)
ignoreSurroundingSpaces
- the trimming behavior, true to remove the surrounding spaces, false to leave the
spaces as is.public boolean getIgnoreEmptyLines()
public CSVFormat withIgnoreEmptyLines(boolean ignoreEmptyLines)
ignoreEmptyLines
- the empty line skipping behavior, true to ignore the empty lines between the records,
false to translate empty lines to empty records.public java.lang.String getRecordSeparator()
public CSVFormat withRecordSeparator(char recordSeparator)
recordSeparator
- the record separator to use for output.public CSVFormat withRecordSeparator(java.lang.String recordSeparator)
recordSeparator
- the record separator to use for output.public CSVFormat withQuotePolicy(Quote quotePolicy)
quotePolicy
- the quote policy to use for output.public CSVFormat withHeader(java.lang.String... header)
CSVFormat format = aformat.withHeader();or specified manually with:
CSVFormat format = aformat.withHeader("name", "email", "phone");
header
- the header, null if disabled, empty if parsed automatically, user specified otherwise.public java.lang.Iterable<CSVRecord> parse(java.io.Reader in) throws java.io.IOException
in
- the input streamjava.io.IOException
public java.lang.String format(java.lang.Object... values)
values
- the values to formatpublic java.lang.String toString()
toString
in class java.lang.Object
public Quote getQuotePolicy()
This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.