chunk has been processed. The item will be passed to any configured ItemProcessor before being sent
as part of a chunk to the ItemWriter.
The best way to understand how to use the ItemReader interface is to put it to use. In the next
section you will begin to look at the many ItemReader implementations provided by Spring Batch by
working with the FlatFileItemReader.
When I think of file IO in Java, I can't help but cringe. The API for IO is marginally better than the API for
handling dates in this language, and you all know how good that is. Luckily, the guys at Spring Batch
have addressed most of this by providing a number of declarative readers that allow you to declare the
format of what you're going to read and they handle the rest. In this section, you'll be looking at the
declarative readers that Spring Batch provides and how to configure them for file-based IO.
When I talk about flat files in the case of batch processes, I'm talking about any file that has one or more
records. Each record can take up one or more lines. The difference between a flat file and an XML file is
that the data within the file is non-descriptive. In other words, there is no meta information within the
file itself to define the format or meaning of the data. In contrast, in XML, you use tags to give the data
Before you get into actually configuring an ItemReader for a flat file, let's take a look at the pieces of
reading a file in Spring Batch. The authors of the framework did a good job in creating an API that makes
sense and can be easily related to concepts that most of us already know.
Figure 7-2 shows the components of the FlatFileItemReader. The
org.springframework.batch.item.file.FlatFileItemReader consists of two main components: a Spring
Resource that represents the file to be read and an implementation of the
org.springfamework.batch.item.file.LineMapper interface. The LineMapper serves a similar function as
the RowMapper does in Spring JDBC. When using a RowMapper in Spring JDBC, a ResultSet
representing a collection of fields is provided for you map to objects.
Figure 7-2. FlatFileItemReader pieces
The FlatFileItemReader allows you to configure a number of attributes about the file you're reading.
Table 7-1 shows the options that you are likely to use and explains their meanings.