Search in sources :

Example 6 with OPOIFSFileSystem

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

the class TestPOIDocumentMain method WriteReadProperties.

@Test
public void WriteReadProperties() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Write them out
    NPOIFSFileSystem outFS = new NPOIFSFileSystem();
    doc.readProperties();
    doc.writeProperties(outFS);
    outFS.writeFilesystem(baos);
    // Create a new version
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    OPOIFSFileSystem inFS = new OPOIFSFileSystem(bais);
    // Check they're still there
    POIDocument doc3 = new HPSFPropertiesOnlyDocument(inFS);
    doc3.readProperties();
    // Delegate test
    readPropertiesHelper(doc3);
    doc3.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) HPSFPropertiesOnlyDocument(org.apache.poi.hpsf.HPSFPropertiesOnlyDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) Test(org.junit.Test)

Example 7 with OPOIFSFileSystem

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

the class TestExtractor method testDifferentPOIFS.

/**
     * Tests that we can work with both {@link POIFSFileSystem}
     * and {@link NPOIFSFileSystem}
     */
@SuppressWarnings("resource")
@Test
public void testDifferentPOIFS() throws IOException {
    // Open the two filesystems
    File pptFile = slTests.getFile("basic_test_ppt_file.ppt");
    InputStream is1 = new FileInputStream(pptFile);
    OPOIFSFileSystem opoifs = new OPOIFSFileSystem(is1);
    is1.close();
    NPOIFSFileSystem npoifs = new NPOIFSFileSystem(pptFile);
    DirectoryNode[] files = { opoifs.getRoot(), npoifs.getRoot() };
    // Open directly
    for (DirectoryNode dir : files) {
        PowerPointExtractor extractor = new PowerPointExtractor(dir);
        assertEquals(expectText, extractor.getText());
    }
    // Open via a HSLFSlideShow
    for (DirectoryNode dir : files) {
        HSLFSlideShowImpl slideshow = new HSLFSlideShowImpl(dir);
        PowerPointExtractor extractor = new PowerPointExtractor(slideshow);
        assertEquals(expectText, extractor.getText());
        extractor.close();
        slideshow.close();
    }
    npoifs.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) File(java.io.File) FileInputStream(java.io.FileInputStream) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Aggregations

OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)7 Test (org.junit.Test)7 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)5 FileInputStream (java.io.FileInputStream)3 File (java.io.File)2 InputStream (java.io.InputStream)2 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 VisioTextExtractor (org.apache.poi.hdgf.extractor.VisioTextExtractor)1 PublisherTextExtractor (org.apache.poi.hpbf.extractor.PublisherTextExtractor)1 HPSFPropertiesOnlyDocument (org.apache.poi.hpsf.HPSFPropertiesOnlyDocument)1 PowerPointExtractor (org.apache.poi.hslf.extractor.PowerPointExtractor)1 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)1 OutlookTextExtactor (org.apache.poi.hsmf.extractor.OutlookTextExtactor)1 OldExcelFormatException (org.apache.poi.hssf.OldExcelFormatException)1 EventBasedExcelExtractor (org.apache.poi.hssf.extractor.EventBasedExcelExtractor)1 ExcelExtractor (org.apache.poi.hssf.extractor.ExcelExtractor)1