Large amounts of data are moved via files in enterprise batch processing. There is a reason for this: files
are simple and reliable. Backups are easy. So is recovery if you need to start over. This section looks at
how to generate flat files in a variety of formats including formatted records (fixed width or other) and
delimited files as well as how Spring Batch handles the issue of file creation.
org.springframework.batch.item.file.FlatFileItemWriter is the ItemWriter implementation provided
to generate text file output. Similar to FlatFileItemReader in many respects, this class addresses the
issues with file-based output in Java with a clean, consistent interface for you to use. Figure 9-2 shows
how the FlatFileItemWriter is constructed.
Figure 9-2. FlatFileItemWriter pieces
FlatFileItemWriter , as shown in Figure 9-2 consists of a resource to write to and a LineAggregator
implementation. The org.springframework.batch.item.file.transform.LineAggregator interface
replaces the LineMapper of the FlatFileItemReader discussed in Chapter 7. Here, instead of parsing a
String into an object as the LineMapper is responsible for doing, the LineAggregator is responsible for the
generating of an output String based on an object.
In many of the previous examples, you used PassThroughLineAggregator to generate the output files.
This particular implementation of the LineAggregator interface just calls the item's toString() method
to generate the output. But there are other implementations that you look at in the coming sections.
FlatFileItemWriter has a number of interesting configuration options, which are reviewed in Table