Java Reference
In-Depth Information
Listing 7-32. CustomerFileReader
package com.apress.springbatch.chapter7;
import java.util.ArrayList;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.item.file.ResourceAwareItemReaderItemStream;
import org.springframework.core.io.Resource;
public class CustomerFileReader implements
ResourceAwareItemReaderItemStream<Object> {
private Object curItem = null;
private ResourceAwareItemReaderItemStream<Object> delegate;
public Object read() throws Exception {
if (curItem == null) {
curItem = (Customer) delegate.read();
}
Customer item = (Customer) curItem;
curItem = null;
if (item != null) {
item.setTransactions(new ArrayList<Transaction>());
while (peek() instanceof Transaction) {
item.getTransactions().add((Transaction) curItem);
curItem = null;
}
}
return item;
}
public Object peek() throws Exception, UnexpectedInputException,
ParseException {
if (curItem == null) {
curItem = delegate.read();
}
return curItem;
}
public void setDelegate(
ResourceAwareItemReaderItemStream<Object> delegate) {
this.delegate = delegate;
Search WWH ::




Custom Search