Announcement Announcement Module
Collapse
No announcement yet.
MultiResourceItemWriter and list of files written Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MultiResourceItemWriter and list of files written

    I have written predefined number of lines in a flat file using MultiResourceItemWriter. It generates lot of files.

    I need to get the file list that have been created as part of this process.

    Please let me know how to get the list of files that have been written.

    Code:
    <bean id="flatFileWriter" class="org.springframework.batch.item.file.MultiResourceItemWriter" scope="step">
      <property name="resource" value="file:H:/ledgers-output.txt" />
      <property name="itemCountLimitPerResource" value="100" />
      <property name="saveState" value="true" />
      <property name="delegate" ref="delegateWriter" />
    </bean> 
    <bean id="delegateWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
      <property name="lineAggregator">
        <bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
          <property name="delimiter" value="," />
          <property name="fieldExtractor">
            <bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
              <property name="names" value="id,valueDate,tradeID" />
            </bean>
          </property>
        </bean>
      </property>
    </bean>

  • #2
    One idea would be to have a shell script that does this task for you.

    Comment


    • #3
      I was looking for getting it as part of spring batch processing itslef. Any other ideas ?

      Comment


      • #4
        In a StepExecutionListener.afterStep you could retrieve the 'MultiResourceItemWriter.resource.index' from the step execution context. For example if resource.index = 5 you should have 5 output files: H:/ledgers-output.txt.1, H:/ledgers-output.txt.2, H:/ledgers-output.txt.3, H:/ledgers-output.txt.4, and H:/ledgers-output.txt.5.

        Comment

        Working...
        X