org.apache.poi.poifs.filesystem.DocumentFactoryHelper Java Examples

The following examples show how to use org.apache.poi.poifs.filesystem.DocumentFactoryHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XSSFUnmarshaller.java    From poiji with MIT License 5 votes vote down vote up
<T> void listOfEncryptedItems(Class<T> type, Consumer<? super T> consumer, POIFSFileSystem fs) throws IOException {
    InputStream stream = DocumentFactoryHelper.getDecryptedStream(fs, options.getPassword());

    try (OPCPackage open = OPCPackage.open(stream)) {
        unmarshal0(type, consumer, open);

    } catch (ParserConfigurationException | SAXException | IOException | OpenXML4JException e) {
        IOUtils.closeQuietly(fs);
        throw new PoijiException("Problem occurred while reading data", e);
    }
}
 
Example #2
Source File: SlideShowFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a SlideShow from the given NPOIFSFileSystem, which may
 * be password protected
 *
 * @param fs The {@link NPOIFSFileSystem} to read the document from
 * @param password The password that should be used or null if no password is necessary.
 *
 * @return The created SlideShow
 *
 * @throws IOException if an error occurs while reading the data
 */
public static SlideShow<?,?> create(final NPOIFSFileSystem fs, String password) throws IOException {
    DirectoryNode root = fs.getRoot();

    // Encrypted OOXML files go inside OLE2 containers, is this one?
    if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
        InputStream stream = null;
        try {
            stream = DocumentFactoryHelper.getDecryptedStream(fs, password);

            return createXSLFSlideShow(stream);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }

    // If we get here, it isn't an encrypted PPTX file
    // So, treat it as a regular HSLF PPT one
    boolean passwordSet = false;
    if (password != null) {
        Biff8EncryptionKey.setCurrentUserPassword(password);
        passwordSet = true;
    }
    try {
        return createHSLFSlideShow(fs);
    } finally {
        if (passwordSet) {
            Biff8EncryptionKey.setCurrentUserPassword(null);
        }
    }
}
 
Example #3
Source File: ExcelReader.java    From zstack with Apache License 2.0 4 votes vote down vote up
public static boolean checkType(String base64Content) throws IOException {
    byte[] decoded = Base64.getDecoder().decode(base64Content);
    InputStream inp = new ByteArrayInputStream(decoded);
     return NPOIFSFileSystem.hasPOIFSHeader(IOUtils.peekFirst8Bytes(inp)) || DocumentFactoryHelper.hasOOXMLHeader(inp);
}