Package com.opencsv

Class RFC4180Parser

  • All Implemented Interfaces:
    ICSVParser

    public class RFC4180Parser
    extends AbstractCSVParser
    This Parser is meant to parse according to the RFC4180 specification.

    Since it shares the same interface with the CSVParser there are methods here that will do nothing. For example the RFC4180 specification does not have an concept of an escape character so the getEscape method will return char 0. The methods that are not supported are noted in the Javadocs.

    Another departure from the CSVParser is that there is only two constructors and only one is available publicly. The intent is that if you want to create anything other than a default RFC4180Parser you should use the CSVParserBuilder. This way the code will not become cluttered with constructors as the CSVParser did.

    You can view the RFC4180 specification at the Internet Engineering Task Force (IETF) website.

    Examples:

    ICSVParser parser = new RFC4180Parser();

    or

    CSVParserBuilder builder = new CSVParserBuilder() ICSVParser parser = builder.withParserType(ParserType.RFC4180Parser).build()
    Since:
    3.9
    • Constructor Detail

      • RFC4180Parser

        public RFC4180Parser()
        Default constructor for the RFC4180Parser. Uses values from the ICSVParser.
      • RFC4180Parser

        RFC4180Parser​(char quoteChar,
                      char separator,
                      CSVReaderNullFieldIndicator nullFieldIndicator)
        Constructor used by the CSVParserBuilder.
        Parameters:
        separator - The delimiter to use for separating entries
        quoteChar - The character to use for quoted elements
        nullFieldIndicator - Indicate what should be considered null
    • Method Detail

      • convertToCsvValue

        protected java.lang.String convertToCsvValue​(java.lang.String value,
                                                     boolean applyQuotesToAll)
        Description copied from class: AbstractCSVParser
        Used when reverse parsing an array of strings to a single string. Handles the application of quotes around the string and handling any quotes within the string.
        Specified by:
        convertToCsvValue in class AbstractCSVParser
        Parameters:
        value - String to be converted
        applyQuotesToAll - All values should be surrounded with quotes
        Returns:
        String that will go into the CSV string
      • parseLine

        protected java.lang.String[] parseLine​(java.lang.String nextLine,
                                               boolean multi)
        Parses an incoming String and returns an array of elements.
        Specified by:
        parseLine in class AbstractCSVParser
        Parameters:
        nextLine - The string to parse
        multi - Does it take multiple lines to form a single record?
        Returns:
        The list of elements, or null if nextLine is null
      • tokenizeStringIntoArray

        private java.lang.String[] tokenizeStringIntoArray​(java.lang.String nextLine)
      • handleEmptySeparators

        private java.lang.String[] handleEmptySeparators​(java.lang.String[] strings)
      • splitWhileNotInQuotes

        private java.lang.String[] splitWhileNotInQuotes​(java.lang.String nextLine,
                                                         boolean multi)
      • lastElementStartedWithQuoteButDidNotEndInOne

        private boolean lastElementStartedWithQuoteButDidNotEndInOne​(java.util.List<java.lang.String> elements)
      • hasOddQuotes

        private boolean hasOddQuotes​(java.lang.String lastElement)
      • hasOnlyOneQuote

        private boolean hasOnlyOneQuote​(java.lang.String lastElement)
      • startsButDoesNotEndWithQuote

        private boolean startsButDoesNotEndWithQuote​(java.lang.String lastElement)
      • findEndOfFieldFromPosition

        private int findEndOfFieldFromPosition​(java.lang.String nextLine,
                                               int currentPosition)
      • haveNotFoundLastQuote

        private boolean haveNotFoundLastQuote​(java.lang.String nextLine,
                                              int nextQuote)
      • handleQuotes

        private java.lang.String handleQuotes​(java.lang.String element)
      • setErrorLocale

        public void setErrorLocale​(java.util.Locale errorLocale)
        Description copied from interface: ICSVParser
        Sets the locale for all error messages.
        Parameters:
        errorLocale - Locale for error messages. If null, the default locale is used.