Search in sources :

Example 1 with CsvParam

use of org.simpleflatmapper.param.CsvParam in project mapping-benchmark by arnaudroger.

the class UnivocityCsvParserBenchmark method main.

public static void main(String[] args) throws IOException {
    CsvParam csvParam = new CsvParam();
    csvParam.setUp();
    CsvParserSettings settings = new CsvParserSettings();
    // turning off features enabled by default
    settings.setIgnoreLeadingWhitespaces(false);
    settings.setIgnoreTrailingWhitespaces(false);
    settings.setSkipEmptyLines(false);
    settings.setColumnReorderingEnabled(false);
    settings.setReadInputOnSeparateThread(false);
    settings.setProcessor(new BeanProcessor<City>(City.class) {

        @Override
        public void beanProcessed(City bean, ParsingContext context) {
            System.out.println(bean);
        }
    });
    com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
    try (Reader reader = csvParam.getReader()) {
        parser.parse(reader);
    }
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) Reader(java.io.Reader) CsvParam(org.simpleflatmapper.param.CsvParam) CsvParserSettings(com.univocity.parsers.csv.CsvParserSettings)

Example 2 with CsvParam

use of org.simpleflatmapper.param.CsvParam in project mapping-benchmark by arnaudroger.

the class JacksonCsvParserBenchmark method main.

public static void main(String[] args) throws IOException {
    CsvParam csvParam = new CsvParam();
    csvParam.setUp();
    CsvMapper csvMapper = new CsvMapper();
    csvMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
    try (Reader reader = csvParam.getReader()) {
        MappingIterator<City> iterator = csvMapper.readerFor(City.class).with(bootstrapSchema).readValues(reader);
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) Reader(java.io.Reader) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CsvParam(org.simpleflatmapper.param.CsvParam)

Aggregations

Reader (java.io.Reader)2 CsvParam (org.simpleflatmapper.param.CsvParam)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 ParsingContext (com.univocity.parsers.common.ParsingContext)1 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)1