-
Jul 29th, 2010, 12:51 AM
#1
What is strategy for putting count of lines into header of flat file
Hello
let me briefly describe my problem. I'm using spring-batch to create flat file reports basing on DB data. The format of flat file is similar to one below
HEADER1
HEADER2 (contains number of records)
....
RECORD1
RECORD2
...
RECORDN
FOOTER
I'm using FlatFileHeaderCallback and FlatFileHeaderCallback interfaces to write header and footer accordingly. There's good and quite obvious tutorial on how to write count of record into footer http://static.springsource.org/sprin...ASummaryFooter.
My problem is that i need to write count of lines into header, i.e. before all input will be processed and i can count them.
Only approach for now is to do following
1. don't use header callback
2. in write() method of ItemWriter storing items into internal storage instead of writing to flat file
3. use footer callback to:
- write header1 and header2 with number of lines
- write internal storage of item to flat file
- write footer
Drawbacks of this approach is need of having internal storage of objects before writing them to file since it could be huge number of such items.
Could community advice some other approach or workaround to solve such kind of tasks ?
-
Aug 1st, 2010, 07:39 AM
#2
Best practice to save memory for summary headers is to write them in a separate file in a listener or footer callback and then concatenate that file with the main body in a separate step or a listener.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules