Package com.opencsv

Class CSVParserBuilder

java.lang.Object
com.opencsv.CSVParserBuilder

public class CSVParserBuilder extends Object
Builder for creating a CSVParser.

Example code for using this class:

final CSVParser parser =
new CSVParserBuilder()
.withSeparator('\t')
.withIgnoreQuotations(true)
.build();

See Also:
  • Field Details

    • separator

      private char separator
    • quoteChar

      private char quoteChar
    • escapeChar

      private char escapeChar
    • strictQuotes

      private boolean strictQuotes
    • ignoreLeadingWhiteSpace

      private boolean ignoreLeadingWhiteSpace
    • ignoreQuotations

      private boolean ignoreQuotations
    • nullFieldIndicator

      private CSVReaderNullFieldIndicator nullFieldIndicator
    • errorLocale

      private Locale errorLocale
  • Constructor Details

    • CSVParserBuilder

      public CSVParserBuilder()
      Default constructor.
  • Method Details

    • withSeparator

      public CSVParserBuilder withSeparator(char separator)
      Sets the delimiter to use for separating entries.
      Parameters:
      separator - The delimiter to use for separating entries
      Returns:
      The CSVParserBuilder
    • withQuoteChar

      public CSVParserBuilder withQuoteChar(char quoteChar)
      Sets the character to use for quoted elements.
      Parameters:
      quoteChar - The character to use for quoted element.
      Returns:
      The CSVParserBuilder
    • withEscapeChar

      public CSVParserBuilder withEscapeChar(char escapeChar)
      Sets the character to use for escaping a separator or quote.
      Parameters:
      escapeChar - The character to use for escaping a separator or quote.
      Returns:
      The CSVParserBuilder
    • withStrictQuotes

      public CSVParserBuilder withStrictQuotes(boolean strictQuotes)
      Sets the strict quotes setting - if true, characters outside the quotes are ignored.
      Parameters:
      strictQuotes - If true, characters outside the quotes are ignored
      Returns:
      The CSVParserBuilder
    • withIgnoreLeadingWhiteSpace

      public CSVParserBuilder withIgnoreLeadingWhiteSpace(boolean ignoreLeadingWhiteSpace)
      Sets the ignore leading whitespace setting - if true, white space in front of a quote in a field is ignored.
      Parameters:
      ignoreLeadingWhiteSpace - If true, white space in front of a quote in a field is ignored
      Returns:
      The CSVParserBuilder
    • withIgnoreQuotations

      public CSVParserBuilder withIgnoreQuotations(boolean ignoreQuotations)
      Sets the ignore quotations mode - if true, quotations are ignored.
      Parameters:
      ignoreQuotations - If true, quotations are ignored
      Returns:
      The CSVParserBuilder
    • build

      public CSVParser build()
      Constructs CSVParser.
      Returns:
      A new CSVParser with defined settings.
    • getSeparator

      public char getSeparator()
      Returns:
      The defined separator.
    • getQuoteChar

      public char getQuoteChar()
      Returns:
      The defined quotation character.
    • getEscapeChar

      public char getEscapeChar()
      Returns:
      The defined escape character.
    • isStrictQuotes

      public boolean isStrictQuotes()
      Returns:
      The defined strict quotation setting.
    • isIgnoreLeadingWhiteSpace

      public boolean isIgnoreLeadingWhiteSpace()
      Returns:
      The defined ignoreLeadingWhiteSpace setting.
    • isIgnoreQuotations

      public boolean isIgnoreQuotations()
      Returns:
      The defined ignoreQuotation setting.
    • withFieldAsNull

      public CSVParserBuilder withFieldAsNull(CSVReaderNullFieldIndicator fieldIndicator)
      Sets the NullFieldIndicator.
      Parameters:
      fieldIndicator - CSVReaderNullFieldIndicator set to what should be considered a null field.
      Returns:
      The CSVParserBuilder
    • withErrorLocale

      public CSVParserBuilder withErrorLocale(Locale errorLocale)
      Sets the locale for all error messages.
      Parameters:
      errorLocale - Locale for error messages
      Returns:
      this
      Since:
      4.0
    • nullFieldIndicator

      public CSVReaderNullFieldIndicator nullFieldIndicator()
      Returns:
      The null field indicator.