Interface CSVParse

All Known Implementing Classes:
CSVParser, ExcelCSVParser, LabeledCSVParser

public interface CSVParse
Read files in comma separated value format. More information about this class is available from ostermiller.org. This interface is designed to be set of general methods that all CSV parsers should implement.
Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeDelimiter(char newDelim)
    Change this parser so that it uses a new delimiter.
    void
    changeQuote(char newQuote)
    Change this parser so that it uses a new character for quoting.
    void
    Close any stream upon which this parser is based.
    String[][]
    Get all the values from the file.
    int
    Get the line number that the last token came from.
    Get all the values from a line.
    int
    Get the line number that the last token came from.
    Read the next value from the file.
  • Method Details

    • nextValue

      String nextValue() throws IOException
      Read the next value from the file. The line number from which this value was taken can be obtained from getLastLineNumber().
      Returns:
      the next value or null if there are no more values.
      Throws:
      IOException - if an error occurs while reading.
      Since:
      ostermillerutils 1.00.00
    • lastLineNumber

      int lastLineNumber()
      Get the line number that the last token came from.
      Returns:
      line number or -1 if no tokens have been returned yet.
      Since:
      ostermillerutils 1.00.00
    • getLine

      String[] getLine() throws IOException
      Get all the values from a line.

      If the line has already been partially read, only the values that have not already been read will be included.

      Returns:
      all the values from the line or null if there are no more values.
      Throws:
      IOException - if an error occurs while reading.
      Since:
      ostermillerutils 1.00.00
    • getLastLineNumber

      int getLastLineNumber()
      Get the line number that the last token came from.

      New line breaks that occur in the middle of a token are not counted in the line number count.

      Returns:
      line number or -1 if no tokens have been returned yet.
      Since:
      ostermillerutils 1.00.00
    • getAllValues

      String[][] getAllValues() throws IOException
      Get all the values from the file.

      If the file has already been partially read, only the values that have not already been read will be included.

      Each line of the file that has at least one value will be represented. Comments and empty lines are ignored.

      The resulting double array may be jagged.

      Returns:
      all the values from the file or null if there are no more values.
      Throws:
      IOException - if an error occurs while reading.
      Since:
      ostermillerutils 1.00.00
    • changeDelimiter

      void changeDelimiter(char newDelim) throws BadDelimiterException
      Change this parser so that it uses a new delimiter.

      The initial character is a comma, the delimiter cannot be changed to a quote or other character that has special meaning in CSV.

      Parameters:
      newDelim - delimiter to which to switch.
      Throws:
      BadDelimiterException - if the character cannot be used as a delimiter.
      Since:
      ostermillerutils 1.02.08
    • changeQuote

      void changeQuote(char newQuote) throws BadQuoteException
      Change this parser so that it uses a new character for quoting.

      The initial character is a double quote ("), the delimiter cannot be changed to a comma or other character that has special meaning in CSV.

      Parameters:
      newQuote - character to use for quoting.
      Throws:
      BadQuoteException - if the character cannot be used as a quote.
      Since:
      ostermillerutils 1.02.16
    • close

      void close() throws IOException
      Close any stream upon which this parser is based.
      Throws:
      IOException - if an error occurs while closing the stream.
      Since:
      ostermillerutils 1.02.26