Announcement Announcement Module
No announcement yet.
FlatFileHeaderCallback Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileHeaderCallback

    HI all
    i have to write a job which reads data from a db and dump it to a file.

    each field in the output will be separated by a tab character, and i need to write header for all fields i will be dumping to the file

    i have been reading the documentation, and i see that i need to implement the FlatFileHeaderCallback, which has only
    this method

    void writeHeader(Writer writer)
    as the file is a tab-delimited one, my headers should be also tag-delimited. therefore i assume that in writing the headers i will have to separate each header by \t myself (sorry for dumb question but it's first time i use spring batch).

    Now, are there any chances that i can get somehow the delimiter associated with the lineAggregator straight into my FlatFileHeaderCallback somehow (either via context or some 'hidden properties' of the flatfileheadercallback?

    for example assume this configuration:
    <bean id="flatFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
               <property name="resource" value="ile:c:/tmp/myoutputfile.txt" />
               <property name="lineAggregator">
                         <property name="delimiter" value="\t" />
                         <property name="fieldExtractor">
                                   <property name="names" value="field1,field2,field3" />
                         <property name="headerCallback" ref="myHeaderCallback" />

    i was wondering how i can inject the delimiter defined on the flatFileWriter bean....?

    is the only choice this one
    <bean id="myDelimiter" value-"\t"/>
    and then reuse that in my headercallback and lineaggregator?

    w/kindest regards