public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
setResources(Resource[]), the
actual reading is delegated to setDelegate(ResourceAwareItemReaderItemStream).
Input resources are ordered using setComparator(Comparator) to make sure resource ordering is preserved
between job runs in restart scenario.| Constructor and Description |
|---|
MultiResourceItemReader() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the
setDelegate(ResourceAwareItemReaderItemStream) reader and reset instance variable values. |
org.springframework.core.io.Resource |
getCurrentResource()
Getter for the current resource.
|
void |
open(ExecutionContext executionContext)
Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in
the resource.
|
T |
read()
Reads the next item, jumping to next resource if necessary.
|
void |
setComparator(java.util.Comparator<org.springframework.core.io.Resource> comparator) |
void |
setDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate) |
void |
setResources(org.springframework.core.io.Resource[] resources) |
void |
setSaveState(boolean saveState)
Set the boolean indicating whether or not state should be saved in the provided
ExecutionContext during
the ItemStream call to update. |
void |
setStrict(boolean strict)
In strict mode the reader will throw an exception on
open(org.springframework.batch.item.ExecutionContext) if there are no resources to read. |
void |
update(ExecutionContext executionContext)
Store the current resource index and position in the resource.
|
getExecutionContextKey, setExecutionContextName, setNamepublic void setStrict(boolean strict)
open(org.springframework.batch.item.ExecutionContext) if there are no resources to read.strict - false by defaultpublic T read() throws java.lang.Exception, UnexpectedInputException, ParseException
null if the data source is
exhaustedParseException - if there is a problem parsing the current record
(but the next one may still be valid)NonTransientResourceException - if there is a fatal exception in
the underlying resource. After throwing this exception implementations
should endeavour to return null from subsequent calls to read.UnexpectedInputException - if there is an uncategorised problem
with the input data. Assume potentially transient, so subsequent calls to
read might succeed.java.lang.Exception - if an there is a non-specific error.public void close()
throws ItemStreamException
setDelegate(ResourceAwareItemReaderItemStream) reader and reset instance variable values.close in interface ItemStreamclose in class ItemStreamSupportItemStreamExceptionItemStream.close()public void open(ExecutionContext executionContext) throws ItemStreamException
open in interface ItemStreamopen in class ItemStreamSupportexecutionContext - current step's ExecutionContext. Will be the
executionContext from the last run of the step on a restart.ItemStreamExceptionItemStream.open(ExecutionContext)public void update(ExecutionContext executionContext) throws ItemStreamException
update in interface ItemStreamupdate in class ItemStreamSupportexecutionContext - to be updatedItemStreamExceptionItemStream.update(ExecutionContext)public void setDelegate(ResourceAwareItemReaderItemStream<? extends T> delegate)
delegate - reads items from single Resource.public void setSaveState(boolean saveState)
ExecutionContext during
the ItemStream call to update.saveState - true to update ExecutionContext. False do not update
ExecutionContext.public void setComparator(java.util.Comparator<org.springframework.core.io.Resource> comparator)
comparator - used to order the injected resources, by default compares Resource.getFilename()
values.public void setResources(org.springframework.core.io.Resource[] resources)
resources - input resources@Nullable public org.springframework.core.io.Resource getCurrentResource()
null if all resources have been
processed or the first resource has not been assigned yet.