Class CsvModel

All Implemented Interfaces:
AutoCloseable, IModel

public class CsvModel extends CachedModel<Map<String,Object>>
The Class CsvModel provides The Epsilon Model Connectivity Layer for CSV files (http://tools.ietf.org/html/rfc4180), with the difference that it supports files in which each line has a different number of fields.

Three properties allow configuration of how to read the CSV file:

  • PROPERTY_FIELD_SEPARATOR, by default a comma (','), but you can specify a different separator. In particular, fields are identified using String.split(String), and as such, PROPERTY_FIELD_SEPARATOR is actually treated as regular expression (see <a href="Regex>http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum)
  • PROPERTY_HAS_KNOWN_HEADERS, "There maybe an optional header line appearing as the first line of the file with the same format as normal record lines. This header will contain names corresponding to the fields in the file and should contain the same number of fields as the records in the rest of the file". If this property is set to true, model loading will verify that all lines have the same number of fields as the header. When accessing the model elements (rows) each of the header fields can be used to access information on each record.
  • PROPERTY_HAS_VARARGS_HEADERS, allows the use of varargs headers. This is a special type of header in which the last filed in the header line is used as a base name for all fields after this one. This allows for lines to have a variable number of fields. During model loading it will be verified that each line has at least the same number of fields as header fields minus one. Fields in a record including and following the last header filed will be assigned the header lastHeader0, lastHeader1, lastHeader2,... and so on an so forth.