Java Reference
In-Depth Information
not found in strict
With Spring Batch's LineMapper interface, a String is provided, representing a single record from a
file. With the raw String from the file, there is a two-step process for getting it to the domain object you
will later work with. These two steps are handled by the LineTokenizer and FieldSetMapper.
A LineTokenizer implementation parses the line into a
org.springframework.batch.item.file.FieldSet . The provided String represents
the entire line from the file. In order to be able to map the individual fields of each
record to your domain object, you need to parse the line into a collection of fields.
The FieldSet in Spring Batch represents that collection of fields for a single row.
The FieldSetMapper implementation maps the FieldSet to a domain object. With
the line divided into individual fields, you can now map each input field to the
field of your domain object just like a RowMapper would map a ResultSet row to
the domain object.
Sounds simple doesn't it? It really is. The intricacies come from how to parse the line and when you
look at objects that are built out of multiple records from your file. Let's take a look at reading files with
fixed-width records first.
Fixed-Width Files
When dealing with legacy mainframe systems, it is common to have to work with fixed-width files due to
the way COBOL and other technologies declare their storage. Because of this, you need to be able to
handle fixed with files as well.
You can use a customer file as your fixed-width file. Consisting of a customer's name and address,
Table 7-2 outlines the format of your customer file.
Table 7-2. Customer File Format
First Name
Your customer's first name.
Middle Initial
The customer's middle initial.
Last Name
The last name of the customer.
Address Number
The street number piece of the customer's address.
The name of the street where the customer lives.
The city the customer is from.
Search WWH ::

Custom Search