in src/main/java/com/univocity/parsers/common/routine/AbstractRoutines.java [813:876]
public <T> IterableResult<T, ParsingContext> iterate(final Class<T> beanType, final Reader input) {
final Object[] beanHolder = new Object[1];
setRowProcessor(new BeanProcessor<T>(beanType) {
@Override
public void beanProcessed(T bean, ParsingContext context) {
beanHolder[0] = bean;
}
@Override
public void processEnded(ParsingContext context) {
super.processEnded(context);
parserSettings.setRowProcessor(null);
}
});
return new IterableResult<T, ParsingContext>() {
private ParsingContext context;
@Override
public ParsingContext getContext() {
return context;
}
@Override
public ResultIterator<T, ParsingContext> iterator() {
final AbstractParser<P> parser = createParser(parserSettings);
parser.beginParsing(input);
context = parser.getContext();
return new ResultIterator<T, ParsingContext>() {
String[] row;
@Override
public boolean hasNext() {
return beanHolder[0] != null || row != null || (row = parser.parseNext()) != null;
}
@Override
public T next() {
T out = (T) beanHolder[0];
if (out == null && hasNext()) {
out = (T) beanHolder[0];
}
beanHolder[0] = null;
row = null;
return out;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Can't remove beans");
}
@Override
public ParsingContext getContext() {
return context;
}
};
}
};
}