Class AbstractTextDataReader

  • Direct Known Subclasses:
    CsvReader, FixedWidthTextReader

    public abstract class AbstractTextDataReader
    extends Object
    Abstract base class to parse a text based resource.
    Since:
    6.3
    Author:
    Jon van Leuven
    • Field Detail

      • DEFAULT_SKIP_LINES

        public static final int DEFAULT_SKIP_LINES
        The default line to start reading.
        See Also:
        Constant Field Values
    • Method Detail

      • readAll

        public TextDataContent readAll​(boolean hasHeader)
                                throws IOException
        Reads the entire file into a TextDataContent object.
        Parameters:
        hasHeader - Indicator if the first row is treated as header.
        Returns:
        a TextDataContent.
        Throws:
        IOException - if bad things happen during the read
      • readNext

        public String[] readNext()
                          throws IOException
        Reads the next line from the buffer and converts to a string array.
        Returns:
        a string array with each comma-separated element as a separate entry.
        Throws:
        IOException - if bad things happen during the read
      • getNextLine

        protected String getNextLine()
                              throws IOException
        Reads the next line from the file. Empty lines are skipped.
        Returns:
        the next line from the file without trailing newline
        Throws:
        IOException - if bad things happen during the read
      • parseLine

        protected abstract String[] parseLine​(String nextLine)
                                       throws IOException
        Parses an incoming String and returns an array of elements.
        Parameters:
        nextLine - the string to parse
        Returns:
        the comma-tokenized list of elements, or null if nextLine is null
        Throws:
        IOException - if bad things happen during the read
      • close

        public void close()
                   throws IOException
        Closes the underlying reader.
        Throws:
        IOException - if the close fails