BeanIO 2.0.4

org.beanio.stream.csv
Class CsvParserConfiguration

java.lang.Object
  extended by org.beanio.stream.csv.CsvParserConfiguration
Direct Known Subclasses:
CsvRecordParserFactory

public class CsvParserConfiguration
extends Object

Stores configuration settings for parsing CSV formatted streams.

Since:
2.0
Author:
Kevin Seim

Constructor Summary
CsvParserConfiguration()
          Constructs a new CsvParserConfiguration.
 
Method Summary
 String[] getComments()
          Returns the array of comment prefixes.
 char getDelimiter()
          Returns the field delimiter.
 Character getEscape()
          Returns the escape character.
 String getLineSeparator()
          Deprecated.  
 char getQuote()
          Returns the character to use for a quotation mark.
 String getRecordTerminator()
          Returns the text used to terminate a record.
 boolean isAlwaysQuote()
          Returns true if fields should always be quoted when marshalled.
 boolean isCommentEnabled()
          Returns whether one or more comment prefixes have been configured.
 boolean isEscapeEnabled()
          Returns whether escaping is enabled.
 boolean isMultilineEnabled()
          Returns whether a record may span multiple lines (when quoted).
 boolean isUnquotedQuotesAllowed()
          Returns whether quotes are allowed to appear in an unquoted field.
 boolean isWhitespaceAllowed()
          Returns whether to ignore unquoted whitespace.
 void setAlwaysQuote(boolean alwaysQuote)
          Set to true to quote every field when marshalled.
 void setComments(String[] comments)
          Sets the array of comment prefixes.
 void setDelimiter(char c)
          Sets the field delimiter.
 void setEscape(Character c)
          Sets the escape character.
 void setLineSeparator(String lineSeparator)
          Deprecated.  
 void setMultilineEnabled(boolean multilineEnabled)
          Sets whether a record may span multiple lines (when quoted).
 void setQuote(char quote)
          Sets the character to use for a quotation mark.
 void setRecordTerminator(String recordTerminator)
          Sets the text used to terminate a record.
 void setUnquotedQuotesAllowed(boolean unquotedQuotesAllowed)
          Sets whether quotes are allowed to appear in an unquoted field.
 void setWhitespaceAllowed(boolean whitespaceAllowed)
          Sets whether unquoted whitespace is ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvParserConfiguration

public CsvParserConfiguration()
Constructs a new CsvParserConfiguration.

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(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 to null to disable escaping.

Parameters:
c - new escape character

getEscape

public 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 null if escaping is disabled

isEscapeEnabled

public boolean isEscapeEnabled()
Returns whether escaping is enabled. By default, escaping is enabled.

Returns:
true if an escape character is enabled
See Also:
getEscape()

isMultilineEnabled

public boolean isMultilineEnabled()
Returns whether a record may span multiple lines (when quoted). Defaults to false.

Returns:
true if 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 true true to allow records to span multiple lines

isWhitespaceAllowed

public boolean isWhitespaceAllowed()
Returns whether to ignore unquoted whitespace. Returns false by default which causes the following record to raise an exception:
 "Field1", "Field2"
          ^
        Unquoted whitespace here
 

Returns:
true if unquoted whitespace is allowed

setWhitespaceAllowed

public void setWhitespaceAllowed(boolean whitespaceAllowed)
Sets whether unquoted whitespace is ignored.

Parameters:
whitespaceAllowed - set to true to ignore unquoted whitespace

isUnquotedQuotesAllowed

public boolean isUnquotedQuotesAllowed()
Returns whether quotes are allowed to appear in an unquoted field. Set to false by default which will cause the following record to throw an exception:
 Field1,Field"2,Field3
 

Returns:
true if 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 to true if quotes may appear in an unquoted field

getComments

public 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(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:
true if one or more comment prefixes have been configured

isAlwaysQuote

public boolean isAlwaysQuote()
Returns true if fields should always be quoted when marshalled. Defaults to false which will only quote fields containing a quotation mark, delimiter, line feeds or carriage return.

Returns:
true if all fields will be quoted

setAlwaysQuote

public void setAlwaysQuote(boolean alwaysQuote)
Set to true to quote every field when marshalled. If false, a field will only be quoted if it contains a quotation mark, delimiter, line feed or carriage return.

Parameters:
alwaysQuote - set to true to quote every field regardless of content

getRecordTerminator

public String getRecordTerminator()
Returns the text used to terminate a record. By default, the record terminator is set to the value of the line.separator system property.

Returns:
the record termination text

setRecordTerminator

public void setRecordTerminator(String recordTerminator)
Sets the text used to terminate a record. If set to null, the the value of the line.separator system property is used to terminate records.

Parameters:
recordTerminator - the record termination text

getLineSeparator

public 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

public void setLineSeparator(String lineSeparator)
Deprecated. 

Sets the text used to terminate a record. If set to null, the default line separator is used based on the 'line.separator' system property.

Parameters:
lineSeparator - the line separation text

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim