Search in sources :

Example 1 with OpenException

use of com.monitorjbl.xlsx.exceptions.OpenException in project data-prep by Talend.

the class StreamingWorkbookReader method init.

// to override https://bz.apache.org/bugzilla/show_bug.cgi?id=57699
public void init(File f) {
    try {
        if (builder.getPassword() != null) {
            // Based on: https://poi.apache.org/encryption.html
            POIFSFileSystem poifs = new POIFSFileSystem(f);
            EncryptionInfo info = new EncryptionInfo(poifs);
            Decryptor d = Decryptor.getInstance(info);
            d.verifyPassword(builder.getPassword());
            pkg = OPCPackage.open(d.getDataStream(poifs));
        } else {
            pkg = OPCPackage.open(f);
        }
        XSSFReader reader = new XSSFReader(pkg);
        ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg);
        StylesTable styles = reader.getStylesTable();
        loadSheets(reader, sst, styles, builder.getRowCacheSize());
    } catch (IOException e) {
        throw new OpenException("Failed to open file", e);
    } catch (OpenXML4JException | XMLStreamException | SAXException e) {
        throw new ReadException("Unable to read workbook", e);
    } catch (GeneralSecurityException e) {
        throw new ReadException("Unable to read workbook - Decryption failed", e);
    }
}
Also used : ReadOnlySharedStringsTable(org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable) Decryptor(org.apache.poi.poifs.crypt.Decryptor) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo) GeneralSecurityException(java.security.GeneralSecurityException) StylesTable(org.apache.poi.xssf.model.StylesTable) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ReadException(com.monitorjbl.xlsx.exceptions.ReadException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) XMLStreamException(javax.xml.stream.XMLStreamException) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) OpenException(com.monitorjbl.xlsx.exceptions.OpenException) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Aggregations

OpenException (com.monitorjbl.xlsx.exceptions.OpenException)1 ReadException (com.monitorjbl.xlsx.exceptions.ReadException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)1 Decryptor (org.apache.poi.poifs.crypt.Decryptor)1 EncryptionInfo (org.apache.poi.poifs.crypt.EncryptionInfo)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1 ReadOnlySharedStringsTable (org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable)1 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1 SAXException (org.xml.sax.SAXException)1