Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(Spring-Batch) Example implementation wraps a MultiResourceItemReader to get the current resource.
public class WrappedMrirToGetCurrentResource<T> implements ItemStreamReader<T> {
private MultiResourceItemReader<T> mrir;
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
mrir.open(executionContext);
// current.resource is only available here if it's a restart
if (mrir.getCurrentResource() != null && mrir.getCurrentResource().getFilename() != null) {
System.out.println("open:" + mrir.getCurrentResource().getFilename());
}
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
mrir.update(executionContext);
// one of the most reliable positions to get the current.resource
if (mrir.getCurrentResource() != null && mrir.getCurrentResource().getFilename() != null) {
System.out.println("update:" + mrir.getCurrentResource().getFilename());
}
}
@Override
public void close() throws ItemStreamException {
mrir.close();
}
@Override
public T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
T result = mrir.read();
// another position to get the actual current.resource, has to be called
// after the first read
if (mrir.getCurrentResource() != null && mrir.getCurrentResource().getFilename() != null) {
System.out.println("read:" + mrir.getCurrentResource().getFilename());
}
return result;
}
public void setMrir(MultiResourceItemReader<T> mrir) {
this.mrir = mrir;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.