public void handleLine(String line) {
headers.add(line);
}
});
reader.setLineMapper(lineMapper);
reader.open(new ExecutionContext());
List<FieldSet> list = new ArrayList<FieldSet>();
FieldSet item = reader.read();
while (item!=null) {
list.add(item);
item = reader.read();
}
assertEquals(7, list.size());
FlatFileItemWriter<FieldSet> writer = new FlatFileItemWriter<FieldSet>();
FileSystemResource resource = new FileSystemResource("target/output/output.txt");
FileUtils.deleteQuietly(resource.getFile());
writer.setResource(resource);
writer.setHeaderCallback(new FlatFileHeaderCallback() {
public void writeHeader(Writer writer) throws IOException {
for (String header : headers) {
writer.write(header);
}
}
});
writer.setLineAggregator(new DelimitedLineAggregator<FieldSet>());
writer.open(new ExecutionContext());
String[] names = getFields(list, 1);
String[] country = getFields(list, 2);
String[] products = getFields(list, 3);
double[] amounts = getMinMax(list, 4);