Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.springframework.batch.item.file;
org.springframework.batch.item.ItemReader which produces 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(org.springframework.batch.item.ExecutionContext). The org.springframework.batch.item.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).

	private Resource[] resources = new Resource[0];
	private AtomicInteger counter = new AtomicInteger(0);
		 * Initialize the name for the key in the execution context.

The resources to serve up as items. Hint: use a pattern to configure.

resources the resources
	public void setResources(Resource[] resources) {
		this. = Arrays.asList(resources).toArray(new Resource[resources.length]);

Increments a counter and returns the next instance from the input, or null if none remain.
	public synchronized Resource read() throws Exception {
		int index = .incrementAndGet() - 1;
		if (index >= .) {
			return null;
		return [index];
	public void close() throws ItemStreamException {
	public void open(ExecutionContext executionContextthrows ItemStreamException {
		.set(executionContext.getInt(getKey("COUNT"), 0));
	public void update(ExecutionContext executionContextthrows ItemStreamException {
		executionContext.putInt(getKey("COUNT"), .get());
New to GrepCode? Check out our FAQ X