简体   繁体   中英

Bindy skipping empty csv files

I built a camel route that unmarshals a csv file using camel bindy and writes the contents to a database. This works perfectly apart from when the file is empty, which by the looks of it will happen a lot. The file does contain csv headers, but no relevant data eg:

CODE;CATEGORY;PRICE;

In this case the following error is thrown:

java.lang.IllegalArgumentException: No records have been defined in the CSV

I tried adding allowEmptyStream = true to the bindy object that I use for unmarshalling. This however does not seem to do much, as the same error appears.

Any ideas on how to skip processing these empty files is very welcome.

In your use case, the option allowEmptyStream must be set to true at Bindy DataFormat level, as next:

BindyCsvDataFormat bindy = new BindyCsvDataFormat(SomeModel.class);
bindy.setAllowEmptyStream(true);

from("file:some/path")
    .unmarshal(bindy)
    // The rest of the route

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM