Class CsvParserConfiguration

  • Direct Known Subclasses:
    CsvRecordParserFactory

    public class CsvParserConfiguration
    extends java.lang.Object
    Stores configuration settings for parsing CSV formatted streams.
    Since:
    2.0
    • 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.
      char getDelimiter()
      Returns the field delimiter.
      java.lang.Character getEscape()
      Returns the escape character.
      java.lang.String getLineSeparator()
      Deprecated. 
      char getQuote()
      Returns the character to use for a quotation mark.
      java.lang.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​(java.lang.String[] comments)
      Sets the array of comment prefixes.
      void setDelimiter​(char c)
      Sets the field delimiter.
      void setEscape​(java.lang.Character c)
      Sets the escape character.
      void setLineSeparator​(java.lang.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​(java.lang.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()
    • 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 to null to 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 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 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:
        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 java.lang.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​(java.lang.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

        @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 to null, the default line separator is used based on the 'line.separator' system property.
        Parameters:
        lineSeparator - the line separation text