io.github.millij.poi.ss.reader.AbstractSpreadsheetReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of poi-object-mapper Show documentation
Show all versions of poi-object-mapper Show documentation
Objects mapper for Office formats - Excel files, Spreadsheets, etc.
The newest version!
package io.github.millij.poi.ss.reader;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.millij.poi.SpreadsheetReadException;
import io.github.millij.poi.ss.handler.RowBeanCollector;
/**
* A abstract implementation of {@link SpreadsheetReader}.
*/
abstract class AbstractSpreadsheetReader implements SpreadsheetReader {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSpreadsheetReader.class);
protected final int headerRowIdx;
protected final int lastRowIdx;
// Constructor
// ------------------------------------------------------------------------
AbstractSpreadsheetReader(final int headerRowIdx, final int lastRowIdx) {
super();
// init
this.headerRowIdx = headerRowIdx;
this.lastRowIdx = lastRowIdx;
final String insName = this.getClass().getSimpleName();
LOGGER.debug("Successfully instantiated {} : header #{}, lastRow #{}", insName, headerRowIdx, lastRowIdx);
}
// Abstract Methods
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
@Override
public List read(final Class beanClz, final InputStream is) throws SpreadsheetReadException {
// Row Collector
final RowBeanCollector beanCollector = new RowBeanCollector<>();
// Read with callback to fill list
this.read(beanClz, is, beanCollector);
// Result
final List beans = beanCollector.getBeans();
return beans;
}
@Override
public List read(final Class beanClz, final InputStream is, final int sheetNo)
throws SpreadsheetReadException {
// Row Collector
final RowBeanCollector beanCollector = new RowBeanCollector<>();
// Read with callback to fill list
this.read(beanClz, is, sheetNo, beanCollector);
// Result
final List beans = beanCollector.getBeans();
return beans;
}
//
// Read to Map
@Override
public List