您好,我正在使用骆驼绑定组件处理 CSV 文件,在该文件中,我将数据拆分为 1000 行块,并为每个块生成标题列,我需要它应该只用单个文件生成一次。我的路线:
final DataFormat inputCSV = new BindyCsvDataFormat(InputCSV.class);
final DataFormat outputCSV = new BindyCsvDataFormat(OutputCSV.class);
@Override
public void configure() throws Exception {
from("file:inbox/inputFile?fileName=inputProducts.csv&noop=true")
.split().tokenize("\\n", 1000)
.unmarshal(inputCSV)
.bean(Processor.class, "processCSV")
.marshal(outputCSV)
.to("file:inbox/outputFile?fileExist=append&fileName=outputProduct.csv");
}
还有我的 OutputCSV.java pojo
@CsvRecord(separator = ",",generateHeaderColumns=true)
public class OutputCSV implements Serializable {
private static final long serialVersionUID = 1L;
@DataField(pos = 1, required = true)
private String product_id;
@DataField(pos = 2, required = true)
private String product_name;
//Getter and setter
}
我的问题是如何制作此代码,以便为单个文件生成一次标题?