package org.simantics.district.imports;
import java.io.IOException;
+import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
}
public static void consumeCSV(Path source, char delim, boolean firstAsHeader, Function<CSVRecord, Boolean> consumer) throws IOException {
- CSVFormat format = CSVFormat.newFormat(delim);
+ consumeCSV(Files.newBufferedReader(source), delim, firstAsHeader, consumer);
+ }
+
+ public static void consumeCSV(Reader reader, char delim, boolean firstAsHeader,
+ Function<CSVRecord, Boolean> consumer) throws IOException {
+ CSVFormat format = CSVFormat.newFormat(delim).withQuote('"');
if (firstAsHeader) {
format = format.withFirstRecordAsHeader();
}
- try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+ try (CSVParser parser = format.parse(reader)) {
Iterator<CSVRecord> records = parser.iterator();
while (records.hasNext()) {
Boolean cont = consumer.apply(records.next());