forked from uniVocity/csv-parsers-comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JacksonParser.java
47 lines (31 loc) · 1.11 KB
/
JacksonParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.univocity.articles.csvcomparison.parser;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvParser;
import java.io.Reader;
import java.util.*;
public class JacksonParser extends AbstractParser {
protected JacksonParser() {
super("Jackson CSV parser");
}
@Override
public void processRows(final Reader input) throws Exception {
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
MappingIterator<String[]> iterator = csvMapper.readerFor(String[].class).readValues(input);
while (iterator.hasNext()) {
process(iterator.next());
}
}
@Override
public List<String[]> parseRows(final Reader input) throws Exception {
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
MappingIterator<String[]> iterator = csvMapper.reader(String[].class).readValues(input);
List<String[]> values = new ArrayList<String[]>();
while (iterator.hasNext()) {
values.add(iterator.next());
}
return values;
}
}