BATCH-1972: StaxEventItemReader fails when restarted at end of file

This commit is contained in:
jpraet
2013-03-01 21:14:43 +01:00
committed by Michael Minella
parent 02b4a66d45
commit f7a88902ed
2 changed files with 33 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.item.xml;
import java.io.InputStream;
import java.util.NoSuchElementException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
@@ -247,8 +248,18 @@ public class StaxEventItemReader<T> extends AbstractItemCountingItemStreamItemRe
@Override
protected void jumpToItem(int itemIndex) throws Exception {
for (int i = 0; i < itemIndex; i++) {
readToStartFragment();
readToEndFragment();
try {
readToStartFragment();
readToEndFragment();
} catch (NoSuchElementException e) {
if (itemIndex == (i + 1)) {
// we can presume a NoSuchElementException on the last item means the EOF was reached on the last run
return;
} else {
// if NoSuchElementException occurs on an item other than the last one, this indicates a problem
throw e;
}
}
}
}