40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
import java.io.File;
|
|
import java.io.IOException;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import com.fasterxml.jackson.datatype.joda.JodaModule;
|
|
import com.espertech.esper.client.EPServiceProvider;
|
|
import com.fasterxml.jackson.databind.MappingIterator;
|
|
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
|
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
|
|
|
|
|
public class CSVReader implements TickStreamReader {
|
|
final Logger log = LoggerFactory.getLogger(CSVReader.class);
|
|
File file;
|
|
|
|
|
|
public CSVReader(File file) {
|
|
this.file = file;
|
|
}
|
|
|
|
public void run(TickProcessor processor) {
|
|
CsvMapper mapper = new CsvMapper();
|
|
|
|
// allow deserializing Joda time classes
|
|
mapper.registerModule(new JodaModule());
|
|
|
|
CsvSchema schema = mapper.schemaFor(TrueFXTickEvent.class);
|
|
|
|
try {
|
|
MappingIterator<TrueFXTickEvent> it = mapper.readerFor(TrueFXTickEvent.class).with(schema).readValues(file);
|
|
while (it.hasNextValue()) {
|
|
TrueFXTickEvent value = it.nextValue();
|
|
processor.process(value);
|
|
}
|
|
} catch (IOException e) {
|
|
log.error("Reading CSV", e);
|
|
}
|
|
}
|
|
}
|