Class AbstractCharInputReader

    • Field Summary

      Fields 
      Modifier and Type Field Description
      char[] buffer
      The buffer itself
      int i
      Current position in the buffer
      int length
      Number of characters available in the buffer.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractCharInputReader​(char[] lineSeparator, char normalizedLineSeparator, int whitespaceRangeStart)
      Creates a new instance with the mandatory characters for handling newlines transparently.
      AbstractCharInputReader​(char normalizedLineSeparator, int whitespaceRangeStart)
      Creates a new instance that attempts to detect the newlines used in the input automatically.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addInputAnalysisProcess​(InputAnalysisProcess inputAnalysisProcess)
      Submits a custom InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as column separators is CSV, data formats, etc.
      long charCount()
      Returns the number of characters returned by CharInputReader.nextChar() at any given time.
      java.lang.String currentParsedContent()
      Returns a String with the input character sequence parsed to produce the current record.
      void enableNormalizeLineEndings​(boolean normalizeLineEndings)
      Indicates to the input reader that the parser is running in "escape" mode and new lines should be returned as-is to prevent modifying the content of the parsed value.
      char getChar()
      Returns the last character returned by the CharInputReader.nextChar() method.
      char[] getLineSeparator()
      Returns the line separator by this character input reader.
      java.lang.String getString​(char ch, char stop, boolean trim, java.lang.String nullValue, int maxLength)
      Attempts to collect a String from the current position until a stop character is found on the input, or a line ending is reached.
      long lineCount()
      Returns the number of newlines read so far.
      void markRecordStart()
      Marks the start of a new record in the input, used internally to calculate the result of CharInputReader.currentParsedContent()
      char nextChar()
      Returns the next character in the input provided by the active Reader.
      java.lang.String readComment()
      Collects the comment line found on the input.
      protected abstract void reloadBuffer()
      Informs the extending class that the buffer has been read entirely and requests for another batch of characters.
      protected abstract void setReader​(java.io.Reader reader)
      Passes the Reader provided in the start(Reader) method to the extending class so it can begin loading characters from it.
      void skipLines​(long lines)
      Skips characters in the input until the given number of lines is discarded.
      char skipWhitespace​(char ch, char stopChar1, char stopChar2)
      Skips characters from the current input position, until a non-whitespace character, or a stop character is found
      void start​(java.io.Reader reader)
      Initializes the CharInputReader implementation with a Reader which provides access to the input.
      protected void unwrapInputStream​(BomInput.BytesProcessedNotification notification)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • i

        public int i
        Current position in the buffer
      • buffer

        public char[] buffer
        The buffer itself
      • length

        public int length
        Number of characters available in the buffer.
    • Constructor Detail

      • AbstractCharInputReader

        public AbstractCharInputReader​(char normalizedLineSeparator,
                                       int whitespaceRangeStart)
        Creates a new instance that attempts to detect the newlines used in the input automatically.
        Parameters:
        normalizedLineSeparator - the normalized newline character (as defined in Format.getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
        whitespaceRangeStart - starting range of characters considered to be whitespace.
      • AbstractCharInputReader

        public AbstractCharInputReader​(char[] lineSeparator,
                                       char normalizedLineSeparator,
                                       int whitespaceRangeStart)
        Creates a new instance with the mandatory characters for handling newlines transparently.
        Parameters:
        lineSeparator - the sequence of characters that represent a newline, as defined in Format.getLineSeparator()
        normalizedLineSeparator - the normalized newline character (as defined in Format.getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
        whitespaceRangeStart - starting range of characters considered to be whitespace.
    • Method Detail

      • setReader

        protected abstract void setReader​(java.io.Reader reader)
        Passes the Reader provided in the start(Reader) method to the extending class so it can begin loading characters from it.
        Parameters:
        reader - the Reader provided in start(Reader)
      • reloadBuffer

        protected abstract void reloadBuffer()
        Informs the extending class that the buffer has been read entirely and requests for another batch of characters. Implementors must assign the new character buffer to the public buffer attribute, as well as the number of characters available to the public length attribute. To notify the input does not have any more characters, length must receive the -1 value
      • start

        public final void start​(java.io.Reader reader)
        Description copied from interface: CharInputReader
        Initializes the CharInputReader implementation with a Reader which provides access to the input.
        Specified by:
        start in interface CharInputReader
        Parameters:
        reader - A Reader that provides access to the input.
      • addInputAnalysisProcess

        public final void addInputAnalysisProcess​(InputAnalysisProcess inputAnalysisProcess)
        Submits a custom InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as column separators is CSV, data formats, etc. The process will be execute only once.
        Parameters:
        inputAnalysisProcess - a custom process to analyze the contents of the input buffer.
      • nextChar

        public final char nextChar()
        Description copied from interface: CharInputReader
        Returns the next character in the input provided by the active Reader.

        If the input contains a sequence of newline characters (defined by Format.getLineSeparator()), this method will automatically converted them to the newline character specified in Format.getNormalizedNewline().

        A subsequent call to this method will return the character after the newline sequence.

        Specified by:
        nextChar in interface CharInput
        Specified by:
        nextChar in interface CharInputReader
        Returns:
        the next character in the input. '\0' if there are no more characters in the input or if the CharInputReader was stopped.
      • lineCount

        public final long lineCount()
        Description copied from interface: CharInputReader
        Returns the number of newlines read so far.
        Specified by:
        lineCount in interface CharInputReader
        Returns:
        the number of newlines read so far.
      • skipLines

        public final void skipLines​(long lines)
        Description copied from interface: CharInputReader
        Skips characters in the input until the given number of lines is discarded.
        Specified by:
        skipLines in interface CharInputReader
        Parameters:
        lines - the number of lines to skip from the current location in the input
      • readComment

        public java.lang.String readComment()
        Description copied from interface: CharInputReader
        Collects the comment line found on the input.
        Specified by:
        readComment in interface CharInputReader
        Returns:
        the text found in the comment from the current position.
      • enableNormalizeLineEndings

        public final void enableNormalizeLineEndings​(boolean normalizeLineEndings)
        Description copied from interface: CharInputReader
        Indicates to the input reader that the parser is running in "escape" mode and new lines should be returned as-is to prevent modifying the content of the parsed value.
        Specified by:
        enableNormalizeLineEndings in interface CharInputReader
        Parameters:
        normalizeLineEndings - flag indicating that the parser is escaping values and line separators are to be returned as-is.
      • skipWhitespace

        public final char skipWhitespace​(char ch,
                                         char stopChar1,
                                         char stopChar2)
        Description copied from interface: CharInputReader
        Skips characters from the current input position, until a non-whitespace character, or a stop character is found
        Specified by:
        skipWhitespace in interface CharInputReader
        Parameters:
        ch - the current character of the input
        stopChar1 - the first stop character (which can be a whitespace)
        stopChar2 - the second character (which can be a whitespace)
        Returns:
        the first non-whitespace character (or delimiter) found in the input.
      • currentParsedContent

        public final java.lang.String currentParsedContent()
        Description copied from interface: CharInputReader
        Returns a String with the input character sequence parsed to produce the current record.
        Specified by:
        currentParsedContent in interface CharInputReader
        Returns:
        the text content parsed for the current input record.
      • getString

        public java.lang.String getString​(char ch,
                                          char stop,
                                          boolean trim,
                                          java.lang.String nullValue,
                                          int maxLength)
        Description copied from interface: CharInputReader
        Attempts to collect a String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be obtained, the current position of the parser will be updated to the last consumed character. If the internal buffer needs to be reloaded, this method will return null and the current position of the buffer will remain unchanged.
        Specified by:
        getString in interface CharInputReader
        Parameters:
        ch - the current character to be considered. If equal to the stop character the nullValue will be returned
        stop - the stop character that identifies the end of the content to be collected
        trim - flag indicating whether or not trailing whitespaces should be discarded
        nullValue - value to return when the length of the content to be returned is 0.
        maxLength - the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
        Returns:
        the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.