Class CsvParser

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    final class CsvParser
    extends java.lang.Object
    implements java.io.Closeable
    • Field Detail

      • STATUS_LAST_CHAR_WAS_CR

        private static final int STATUS_LAST_CHAR_WAS_CR
        See Also:
        Constant Field Values
      • STATUS_COMMENTED_RECORD

        private static final int STATUS_COMMENTED_RECORD
        See Also:
        Constant Field Values
      • fsep

        private final char fsep
      • qChar

        private final char qChar
      • cChar

        private final char cChar
      • acceptCharsAfterQuotes

        private final boolean acceptCharsAfterQuotes
      • startingLineNumber

        private long startingLineNumber
      • lines

        private int lines
      • status

        private int status
      • finished

        private boolean finished
    • Constructor Detail

      • CsvParser

        CsvParser​(char fieldSeparator,
                  char quoteCharacter,
                  CommentStrategy commentStrategy,
                  char commentCharacter,
                  boolean acceptCharsAfterQuotes,
                  CsvCallbackHandler<?> callbackHandler,
                  java.io.Reader reader)
      • CsvParser

        CsvParser​(char fieldSeparator,
                  char quoteCharacter,
                  CommentStrategy commentStrategy,
                  char commentCharacter,
                  boolean acceptCharsAfterQuotes,
                  CsvCallbackHandler<?> callbackHandler,
                  java.lang.String data)
    • Method Detail

      • assertFields

        private void assertFields​(char fieldSeparator,
                                  char quoteCharacter,
                                  char commentCharacter)
      • parse

        boolean parse()
               throws java.io.IOException
        Throws:
        java.io.IOException
      • processBufferTail

        private boolean processBufferTail()
      • consume

        boolean consume​(char[] lBuf,
                        int lLen)
      • materialize

        private void materialize​(char[] lBuf,
                                 int lBegin,
                                 int lPos,
                                 int lStatus,
                                 char quoteCharacter)
      • cleanDelimiters

        private static int cleanDelimiters​(char[] buf,
                                           int begin,
                                           int end,
                                           char quoteCharacter)
        Remove escapes from the field data.

        The input buffer could look like this: foo ""is"" bar

        Parameters:
        buf - the buffer containing the field data
        begin - the start position of the field data (after the opening quote)
        end - the end position of the field data (on the closing quote / end of buffer)
        quoteCharacter - the quote character
        Returns:
        the length of the field data after removing escapes
      • getStartingLineNumber

        public long getStartingLineNumber()
      • reset

        void reset​(long startingLineNumber)
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • peekLine

        java.lang.String peekLine()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • skipLine

        boolean skipLine​(int numCharsToSkip)
                  throws java.io.IOException
        Throws:
        java.io.IOException