Package org.springframework.batch.item.file

# Class ResourcesItemReader

java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<org.springframework.core.io.Resource>
org.springframework.batch.item.file.ResourcesItemReader

All Implemented Interfaces:
  `ItemReader<org.springframework.core.io.Resource>`, `ItemStream`, `ItemStreamReader<org.springframework.core.io.Resource>`

public class ResourcesItemReader extends AbstractItemStreamItemReader<org.springframework.core.io.Resource>
`ItemReader` which produces `Resource` instances from an array. This can be used conveniently with a configuration entry that injects a pattern (e.g. `mydir/*.txt`, which can then be converted by Spring to an array of Resources by the ApplicationContext.
Thread-safe between calls to `open(ExecutionContext)`. The `ExecutionContext` is not accurate in a multi-threaded environment, so do not rely on that data for restart (i.e. always open with a fresh context).

Since:
  2.1
Author:
  Dave Syer, Mahmoud Ben Hassine
See Also:
  - `ResourceArrayPropertyEditor`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ResourcesItemReader()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `open(ExecutionContext executionContext)`
  No-op.
  `org.springframework.core.io.Resource`
  `read()`
  Increments a counter and returns the next `Resource` instance from the input, or `null` if none remain.
  `void`
  `setResources(org.springframework.core.io.Resource[] resources)`
  The resources to serve up as items.
  `void`
  `update(ExecutionContext executionContext)`
  Return empty `ExecutionContext`.

  ### Methods inherited from class org.springframework.batch.item.ItemStreamSupport

  `close, getExecutionContextKey, setExecutionContextName, setName`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.springframework.batch.item.ItemStream

  `close`

- ## Constructor Details

  - ### ResourcesItemReader

    public ResourcesItemReader()

- ## Method Details

  - ### setResources

    public void setResources(org.springframework.core.io.Resource[] resources)
    The resources to serve up as items. Hint: use a pattern to configure.
    Parameters:
      `resources` - the resources

  - ### read

    @Nullable public org.springframework.core.io.Resource read() throws Exception
    Increments a counter and returns the next `Resource` instance from the input, or `null` if none remain.
    Returns:
      T the item to be processed or `null` if the data source is exhausted
    Throws:
      `ParseException` - 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.
      `Exception` - if an there is a non-specific error.

  - ### open

    public void open(ExecutionContext executionContext) throws ItemStreamException
    Description copied from class: `ItemStreamSupport`
    No-op.
    Specified by:
      `open` in interface `ItemStream`
    Overrides:
      `open` in class `ItemStreamSupport`
    Parameters:
      `executionContext` - current step's `ExecutionContext`. Will be the executionContext from the last run of the step on a restart.
    Throws:
      `ItemStreamException`
    See Also:
      - `ItemStream.open(ExecutionContext)`

  - ### update

    public void update(ExecutionContext executionContext) throws ItemStreamException
    Description copied from class: `ItemStreamSupport`
    Return empty `ExecutionContext`.
    Specified by:
      `update` in interface `ItemStream`
    Overrides:
      `update` in class `ItemStreamSupport`
    Parameters:
      `executionContext` - to be updated
    Throws:
      `ItemStreamException`
    See Also:
      - `ItemStream.update(ExecutionContext)`