Search in sources :

Example 6 with POIFSFileSystem

use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.

the class HPBFFileHandler method handleFile.

@Override
public void handleFile(InputStream stream, String path) throws Exception {
    HPBFDocument pub = new HPBFDocument(new POIFSFileSystem(stream));
    assertNotNull(pub.getEscherDelayStm());
    assertNotNull(pub.getMainContents());
    assertNotNull(pub.getQuillContents());
    // writing is not yet implemented... handlePOIDocument(pub);
    pub.close();
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HPBFDocument(org.apache.poi.hpbf.HPBFDocument)

Example 7 with POIFSFileSystem

use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.

the class HPSFPropertiesOnlyDocument method write.

/**
     * Write out, with any properties changes, but nothing else
     */
public void write(File newFile) throws IOException {
    POIFSFileSystem fs = POIFSFileSystem.create(newFile);
    try {
        write(fs);
        fs.writeFilesystem();
    } finally {
        fs.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem)

Example 8 with POIFSFileSystem

use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.

the class EmbeddedExtractor method extract.

protected EmbeddedData extract(DirectoryNode dn) throws IOException {
    assert (canExtract(dn));
    ByteArrayOutputStream bos = new ByteArrayOutputStream(20000);
    POIFSFileSystem dest = new POIFSFileSystem();
    try {
        copyNodes(dn, dest.getRoot());
        // start with a reasonable big size
        dest.writeFilesystem(bos);
    } finally {
        dest.close();
    }
    return new EmbeddedData(dn.getName(), bos.toByteArray(), CONTENT_TYPE_BYTES);
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 9 with POIFSFileSystem

use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.

the class EncryptionUtils method decrypt.

public static InputStream decrypt(final InputStream inputStream, final String pwd) throws Exception {
    try {
        POIFSFileSystem fs = new POIFSFileSystem(inputStream);
        EncryptionInfo info = new EncryptionInfo(fs);
        Decryptor d = Decryptor.getInstance(info);
        if (!d.verifyPassword(pwd)) {
            throw new RuntimeException("incorrect password");
        }
        return d.getDataStream(fs);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : Decryptor(org.apache.poi.poifs.crypt.Decryptor) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo)

Example 10 with POIFSFileSystem

use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.

the class HSLFSlideShowImpl method write.

/**
     * Writes out the slideshow file the is represented by an instance
     * of this class.
     * If you require all streams to be written out (eg Marcos, embeded
     * documents), then set <code>preserveNodes</code> set to <code>true</code>
     *
     * @param out           The OutputStream to write to.
     * @param preserveNodes Should all OLE2 streams be written back out, or only the common ones?
     * @throws IOException If there is an unexpected IOException from
     *                     the passed in OutputStream
     */
public void write(OutputStream out, boolean preserveNodes) throws IOException {
    // Get a new FileSystem to write into
    POIFSFileSystem outFS = new POIFSFileSystem();
    try {
        // Write into the new FileSystem
        write(outFS, preserveNodes);
        // Send the POIFSFileSystem object out to the underlying stream
        outFS.writeFilesystem(out);
    } finally {
        outFS.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem)

Aggregations

POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)121 Test (org.junit.Test)58 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)38 InputStream (java.io.InputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 FileInputStream (java.io.FileInputStream)31 File (java.io.File)25 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)15 FileOutputStream (java.io.FileOutputStream)14 OutputStream (java.io.OutputStream)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)13 TempFile (org.apache.poi.util.TempFile)13 IOException (java.io.IOException)12 MutablePropertySet (org.apache.poi.hpsf.MutablePropertySet)7 MutableSection (org.apache.poi.hpsf.MutableSection)7 HashMap (java.util.HashMap)6 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)6 NDocumentOutputStream (org.apache.poi.poifs.filesystem.NDocumentOutputStream)6