Class CSVParser

java.lang.Object
net.sf.anupam.csv.CSVParser
All Implemented Interfaces:
AutoCloseable, Iterable<Object>

public class CSVParser extends Object implements Iterable<Object>, AutoCloseable
Parses CSV files and creates the mapped POJO objects. This is the primary interface into the CSV parsing framework.

The class implements Iterable interface and can be used in the new Tiger for loops to iterate over all the CSV records in the file.

Configuration of the parser is performed via the csv-mapping.xml file. See the package description for more details.

Note that the class is not meant to be instantiated directly. Instead, the CSVParserFactory factory should be used for creation of instances.

Since:
1.8
Version:
$Revision$
Author:
Anupam Sengupta
See Also:
  • Field Details

    • LOG

      protected static final Logger LOG
      The logger to use.
  • Constructor Details

    • CSVParser

      public CSVParser(CSVBeanMapping rootBeanMapping, net.sf.anupam.csv.CSVReader reader)
      Constructor for CSVParser. The constructor accepts the bean mapping to use as the starting CSV mapping configuration (a.k.a the root bean mapping) and the CSV reader/parser engine to use for actual parsing.
      Parameters:
      rootBeanMapping - the bean mapping to use as the starting configuration
      reader - the CSV Reader object which will actually parse the CSV file
  • Method Details

    • toString

      public String toString()
      Dumps the root bean mapping configuration for this parser. This is meant for debugging only.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this parser
      See Also:
    • iterator

      public Iterator<Object> iterator()
      Returns the iterator for retrieving the parsed POJO beans.
      Specified by:
      iterator in interface Iterable<Object>
      Returns:
      the iterator over the parsed beans
      See Also:
    • getRootBeanMapping

      protected CSVBeanMapping getRootBeanMapping()
      Returns the root bean mapping. The root bean mapping is the bean mapping with which the Parser is configured. "Child" bean mappings (which are not directly accessible) are the bean mapping configurations which may be present as references from the root mapping.
      Returns:
      Returns the root bean mapping.
    • close

      public void close()
      Closes the parser.
      Specified by:
      close in interface AutoCloseable