This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.
You need to get rid of the CompositeItemStream stuff. The CompositeItemStream is trying to manage your FFIW for you. However, this is not what you want. Inside your write() method you are manually opening and closing the FFIW. You do not want the framework to try to open/update/close the FFIW.
There is a bit progress. Now i am not getting mesage 'Stream already closed' because now i am creating reference of FileItemWriter in the write() method itself, opening it, writing data to it and then closing it.
Is there a way by which CompositeItemStream can be used to write multiple files where opening/closing of FFIW is managed by framework itself. Each and every time CompanyDTO object comes to the writer a new file should get created.
Using ItemStream to have the framework manage opening/closing is the standard way to use Spring Batch. However, this does not apply to your situation. The reason is because the scope of your file is smaller than the write() method. Since you must open and close more than one file within one call to write() there is no way that the framework could do it for you. But you should not consider this to be a problem; you simply have different requirements than the typical batch job.