Java Reference
In-Depth Information
Listing 10-46. StatementHeaderCallback
package com.apress.springbatch.statement.writer;
import org.springframework.batch.item.file.FlatFileHeaderCallback;
public class StatementHeaderCallback implements FlatFileHeaderCallback {
public void writeHeader(Writer writer) throws IOException {
writer.write(" " +
" Brokerage Account Statement\n");
writer.write("Apress Investment Company " +
" Customer Service Number\n");
writer.write("1060 W. Addison St. " +
" (800) 876-5309\n");
writer.write("Chicago, IL 60613 " +
" Available 24/7\n");
StatementHeaderCallback writes some static text to each of your files. Because Spring Batch handles
calling it, the job is pretty easy.
The last piece of code that needs to be written for the statement job is a suffix generator. This class
will be used by Spring Batch to append a number and the .txt extension on the statement files that are
generated. Listing 4-47 shows the code for the StatementSuffixGenerator.
Listing 4-47. StatementSuffixGenerator.
package com.apress.springbatch.statement.writer;
import org.springframework.batch.item.file.ResourceSuffixCreator;
public class StatementSuffixGenerator implements ResourceSuffixCreator {
public String getSuffix(int arg0) {
return arg0 + ".txt";
That is all the code you need to write to output the robust statement you require. The configuration
is also deceptively simple. It consists of the output resource, a suffix generator so that your files have a
nice file name, StatementFormatter , the statement writer, and the MultiResourceItemWriter used to
create new files for each customer. The complete configuration is shown in Listing 10-48.
Search WWH ::

Custom Search