Take a look at the org.springframework.batch.core.step.skip.SkipPolicy interface. I will give an example from the Pro Spring Package written by T. Mineller
import java.io.FileNotFoundException; import org.springframework.batch.core.step.skip.SkipLimitExceededException; import org.springframework.batch.core.step.skip.SkipPolicy; import org.springframework.batch.item.ParseException; public class FileVerificationSkipper implements SkipPolicy { public boolean shouldSkip(Throwable exception, int skipCount) throws SkipLimitExceededException { if(exception instanceof FileNotFoundException) { return false; } else if(exception instanceof ParseException && skipCount <= 10) { return true; } else { return false; } } }
Inside the xml file:
<step id="copyFileStep"> <tasklet> <chunk reader="customerItemReader" writer="outputWriter" commit-interval="10" skip-limit="10"> <skippable-exception-classes> <include class="java.lang.Exception"/> <exclude class="org.springframework.batch.item.ParseException"/> </skippable-exception-classes> </chunk> </tasklet> </step>
Or maybe another way could be to add at the beginning of your work a step that sorts your input files into two separate folders. Inside one folder, you will have all of your wrong files, and inside the other folder, only good ones will remain.
source share