title: Customised MultiResourceItemReader: assign different mappers/writers for each file inside an archive
body: <p>I have a requirement to read/process an archive which contains several flat files, each file should have it's own mapping and writer.</p>
  
  <p>How do I go about assigning different <code>FieldSetmappers</code> and Writers for each file
  using the bean configuration.</p>
  
  <p>I have started with extending the <code>MultiResourceItemReader</code> and overriding the <strong><code>open</code></strong> method
  as shown here:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Override
      public void open(ExecutionContext executionContext)
              throws ItemStreamException {
  
          ZipFile zipFile;
          List&lt;Resource&gt; resources = new ArrayList&lt;Resource&gt;();
          try {
              zipFile = new ZipFile(pathtozipfile);
              Enumeration zippedFile = zipFile.entries();
              while (zippedFile.hasMoreElements()) {
                  ZipEntry zipEntry = (ZipEntry) zippedFile.nextElement();
                  resources.add(new InputStreamResource(zipFile
                          .getInputStream(zipEntry), zipEntry.getName()));
  
              }
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          this.setResources(resources.toArray(new Resource[resources.size()]));
  
          super.open(executionContext);
      }
  </code></pre>
  
  <p></p>
  
  <p>and the bean declaration as follows:</p>
  
  <pre><code>&lt;bean id="itemReader" class="com.proc.spring.ZipMResourceItemReader" scope="step"&gt;
          &lt;property name="pathtozipfile" value="#{jobParameters['input.pathtozipfile']}" /&gt;
          &lt;property name="delegate" ref="delegateReader" /&gt;   &lt;/bean&gt;
  
   &lt;bean id="delegateReader" class="org.springframework.batch.item.file.FlatFileItemReader"&gt;
          &lt;property name="lineMapper1"&gt;
          &lt;bean class="org.springframework.batch.item.file.mapping.." /&gt;
          &lt;/property&gt;
     &lt;/bean&gt;
  </code></pre>
  
  <p>I know programmatically, I could use the <code>getCurrentResource()</code> during read but I expect spring must support the ability to assign different <code>FieldSetMappers</code> based on current resource of the <code>MultiResourceItemReader</code>.</p>
  
  <p>I guess perhaps extracting the files as the first step then assign each file/resource to a step: <code>FlatFileItemReader</code> would be solution  but would prefer to use delegate method if its possible to differentiate the mappers/writers based on the resource name.</p>