質問

I have an option to use either bindy or beanIO camel components to parse a csv file. Besides this csv there is dat (txt) file which contains key-value. Is it possible to parse this file to Map using one of mentioned libraries?

役に立ちましたか?

解決

The bindy component can unmarshall a csv file into an Object, not directly in a Map. Here is the response of a related question by Claus Ibsen. It seems that is the same for beanIO.

However you can use the CSV component of Camel which will transform your file into a List<List<String>>.

Here is more info on bindy (documentation on the Camel site).

You have just to declare a DataFormat:

DataFormat bindy = new BindyCsvDataFormat("com.acme.model");

And then use it like this:

from("file://inbox")
  .unmarshal(bindy)
  .to("direct:whatYouWant");

The parameter "com.acme.model" correspond to the package where you define your model. Camel bindy provide a lot of option to configure the binding I encourage you to see the doc for more details, but a basic model will look like this:

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    ...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top