Package net.sf.anupam.csv
Class CSVParser
java.lang.Object
net.sf.anupam.csv.CSVParser
- All Implemented Interfaces:
AutoCloseable,Iterable<Object>
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCSVParser(CSVBeanMapping rootBeanMapping, net.sf.anupam.csv.CSVReader reader) Constructor for CSVParser. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the parser.protected CSVBeanMappingReturns the root bean mapping.iterator()Returns the iterator for retrieving the parsed POJO beans.toString()Dumps the root bean mapping configuration for this parser.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
LOG
The logger to use.
-
-
Constructor Details
-
CSVParser
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 configurationreader- the CSV Reader object which will actually parse the CSV file
-
-
Method Details
-
toString
Dumps the root bean mapping configuration for this parser. This is meant for debugging only. -
iterator
Returns the iterator for retrieving the parsed POJO beans. -
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:
closein interfaceAutoCloseable
-