Writing many lines from one item in FlatFileItemWriter
I am using the FlatFileItemWriter to write data read by a reader. Each read item results in writing N lines in the file.
What is the strategy to be used in this case ?
My first idea is to set up a ItemTransformer that transforms the item into a List of N sub-items. The list is passed as a single item to the FlatFileItemWriter.write() method; a FieldSetCreator creates a huge FieldSet containing N*nb_fields_per_sub_item fields, and a LineAggregator creates a String containing N lines (i.e. the returned String contains \n characters), with a double nested loop: (for i=0..N) and for (j=0..nb_fields_per_sub_item).
There is however a problem with this : the FlatFileItemReader increments its the linesWritten counter by one for each written line, even if the line contains \n characters.
I really need to the know the exact number of written lines, as each line of the output file must start with the line number.