IN PROGRESS - BATCH-827: Create Sample job for reading and writing headers and footers

This commit is contained in:
robokaso
2008-09-11 14:21:43 +00:00
parent df870a5df6
commit 2973139959
9 changed files with 212 additions and 19 deletions

View File

@@ -0,0 +1,32 @@
package org.springframework.batch.sample.support;
import java.io.IOException;
import java.io.Writer;
import org.springframework.batch.item.file.FileWriterCallback;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.FlatFileItemWriter;
import org.springframework.batch.item.file.LineCallbackHandler;
import org.springframework.util.Assert;
/**
* Designed to be registered with both {@link FlatFileItemReader} and
* {@link FlatFileItemWriter} and copy header line from input file to output
* file.
*/
public class HeaderCopyCallback implements LineCallbackHandler, FileWriterCallback {
private String header = "";
public void handleLine(String line) {
Assert.notNull(line);
this.header = line;
}
public void write(Writer writer) throws IOException {
writer.write("header from input: " + header);
}
}

View File

@@ -0,0 +1,27 @@
package org.springframework.batch.sample.support;
import java.io.IOException;
import java.io.Writer;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.item.file.FileWriterCallback;
/**
* Writes summary info in the footer of a file.
*/
public class SummaryFooterCallback extends StepExecutionListenerSupport implements FileWriterCallback{
private StepExecution stepExecution;
public void write(Writer writer) throws IOException {
writer.write("footer - number of items written: " + stepExecution.getWriteCount());
}
@Override
public void beforeStep(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
}