All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.millij.poi.ss.reader.AbstractSpreadsheetReader Maven / Gradle / Ivy

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> read(final InputStream is) throws SpreadsheetReadException {
        // Row Collector
        final RowBeanCollector> beanCollector = new RowBeanCollector<>();

        // Read with callback to fill list
        this.read(is, beanCollector);

        // Result
        final List> beans = beanCollector.getBeans();
        return beans;
    }

    @Override
    public List> read(final InputStream is, final int sheetNo) throws SpreadsheetReadException {
        // Row Collector
        final RowBeanCollector> beanCollector = new RowBeanCollector<>();

        // Read with callback to fill list
        this.read(is, sheetNo, beanCollector);

        // Result
        final List> beans = beanCollector.getBeans();
        return beans;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy