Announcement Announcement Module
Collapse
No announcement yet.
list to flat file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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();
        }
    }

    Comment

    Working...
    X