Package com.univocity.parsers.csv
Class CsvFormat
- java.lang.Object
-
- com.univocity.parsers.common.Format
-
- com.univocity.parsers.csv.CsvFormat
-
- All Implemented Interfaces:
java.lang.Cloneable
public class CsvFormat extends Format
The CSV format configuration. In addition to the default configuration inFormat
, the CSV format defines:- delimiter (defaults to ','): the field delimiter character. Used to separate individual fields in a CSV record (where the record is usually a line of text with multiple fields).
e.g. the value a , b is parsed as [ a ][ b ]
- quote (defaults to '"'): character used for escaping values where the field delimiter is part of the value.
e.g. the value " a , b " is parsed as [ a , b ] (instead of [ a ][ b ]
- quoteEscape (defaults to '"'): character used for escaping the quote character inside an already quoted value
e.g. the value " "" a , b "" " is parsed as [ " a , b " ] (instead of [ " a ][ b " ] or [ "" a , b "" ])
- charToEscapeQuoteEscaping (defaults to '\0' - undefined): character used for escaping the escape for the quote character
e.g. if the quoteEscape and charToEscapeQuoteEscaping are set to '\', the value " \\\" a , b \\\" " is parsed as [ \" a , b \" ]
- See Also:
Format
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Character
charToEscapeQuoteEscaping
private java.lang.String
delimiter
private char
quote
private char
quoteEscape
-
Constructor Summary
Constructors Constructor Description CsvFormat()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CsvFormat
clone()
char
getCharToEscapeQuoteEscaping()
Returns the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
.protected java.util.TreeMap<java.lang.String,java.lang.Object>
getConfiguration()
char
getDelimiter()
Returns the field delimiter character.java.lang.String
getDelimiterString()
Returns the field delimiter sequence.char
getQuote()
Returns the character used for escaping values where the field delimiter is part of the value.char
getQuoteEscape()
Returns the character used for escaping quotes inside an already quoted value.boolean
isCharToEscapeQuoteEscaping(char ch)
Identifies whether or not a given character is used to escape the character used for escaping quotes defined bygetQuoteEscape()
.boolean
isDelimiter(char ch)
Identifies whether or not a given character represents a field delimiterboolean
isDelimiter(java.lang.String sequence)
Identifies whether or not a given character represents a field delimiterboolean
isQuote(char ch)
Identifies whether or not a given character is used for escaping values where the field delimiter is part of the valueboolean
isQuoteEscape(char ch)
Identifies whether or not a given character is used for escaping quotes inside an already quoted value.void
setCharToEscapeQuoteEscaping(char charToEscapeQuoteEscaping)
Defines the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
.void
setDelimiter(char delimiter)
Defines the field delimiter character.void
setDelimiter(java.lang.String delimiter)
Defines the field delimiter as a sequence of characters.void
setQuote(char quote)
Defines the character used for escaping values where the field delimiter is part of the value.void
setQuoteEscape(char quoteEscape)
Defines the character used for escaping quotes inside an already quoted value.-
Methods inherited from class com.univocity.parsers.common.Format
getComment, getLineSeparator, getLineSeparatorString, getNormalizedNewline, getSystemLineSeparator, isComment, isNewLine, setComment, setLineSeparator, setLineSeparator, setNormalizedNewline, toString
-
-
-
-
Method Detail
-
getQuote
public char getQuote()
Returns the character used for escaping values where the field delimiter is part of the value. Defaults to '"'- Returns:
- the quote character
-
setQuote
public void setQuote(char quote)
Defines the character used for escaping values where the field delimiter is part of the value. Defaults to '"'- Parameters:
quote
- the quote character
-
isQuote
public boolean isQuote(char ch)
Identifies whether or not a given character is used for escaping values where the field delimiter is part of the value- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the character used for escaping values, false otherwise
-
getQuoteEscape
public char getQuoteEscape()
Returns the character used for escaping quotes inside an already quoted value. Defaults to '"'- Returns:
- the quote escape character
-
setQuoteEscape
public void setQuoteEscape(char quoteEscape)
Defines the character used for escaping quotes inside an already quoted value. Defaults to '"'- Parameters:
quoteEscape
- the quote escape character
-
isQuoteEscape
public boolean isQuoteEscape(char ch)
Identifies whether or not a given character is used for escaping quotes inside an already quoted value.- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the quote escape character, false otherwise
-
getDelimiter
public char getDelimiter()
Returns the field delimiter character. Defaults to ','- Returns:
- the field delimiter character
-
getDelimiterString
public java.lang.String getDelimiterString()
Returns the field delimiter sequence.- Returns:
- the field delimiter as a
String
.
-
setDelimiter
public void setDelimiter(char delimiter)
Defines the field delimiter character. Defaults to ','- Parameters:
delimiter
- the field delimiter character
-
setDelimiter
public void setDelimiter(java.lang.String delimiter)
Defines the field delimiter as a sequence of characters. Defaults to ','- Parameters:
delimiter
- the field delimiter sequence.
-
isDelimiter
public boolean isDelimiter(char ch)
Identifies whether or not a given character represents a field delimiter- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is the field delimiter character, false otherwise
-
isDelimiter
public boolean isDelimiter(java.lang.String sequence)
Identifies whether or not a given character represents a field delimiter- Parameters:
sequence
- the character sequence to be verified- Returns:
- true if the given sequence is the field delimiter character sequence, false otherwise
-
getCharToEscapeQuoteEscaping
public final char getCharToEscapeQuoteEscaping()
Returns the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
. For example, if the quote escape is set to '\', and the quoted value ends with: \", as in the following example:[ " a\\", b ]
Then:- If the character to escape the '\' is undefined, the record won't be parsed. The parser will read characters: [a],[\],["],[,],[ ],[b] and throw an error because it cannot find a closing quote
- If the character to escape the '\' is defined as '\', the record will be read with 2 values: [a\] and [b]
- Returns:
- the character to escape the character used for escaping quotes defined
-
setCharToEscapeQuoteEscaping
public final void setCharToEscapeQuoteEscaping(char charToEscapeQuoteEscaping)
Defines the character used to escape the character used for escaping quotes defined bygetQuoteEscape()
. For example, if the quote escape is set to '\', and the quoted value ends with: \", as in the following example:[ " a\\", b ]
Then:- If the character to escape the '\' is undefined, the record won't be parsed. The parser will read characters: [a],[\],["],[,],[ ],[b] and throw an error because it cannot find a closing quote
- If the character to escape the '\' is defined as '\', the record will be read with 2 values: [a\] and [b]
- Parameters:
charToEscapeQuoteEscaping
- the character to escape the character used for escaping quotes defined
-
isCharToEscapeQuoteEscaping
public final boolean isCharToEscapeQuoteEscaping(char ch)
Identifies whether or not a given character is used to escape the character used for escaping quotes defined bygetQuoteEscape()
.- Parameters:
ch
- the character to be verified- Returns:
- true if the given character is used to escape the quote escape character, false otherwise
-
getConfiguration
protected java.util.TreeMap<java.lang.String,java.lang.Object> getConfiguration()
- Specified by:
getConfiguration
in classFormat
-
-