IN PROGRESS - BATCH-827: Create Sample job for reading and writing headers and footers
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user