Java Reference
In-Depth Information
<beans:property name="names"
<beans:property name="delimiter" value=";"/>
By changing the configuration of the FormatterLineAggregator to use Spring Batch's
DelimitedLineAggregator , the only other change you have to make is removing the format dependency
and including the definition of a delimiter character. After building the project with the same mvn clean
install you used previously, you can run the job with the command in Listing 9-12.
Listing 9-12. Running formatJob to Generate Delimited Output
java -jar itemWriters-0.0.1-SNAPSHOT.jar jobs/formatJob.xml formatJob
customerFile=/input/customer.csv outputFile=/output/delimitedCustomers.txt
The results of the formatJob with the updated configuration are shown in Listing 9-13.
Listing 9-13. formatJob results for delimited file writing
58540;IL;St. Louis;5570 Isabella Ave;Darrow;Richard
94935;NY;St. Louis;4686 Mt. Lee Drive;Darrow;Warren
38635;CA;Houston;7844 S. Greenwood Ave;Donnelly;Barack
55366;NY;Las Vegas;2447 S. Greenwood Ave;Benes;Ann
57640;CA;Omaha;3141 Farnam Street;Gates;Erica
37288;FL;Hollywood;6670 S. Greenwood Ave;Williams;Warren
97261;FL;Houston;3273 Isabella Ave;Darrow;Harry
90520;WA;Las Vegas;8407 Infinite Loop Drive;Darrow;Steve
It's easy to create flat files with Spring Batch. With zero lines of code outside of the domain object,
you can read in a file and convert its format to either a formatted file or a delimited file. Both of the
examples for flat-file processing have assumed that the file is a new file to be created each time. The next
section looks at some of the more advanced options Spring Batch provides for handling what file to write
File Creation Options
Unlike reading from an input file where the file must exist or it's considered an error condition, an
output file may or may not exist, and that may or may not be ok. Spring Batch provides the ability to
configure how to handle each of these scenarios based on your needs. This section looks at how to
configure FlatFileItemWriter to handle multiple file creation scenarios.
In Table 9-1, there were two options for FlatFileItemWriter that pertain to file creation:
shouldDeleteIfEmpty and shouldDeleteIfExists . shouldDeleteIfEmpty actually deals with what to do
when a step is complete. It's set to false by default. If a step executes, no items were written (a header
Search WWH ::

Custom Search