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

com.poiji.bind.mapping.XSSFUnmarshallerStream Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package com.poiji.bind.mapping;

import com.poiji.bind.PoijiInputStream;
import com.poiji.exception.PoijiException;
import com.poiji.option.PoijiOptions;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.function.Consumer;

/**
 * Created by hakan on 22/10/2017
 */
final class XSSFUnmarshallerStream extends XSSFUnmarshaller {

    private final PoijiInputStream poijiInputStream;

    XSSFUnmarshallerStream(PoijiInputStream poijiInputStream, PoijiOptions options) {
        super(options);
        this.poijiInputStream = poijiInputStream;
    }

    @Override
    public  void unmarshal(Class type, Consumer consumer) {

        if (options.getPassword() != null) {
            returnFromEncryptedFile(type, consumer);
            return;
        }

        returnFromExcelFile(type, consumer);
    }

    @Override
    public  void returnFromExcelFile(Class type, Consumer consumer) {

        try (OPCPackage open = OPCPackage.open(poijiInputStream.stream())) {

            unmarshal0(type, consumer, open);

        } catch (ParserConfigurationException | SAXException | IOException | OpenXML4JException e) {
            throw new PoijiException("Problem occurred while reading data", e);
        }
    }

    @Override
    public  void returnFromEncryptedFile(Class type, Consumer consumer) {

        try (POIFSFileSystem fs = new POIFSFileSystem(poijiInputStream.stream())) {

            listOfEncryptedItems(type, consumer, fs);

        } catch (IOException e) {
            throw new PoijiException("Problem occurred while reading data", e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy