Package org.beanio.stream.csv
Class CsvParserConfiguration
- java.lang.Object
-
- org.beanio.stream.csv.CsvParserConfiguration
-
- Direct Known Subclasses:
CsvRecordParserFactory
public class CsvParserConfiguration extends java.lang.ObjectStores configuration settings for parsing CSV formatted streams.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description CsvParserConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.String[]getComments()Returns the array of comment prefixes.chargetDelimiter()Returns the field delimiter.java.lang.CharactergetEscape()Returns the escape character.java.lang.StringgetLineSeparator()Deprecated.chargetQuote()Returns the character to use for a quotation mark.java.lang.StringgetRecordTerminator()Returns the text used to terminate a record.booleanisAlwaysQuote()Returnstrueif fields should always be quoted when marshalled.booleanisCommentEnabled()Returns whether one or more comment prefixes have been configured.booleanisEscapeEnabled()Returns whether escaping is enabled.booleanisMultilineEnabled()Returns whether a record may span multiple lines (when quoted).booleanisUnquotedQuotesAllowed()Returns whether quotes are allowed to appear in an unquoted field.booleanisWhitespaceAllowed()Returns whether to ignore unquoted whitespace.voidsetAlwaysQuote(boolean alwaysQuote)Set totrueto quote every field when marshalled.voidsetComments(java.lang.String[] comments)Sets the array of comment prefixes.voidsetDelimiter(char c)Sets the field delimiter.voidsetEscape(java.lang.Character c)Sets the escape character.voidsetLineSeparator(java.lang.String lineSeparator)Deprecated.voidsetMultilineEnabled(boolean multilineEnabled)Sets whether a record may span multiple lines (when quoted).voidsetQuote(char quote)Sets the character to use for a quotation mark.voidsetRecordTerminator(java.lang.String recordTerminator)Sets the text used to terminate a record.voidsetUnquotedQuotesAllowed(boolean unquotedQuotesAllowed)Sets whether quotes are allowed to appear in an unquoted field.voidsetWhitespaceAllowed(boolean whitespaceAllowed)Sets whether unquoted whitespace is ignored.
-
-
-
Method Detail
-
setDelimiter
public void setDelimiter(char c)
Sets the field delimiter. By default, the delimiter is a comma.- Parameters:
c- the character used to delimit fields
-
getDelimiter
public char getDelimiter()
Returns the field delimiter. By default, the delimiter is a comma.- Returns:
- the character used to delimit fields
-
getQuote
public char getQuote()
Returns the character to use for a quotation mark. Defaults to '"'.- Returns:
- the quotation mark character
-
setQuote
public void setQuote(char quote)
Sets the character to use for a quotation mark.- Parameters:
quote- the new quotation mark character
-
setEscape
public void setEscape(java.lang.Character c)
Sets the escape character. Quotation marks can be escaped within quoted values using the escape character. For example, using the default escape character, '"Hello ""friend"""' is parsed into 'Hello "friend"'. Set tonullto disable escaping.- Parameters:
c- new escape character
-
getEscape
public java.lang.Character getEscape()
Returns the escape character. Quotation marks can be escaped within quoted values using the escape character. For example, using the default escape character, '"Hello ""friend"""' is parsed into 'Hello "friend"'. Defaults to the quotation mark,".- Returns:
- the escape character or
nullif escaping is disabled
-
isEscapeEnabled
public boolean isEscapeEnabled()
Returns whether escaping is enabled. By default, escaping is enabled.- Returns:
trueif an escape character is enabled- See Also:
getEscape()
-
isMultilineEnabled
public boolean isMultilineEnabled()
Returns whether a record may span multiple lines (when quoted). Defaults tofalse.- Returns:
trueif a record may span multiple lines
-
setMultilineEnabled
public void setMultilineEnabled(boolean multilineEnabled)
Sets whether a record may span multiple lines (when quoted).- Parameters:
multilineEnabled- set to truetrueto allow records to span multiple lines
-
isWhitespaceAllowed
public boolean isWhitespaceAllowed()
Returns whether to ignore unquoted whitespace. Returnsfalseby default which causes the following record to raise an exception:"Field1", "Field2" ^ Unquoted whitespace here- Returns:
trueif unquoted whitespace is allowed
-
setWhitespaceAllowed
public void setWhitespaceAllowed(boolean whitespaceAllowed)
Sets whether unquoted whitespace is ignored.- Parameters:
whitespaceAllowed- set totrueto ignore unquoted whitespace
-
isUnquotedQuotesAllowed
public boolean isUnquotedQuotesAllowed()
Returns whether quotes are allowed to appear in an unquoted field. Set tofalseby default which will cause the following record to throw an exception:Field1,Field"2,Field3
- Returns:
trueif quotes may appear in an unquoted field
-
setUnquotedQuotesAllowed
public void setUnquotedQuotesAllowed(boolean unquotedQuotesAllowed)
Sets whether quotes are allowed to appear in an unquoted field.- Parameters:
unquotedQuotesAllowed- set totrueif quotes may appear in an unquoted field
-
getComments
public java.lang.String[] getComments()
Returns the array of comment prefixes. If a line read from a stream begins with a configured comment prefix, the line is ignored. By default, no lines are considered commented.- Returns:
- the array of comment prefixes
-
setComments
public void setComments(java.lang.String[] comments)
Sets the array of comment prefixes. If a line read from a stream begins with a configured comment prefix, the line is ignored.- Parameters:
comments- the array of comment prefixes
-
isCommentEnabled
public boolean isCommentEnabled()
Returns whether one or more comment prefixes have been configured.- Returns:
trueif one or more comment prefixes have been configured
-
isAlwaysQuote
public boolean isAlwaysQuote()
Returnstrueif fields should always be quoted when marshalled. Defaults tofalsewhich will only quote fields containing a quotation mark, delimiter, line feeds or carriage return.- Returns:
trueif all fields will be quoted
-
setAlwaysQuote
public void setAlwaysQuote(boolean alwaysQuote)
Set totrueto quote every field when marshalled. Iffalse, a field will only be quoted if it contains a quotation mark, delimiter, line feed or carriage return.- Parameters:
alwaysQuote- set totrueto quote every field regardless of content
-
getRecordTerminator
public java.lang.String getRecordTerminator()
Returns the text used to terminate a record. By default, the record terminator is set to the value of theline.separatorsystem property.- Returns:
- the record termination text
-
setRecordTerminator
public void setRecordTerminator(java.lang.String recordTerminator)
Sets the text used to terminate a record. If set tonull, the the value of theline.separatorsystem property is used to terminate records.- Parameters:
recordTerminator- the record termination text
-
getLineSeparator
@Deprecated public java.lang.String getLineSeparator()
Deprecated.Returns the text used to terminate a record. By default, the line separator is set using the 'line.separator' system property.- Returns:
- the line separation text
-
setLineSeparator
@Deprecated public void setLineSeparator(java.lang.String lineSeparator)
Deprecated.Sets the text used to terminate a record. If set tonull, the default line separator is used based on the 'line.separator' system property.- Parameters:
lineSeparator- the line separation text
-
-