2

Hi I have requirement to read (n number) of flat file. During file reading if received FileParseException: from reader then stop the current file reading and came out safely and process next file and continue the job execution. currently i have this xml config but i don't want to go with this because i don't have a really skip limit count. is there any way to handle this scenario may be using ItemReaderListener ?

<chunk reader="flatFileItemReader" writer="itemWriter"
             commit-interval="10" skip-limit="2">
         <skippable-exception-classes>
            <include class="org.springframework.batch.item.file.FlatFileParseException"/>
         </skippable-exception-classes>
Raju Yadav
  • 39
  • 1
  • 6
  • Possible duplicate of [How to skip blank lines in CSV using FlatFileItemReader and chunks](http://stackoverflow.com/questions/29673524/how-to-skip-blank-lines-in-csv-using-flatfileitemreader-and-chunks) – Luca Basso Ricci Feb 29 '16 at 07:45

2 Answers2

0

Instead of specifying a skip-limit, you can use a policy. There are several out-of-the-box skip policies, it sounds like you always want to skip (no limit), use AlwaysSkipItemSkipPolicy.

Example config :

<batch:skip-policy>   

     <bean:bean class="org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy"/>

</batch:skip-policy> 
  • Thanks Doeleman for your valuable input. your assumption is correct only i always want to skip some specific exception. could you please share some example. – Raju Yadav Mar 01 '16 at 18:06
  • Just add a skippable-exception-classes section inside your chunk element, like: ` ` – Heikki Doeleman Mar 02 '16 at 08:31
0

thanks Doeleman, based upon your input i am able to skip exception usingAlwaysSkipItemSkipPolicy this is how i have implemented

public class SkipPolicy extends  AlwaysSkipItemSkipPolicy  {

    @Override
     public boolean shouldSkip(java.lang.Throwable t, int skipCount){

        if(t instanceof NonSkippableReadException){
            return true;
        }
        return false;

     }
}

xml config.

<batch:chunk reader="cvsFileItemReader"  writer="mysqlItemWriter" 
                    commit-interval="2" skip-policy="mySkipPolicy">

<bean id="mySkipPolicy" class="com.model.SkipPolicy"/>
Raju Yadav
  • 39
  • 1
  • 6