Package cdc.util.csv

Class CsvParser


  • public class CsvParser
    extends Object
    Parsing of csv files. Special handling of text is done. However, one must not use '"' as a field separator. One must indicate whether the file has a header or not (this information is not automatically elaborated).
    Author:
    Damien Carbonne
    • Field Detail

      • separator

        char separator
    • Constructor Detail

      • CsvParser

        public CsvParser()
        Creates a parser with ';' separator.
      • CsvParser

        public CsvParser​(char separator)
        Creates a parser with a specified separator.
        Parameters:
        separator - the separator to use.
    • Method Detail

      • setSeparator

        public void setSeparator​(char separator)
        Sets the used separator.
        Parameters:
        separator - the separator to use.
      • setVerbose

        public void setVerbose​(boolean verbose)
        Sets the verbosity level of the parser.
        Parameters:
        verbose - indicates whether the parsing must be verbose or not.
      • parse

        public void parse​(Reader reader,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses a Reader.
        Parameters:
        reader - The reader to parse.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(Reader reader,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses a Reader.
        Parameters:
        reader - The reader to parse.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(InputStream in,
                          String charset,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses an InputStream.
        Parameters:
        in - The input stream.
        charset - The charset to use.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(InputStream in,
                          String charset,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses an InputStream.
        Parameters:
        in - The input stream.
        charset - The charset to use.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(InputStream in,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses an InputStream using default charset.
        Parameters:
        in - The input stream.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(InputStream in,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses an InputStream using default charset.
        Parameters:
        in - The input stream.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(File file,
                          String charset,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses a file.
        Parameters:
        file - The input file.
        charset - The charset to use.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(File file,
                          String charset,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses a file.
        Parameters:
        file - The input file.
        charset - The charset to use.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(File file,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses a file using default charset.
        Parameters:
        file - The input file.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(File file,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses a file using default charset.
        Parameters:
        file - The input file.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(String filename,
                          String charset,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses a file.
        Parameters:
        filename - The input file name.
        charset - The charset to use.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(String filename,
                          String charset,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses a file.
        Parameters:
        filename - The input file name.
        charset - The charset to use.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(String filename,
                          TableHandler handler,
                          int headers)
                   throws IOException
        Parses a file using default charset.
        Parameters:
        filename - The input file name.
        handler - The table handler to use.
        headers - The number of header lines.
        Throws:
        IOException - When an IO exception occurs.
      • parse

        public void parse​(String filename,
                          TableHandler handler,
                          boolean hasHeader)
                   throws IOException
        Parses a file using default charset.
        Parameters:
        filename - The input file name.
        handler - The table handler to use.
        hasHeader - If true, the input has 1 header line.
        Throws:
        IOException - When an IO exception occurs.