Sep 17th, 2012, 04:37 AM
routing data to multiple files in item writer based on item's property as criteria
I am getting a list of items in my reader.
There is a property called CODE in each item object having several possible values not known to me before hand.
1) Based on the value of CODE in each item, I want to write that particular item in a output file pertaining to that CODE. For e.g. if my current item's code is "abc", the item should be written in to abc.txt in the writer.
2) If there is a code "xyz" in current item, for which the file is not present, a new file should get created and the item should go to that file.
3) For all such multiple files created based on code, I also want to add a header and footer call back to enter some details e.g. count of items in each file.
Is it possible to have a writer, which satisfies above 3 requirements ?
I know that using multiresourceitemwriter, one can divide the data among multiple output files. But as far as I know, this division is based on the number of items. For e.g. first 10 items in file1, next 10 in file2 and so on. So, I think I can not use multiresourceitemwriter for my issue.
I can not use BackToBackPatternClassifier as it knows the number of writers present. However, I do not have the Code list available beforehand.
But how to route data to output files based on an item property as mentioned in my question ?
I am well acquainted with Spring Batch and just need a little guidance since this is the first time I am facing this kind of issue.
Thanks for reading!
Last edited by nikunj_c; Sep 17th, 2012 at 05:04 AM.
Sep 17th, 2012, 11:45 AM
The class allows you to implement multiple itemWriters as a composite.
Give it a try.
Tags for this Thread