Announcement Announcement Module
Collapse
No announcement yet.
FlatFileHeaderCallback Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Code:
    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:
    Code:
    <bean id="flatFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
               <property name="resource" value="ile:c:/tmp/myoutputfile.txt" />
               <property name="lineAggregator">
                    <bean
                         class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                         <property name="delimiter" value="\t" />
                         <property name="fieldExtractor">
                              <bean
                                   class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                                   <property name="names" value="field1,field2,field3" />
                              </bean>
                         </property>
                         <property name="headerCallback" ref="myHeaderCallback" />
                    </bean>
               </property>
          </bean>
    ?

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

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

    w/kindest regards
    marco
Working...
X