Announcement Announcement Module
No announcement yet.
What is strategy for putting count of lines into header of flat file Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is strategy for putting count of lines into header of flat file

    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

    HEADER2 (contains number of records)

    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

    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 ?

  • #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.