Results 1 to 2 of 2

Thread: list to flat file

  1. #1
    Join Date
    May 2009
    Posts
    10

    Default list to flat file

    HI,

    If I am getting the list from various external sources(From two Webservices), if I want to write this list in the flat file, can I use the FlatFileItemWriter?

    How can I iterate the list in spring batch?

    Appreciate your help

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    If you just want to use the FlatFileItemWriter on its own, you can do that by passing your list to the write() method:
    Code:
    writer.setResource(new FileSystemResource(outputFile));
    writer.setLineAggregator(someLineAggregator);
    writer.open(new ExecutionContext());
    writer.write(myList);
    writer.close();
    If you want to do it in a "batch processing" way, then you can configure a batch job that uses a ListItemReader and a FlatFileItemWriter. You can do the webservice calls from within the ItemReader by creating a custom wrapper to the ListItemReader:
    Code:
    public class MyItemReader<MyItemType> extends ItemStreamSupport implements ItemReader<MyItemType> {
        private ItemReader listItemReader = null;
    
        public void open(ExecutionContext executionContext) throws ItemStreamException {
            List<MyItemType> webserviceData = getListFromWebservices();
            this.listItemReader = new ListItemReader(webserviceData);
        }
    
        public MyItemType read() {
            return this.listItemReader.read();
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •