76.3. 将 CSV 消息解压缩到一个 Java 列表中

取消汇总会将 CSV 机码转换为带有 CSV 文件行的 Java 列表(包含所有字段值包含另一个列表)。

示例:我们有一个 CSV 文件,其名称为用户角色、IQ 及其当前活动。

Jack Dalton, 115, mad at Averell
Joe Dalton, 105, calming Joe
William Dalton, 105, keeping Joe from killing Averell
Averell Dalton, 80, playing with Rantanplan
Lucky Luke, 120, capturing the Daltons

现在,我们可以使用 CSV 组件来总结此文件:

from("file:src/test/resources/?fileName=daltons.csv&noop=true")
    .unmarshal().csv()
    .to("mock:daltons");

生成的消息将包含 List< List<String>>,如…​

List<List<String>> data = (List<List<String>>) exchange.getIn().getBody();
for (List<String> line : data) {
    LOG.debug(String.format("%s has an IQ of %s and is currently %s", line.get(0), line.get(1), line.get(2)));
}