Search in sources :

Example 1 with ReadException

use of com.monitorjbl.xlsx.exceptions.ReadException 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);
        SharedStringsTable sst = reader.getSharedStringsTable();
        StylesTable styles = reader.getStylesTable();
        loadSheets(reader, sst, styles, builder.getRowCacheSize());
    } catch (IOException e) {
        throw new OpenException("Failed to open file", e);
    } catch (OpenXML4JException | XMLStreamException e) {
        throw new ReadException("Unable to read workbook", e);
    } catch (GeneralSecurityException e) {
        throw new ReadException("Unable to read workbook - Decryption failed", e);
    }
}
Also used : 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) ReadException(com.monitorjbl.xlsx.exceptions.ReadException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) SharedStringsTable(org.apache.poi.xssf.model.SharedStringsTable) 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)

Example 2 with ReadException

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

the class StreamingWorkbookReader method init.

public void init(InputStream is) {
    File f = null;
    try {
        f = writeInputStreamToFile(is, builder.getBufferSize());
        LOGGER.debug("Created temp file [{}", f.getAbsolutePath());
        init(f);
        tmp = f;
    } catch (IOException e) {
        throw new ReadException("Unable to read input stream", e);
    } catch (RuntimeException e) {
        FilesHelper.deleteQuietly(f);
        throw e;
    }
}
Also used : ReadException(com.monitorjbl.xlsx.exceptions.ReadException) IOException(java.io.IOException) File(java.io.File)

Aggregations

ReadException (com.monitorjbl.xlsx.exceptions.ReadException)2 IOException (java.io.IOException)2 OpenException (com.monitorjbl.xlsx.exceptions.OpenException)1 File (java.io.File)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 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)1 SharedStringsTable (org.apache.poi.xssf.model.SharedStringsTable)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1