Class CsvParser

java.lang.Object
org.simpleflatmapper.csv.CsvParser

public final class CsvParser extends Object
CsvParser provides an fluent DSL to parse or map csv content.

It is possible to customize the quote char, the separator, skip lines,and specified the size of the buffer

CsvParser
    .quote('\'')
    .separator(';')
    .skip(2)
    .bufferSize(256)
    .stream(new StringReader("1;1\n2;2\n3;3\n4;4\n5;5"))
    .map(Arrays::toString)
    .forEach(System.out::println);
    // output
    // [3, 3]
    // [4, 4]
    // [5, 5]


the limit settings does not affect streams or iterator, only parse on DSL and forEach on the mapTo/mapWith DSL.

The DSL provides way to mapTo an object

CsvParser.mapTo(MyClass.class).stream(reader).forEach(System.out::println);

using static mapping when no headers

CsvParser.mapTo(MyClass.class).addHeaders("id", "field").stream(reader).forEach(System.out::println);
// using the addMapping
CsvParser.mapTo(MyClass.class).addMapping("id").addMapping("field").stream(reader).forEach(System.out::println);

using static mapping and ignoring source header

CsvParser.mapTo(MyClass.class).overrideHeaders("id", "field").stream(reader).forEach(System.out::println);
// using the addMapping
CsvParser.skip(1).mapTo(MyClass.class).addMapping("id").addMapping("field").stream(reader).forEach(System.out::println);

or mapping with a predefined jdbcMapper.

CsvMapper<MyClass> jdbcMapper = CsvMapperFactory.newInstance().newMapper(MyClass.class);
CsvParser.mapWith(jdbcMapper).stream(reader).forEach(System.out::println);

Each call to the DSL return an immutable representation of the current setup. So that it is possible to cache step of the DSL without side effect.

CsvParser.DSL semiColumnParser = CsvParser.separator(';');

try (Reader r = new FileReader(file)) {
    // the limit does not modify to the semiColumnParser object
    semiColumnParser.limit(3).stream(r);
}