Search in sources :

Example 26 with POIFSFileSystem

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

the class POIFSFileHandler method handlePOIDocument.

protected void handlePOIDocument(POIDocument doc) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    doc.write(out);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    POIFSFileSystem fs = new POIFSFileSystem(in);
    handlePOIFSFileSystem(fs);
    fs.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 27 with POIFSFileSystem

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

the class POIFSFileHandler method handleFile.

@Override
public void handleFile(InputStream stream, String path) throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(stream);
    try {
        handlePOIFSFileSystem(fs);
        handleHPSFProperties(fs);
    } finally {
        fs.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem)

Example 28 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 29 with POIFSFileSystem

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

the class HWPFDocumentCore method verifyAndBuildPOIFS.

/**
   * Takes an InputStream, verifies that it's not RTF or PDF, builds a
   *  POIFSFileSystem from it, and returns that.
   */
public static POIFSFileSystem verifyAndBuildPOIFS(InputStream istream) throws IOException {
    // Open a PushbackInputStream, so we can peek at the first few bytes
    PushbackInputStream pis = new PushbackInputStream(istream, 6);
    byte[] first6 = IOUtils.toByteArray(pis, 6);
    // Does it start with {\rtf ? If so, it's really RTF
    if (first6[0] == '{' && first6[1] == '\\' && first6[2] == 'r' && first6[3] == 't' && first6[4] == 'f') {
        throw new IllegalArgumentException("The document is really a RTF file");
    } else if (first6[0] == '%' && first6[1] == 'P' && first6[2] == 'D' && first6[3] == 'F') {
        throw new IllegalArgumentException("The document is really a PDF file");
    }
    // OK, so it's neither RTF nor PDF
    // Open a POIFSFileSystem on the (pushed back) stream
    pis.unread(first6);
    return new POIFSFileSystem(pis);
}
Also used : PushbackInputStream(java.io.PushbackInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem)

Example 30 with POIFSFileSystem

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

the class TestCurrentUserAtom method readEnc.

@Test(expected = EncryptedPowerPointFileException.class)
public void readEnc() throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(encFile));
    try {
        new CurrentUserAtom(fs.getRoot());
        // not yet failed
        assertTrue(true);
        new HSLFSlideShowImpl(fs).close();
    } finally {
        fs.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

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