title: Get path of onSkipInRead Item
body: <p>Is there a way to get the location of the failed to be read input file to use it in a <code>SkipListener</code>?</p>
  
  <p>Example:<br/><br/>
  My <code>SkipListener</code> moves every file that failed to be processed or written to an error location:</p>
  
  <pre><code>@Override
      public void onSkipInWrite(MyFileObject arg0, Throwable arg1) {
          logger.error("onSkipInWrite ");
          logToErrorDirectory(arg0.getPath(), arg1);
  
      }
  
  @Override
      public void onSkipInProcess(MyFileObject arg0, Throwable arg1) {
          logger.error("onSkipInProcess ");
          logToErrorDirectory(arg0.getPath(), arg1);
  
      }
  
  @Override
      public void onSkipInRead(Throwable arg1) {
          // WHAT TO DO HERE
  
      }
  </code></pre>
  
  <p>I need to do the same thing when an Item (<code>.xml</code> file to be precise) <strong>fails to be read too.</strong></p>
  
  <p>My configuration:</p>
  
  <pre><code>&lt;bean id="ExportPatentReader"
          class="org.springframework.batch.item.file.MultiResourceItemReader"
          scope="step"&gt;
          &lt;property name="resources" value="file:SomeFolder/*.xml'&lt;/property&gt;
          &lt;property name="delegate" ref="staxPatentReader"&gt;&lt;/property&gt;
          &lt;property name="strict" value="true"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;bean id="staxPatentReader" class="org.springframework.batch.item.xml.StaxEventItemReader"
          scope="step"&gt;
          &lt;property name="fragmentRootElementName" value="Root" /&gt;
          &lt;property name="unmarshaller" ref="patentMarshaller" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="patentMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
          &lt;property name="classesToBeBound"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.company.MyFileObject&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>In <code>MyFileObject</code> I can easily get the resource and move the file but the problem is before that. <strong>A typical case is a malformed xml file which still needs to be moved to the error directory</strong> but because it's still unmarshalled I can not find a way to get it's resource path.</p>
  
  <p><strong>---------------------UPDATE---------------------</strong></p>
  
  <p>Following @Michael Minella 's suggestion I used the sorted <code>Resources[]</code> and the <code>MultiResourceItemReader.resourceIndex</code>to get the failed file. For <strong>commit-interval=1</strong> worked perfectly! But for bigger ci no luck :( . </p>
  
  <p>My adjusted part of Listener:</p>
  
  <pre><code>@Override
      public void onSkipInRead(Throwable arg0) {
          logger.error("onSkipInRead ");
  
          ExecutionContext stepContext = stepExecution.getExecutionContext();
          logger.info("ExecutionContext: " + stepContext.toString());
          logger.info("stepExecution: " + stepExecution.toString());
  
          Arrays.sort(resources, comparator);
  
          Resource errorResource = resources[stepContext.getInt("MultiResourceItemReader.resourceIndex")+1];
  
          // NOT WORKING
          Resource errorResource2 = resources[stepExecution.getReadCount()+1];
          try {
              // INCORRECT PATH FOR CI&gt;1
              logger.info("Path: " + errorResource.getFile().getCanonicalPath());
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
  private Comparator&lt;Resource&gt; comparator = new Comparator&lt;Resource&gt;() {
  
          /**
           * Compares resource filenames.
           */
          @Override
          public int compare(Resource r1, Resource r2) {
              return r1.getFilename().compareTo(r2.getFilename());
          }
  
      };
  
  @Override
  public void beforeStep(StepExecution arg0) {
      stepExecution = arg0;
  }
  </code></pre>
  
  <p>Probably the problem is when every commit finishes and <code>ExecutionContext</code> is updated but couldn't find a workaround. <br/><br/>For the update thing during logging the printed stepExecution looked like that: <code>StepExecution: id=6, version=2, name=partitionedStep:partition4, status=STARTED, exitStatus=EXECUTING, readCount=10, filterCount=0, writeCount=10 readSkipCount=2, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=</code> <br/>So I was thinking that maybe the correct index can be a combination of <code>Items per commit + MultiResourceReader.index</code></p>
  
  <p>Another thing... I forgot to mention in the beginning that I use a <code>partitioner</code> for reading files although not sure if this affects the result.</p>
  
  <p>The more I play with the <code>SkipListener</code> the more I think that an easier solution would be to write a custom reader to replace at least <code>StaxEventReader</code> :D</p>