org.springframework.batch.item.file
Class ResourcesItemReader

java.lang.Object
  extended by org.springframework.batch.item.util.ExecutionContextUserSupport
      extended by org.springframework.batch.item.file.ResourcesItemReader
All Implemented Interfaces:
ItemReader<Resource>, ItemStream, ItemStreamReader<Resource>

public class ResourcesItemReader
extends ExecutionContextUserSupport
implements ItemStreamReader<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
See Also:
ResourceArrayPropertyEditor

Constructor Summary
ResourcesItemReader()
           
 
Method Summary
 void close()
          If any resources are needed for the stream to operate they need to be destroyed here.
 void open(ExecutionContext executionContext)
          Open the stream for the provided ExecutionContext.
 Resource read()
          Increments a counter and returns the next Resource instance from the input, or null if none remain.
 void setResources(Resource[] resources)
          The resources to serve up as items.
 void update(ExecutionContext executionContext)
          Indicates that the execution context provided during open is about to be saved.
 
Methods inherited from class org.springframework.batch.item.util.ExecutionContextUserSupport
getKey, getName, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcesItemReader

public ResourcesItemReader()
Method Detail

setResources

public void setResources(Resource[] resources)
The resources to serve up as items. Hint: use a pattern to configure.

Parameters:
resources - the resources

read

public Resource read()
              throws Exception
Increments a counter and returns the next Resource instance from the input, or null if none remain.

Specified by:
read in interface ItemReader<Resource>
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.

close

public void close()
           throws ItemStreamException
Description copied from interface: ItemStream
If any resources are needed for the stream to operate they need to be destroyed here. Once this method has been called all other methods (except open) may throw an exception.

Specified by:
close in interface ItemStream
Throws:
ItemStreamException

open

public void open(ExecutionContext executionContext)
          throws ItemStreamException
Description copied from interface: ItemStream
Open the stream for the provided ExecutionContext.

Specified by:
open in interface ItemStream
Throws:
ItemStreamException

update

public void update(ExecutionContext executionContext)
            throws ItemStreamException
Description copied from interface: ItemStream
Indicates that the execution context provided during open is about to be saved. If any state is remaining, but has not been put in the context, it should be added here.

Specified by:
update in interface ItemStream
Parameters:
executionContext - to be updated
Throws:
ItemStreamException


Copyright © 2013 SpringSource. All Rights Reserved.