
org.sfm.csv.impl.CsvMapperIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.csv.impl;
import org.sfm.csv.CsvReader;
import org.sfm.csv.parser.CellConsumer;
import org.sfm.utils.RowHandler;
import java.io.IOException;
import java.util.Iterator;
public class CsvMapperIterator implements Iterator {
private T currentValue;
private boolean isFetched;
private final CsvReader reader;
private final CellConsumer cellConsumer;
public CsvMapperIterator(CsvReader reader, CsvMapperImpl csvMapperImpl) {
cellConsumer = csvMapperImpl.newCellConsumer(new RowHandler() {
@Override
public void handle(T t) throws Exception {
currentValue = t;
}
});
this.reader = reader;
}
@Override
public boolean hasNext() {
fetch();
return currentValue != null;
}
private void fetch() {
if (isFetched) return;
try {
currentValue = null;
reader.parseRow(cellConsumer);
isFetched = true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public T next() {
fetch();
isFetched = false;
return currentValue;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy