How to skip empty rows using Spring Batch

1.5k views Asked by At

I'm reading a fixed lenght flatfile with Spring Batch and I would like to skip empty rows and incorrect rows for my batch processing. In the exemple bellow I'm also want to skip rows that starts with the characters "------".

Could you please help me giving an exemple using Skip Policy or other ways?

My file:

---------------------------A---------------------------

AARON THIAGO LOPES                       3099234 100-11

AARON PAPA DA SILVA                      8610822 160-26

ABNER MENEZEZ SOUZA                      1494778 500-35

EDSON EDUARD MOZART                      1286664 500-34 


//Method that reads the file.

@Configuration
@EnableBatchProcessing
public class SpringBatchConfig {

    @Bean
    public Job job(JobBuilderFactory jobBuilderFactory,
                   StepBuilderFactory stepBuilderFactory,
                   ItemReader<Aluno> itemReader,
                   ItemWriter<Aluno> itemWriter){

        Step step = stepBuilderFactory.get("ETL-file-load")
                .<Aluno, Aluno>chunk(100)
                .reader(itemReader)
                .writer(itemWriter)
                .build();

        return jobBuilderFactory.get("ETL-Load")
                .incrementer(new RunIdIncrementer())
                .start(step)
                .build();
    }

    @Bean
    public FlatFileItemReader<Aluno> itemReader(@Value("${input}") Resource resource) {
        FlatFileItemReader<Aluno> flatFileItemReader = new FlatFileItemReader<>();
        flatFileItemReader.setResource(resource);
        flatFileItemReader.setName("CSV-Reader");
        flatFileItemReader.setLinesToSkip(2);
        flatFileItemReader.setLineMapper(lineMapper());
        return flatFileItemReader;
    }
0

There are 0 answers