Java Reference
In-Depth Information
columns. Let's start by looking at an updated customerFile that is delimited instead of fixed-width.
Listing 7-8 shows your new input file.
Listing 7-8. A Delimited customerFile
Michael,T,Minella,123,4th Street,Chicago,IL,60606
Warren,Q,Gates,11,Wall Street,New York,NY,10005
Ann,B,Darrow,350,Fifth Avenue,New York,NY,10118
Terrence,H,Donnelly,4059,Mt. Lee Drive,Hollywood,CA,90068
You'll notice right away that there are two changes between the new file and the old one. First, you
are using commas to delimit the fields. Second, you have trimmed all of the fields. Typically when using
delimited files, each field is not padded to a fixed-width like they are in fixed-width files. Because of that,
the record length can vary, unlike the fixed-width record length.
As mentioned, the only configuration update you need to make to use the new file format is how
each record is parsed. For fixed-width records, you used the FixedLengthTokenizer to parse each line.
For the new delimited records, you will use the
org.springframework.batch.item.file.transform.DelimitedLineTokenizer to parse the records into a
FieldSet. Listing 7-9 shows the configuration of the reader updated with the DelimitedLineTokenizer.
Listing 7-9. customerFileReader with the DelimitedLineTokenizer
<beans:bean id="customerFile"
class="" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
<beans:bean id="customerFileReader"
<beans:property name="resyource" ref="customerFile" />
<beans:property name="lineMapper">
<beans:property name="lineTokenizer">
<beans:property name="names"
<beans:property name="delimiter" value=","/>
<beans:property name="fieldSetMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.
<beans:property name="prototypeBeanName" value="customer"/>
Search WWH ::

Custom Search