I want to download and parse a large CSV using camel-csv
and I can't figure out a solution that I'm satisfied with. camel-csv
seems to be designed to read and process files placed on disk.
I want to download a list of URL's via HTTP and parse the stream as it is downloaded. I can do it by bypassing camel-csv
like so:
from("mock:in").process(new TaxiDataProcessor(new DataCSVParserFactory())).to("mock:out");
public class DataProcessor implements Processor {
private final DataCSVParserFactory csvParserFactory;
@Inject
public DataProcessor(DataCSVParserFactory csvParserFactory) {
this.csvParserFactory = csvParserFactory;
}
@Override
public void process(Exchange exchange) throws Exception {
String file = (String) exchange.getIn().getBody();
URL url = new URL(file);
CSVParser parser = csvParserFactory.build(url);
for (CSVRecord csvRecord : parser) {
exchange.getIn().setBody(csvRecord);
}
}
}
But would it be possible to use something like camel-ahc
to download the files and pipe that into the csv unmarshalling? Something like:
from("direct:input").unmarshall().csv().to("direct:out");
template.send("ahc:uri");