spring-batchbatch-processingreaderitemwriter

Can we use Spring batch Item Reader and Writer on a file which needs to skip first and last line?


I have a file to written to db after doing some validations. The file will have Header and Trailer which needs to be validated and then skipped, and all the lines in between should be mapped and loaded to a db if validations are met. Can I use Item Reader and Writer to do this? Below is a sample file data which has a header line, a trailer line and in between them the lines with actual data to be loaded to db. Any help is appreciated.

HEADER|xxxxx|20190405T143025Z linedata|linedata|linedata|linedata|||linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata|linedata

TRAILER|20190405T143025Z|1

p.s: I am an IIB Developer, this is my first time using spring batch.


Solution

  • You can break down the requirement in two steps: