Search in sources :

Example 36 with POIFSFileSystem

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

the class TestHWPFWrite method testWriteNewFile.

/**
     * Write to a new file
     */
@Test
public void testWriteNewFile() throws IOException {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
    Range r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    File file = TempFile.createTempFile("TestDocument", ".doc");
    doc.write(file);
    doc.close();
    // Check reading from File and Stream
    doc = new HWPFDocument(new FileInputStream(file));
    r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    doc.close();
    doc = new HWPFDocument(new POIFSFileSystem(file));
    r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    doc.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) TempFile(org.apache.poi.util.TempFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 37 with POIFSFileSystem

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

the class TestHPSFPropertiesExtractor method testNormalProperties.

public void testNormalProperties() throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc"));
    HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
    try {
        // Check each bit in turn
        String summary = ext.getSummaryInformationText();
        String docsummary = ext.getDocumentSummaryInformationText();
        assertContains(summary, "TEMPLATE = Normal");
        assertContains(summary, "SUBJECT = sample subject");
        assertContains(docsummary, "MANAGER = sample manager");
        assertContains(docsummary, "COMPANY = sample company");
        // Now overall
        String text = ext.getText();
        assertContains(text, "TEMPLATE = Normal");
        assertContains(text, "SUBJECT = sample subject");
        assertContains(text, "MANAGER = sample manager");
        assertContains(text, "COMPANY = sample company");
    } finally {
        ext.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem)

Example 38 with POIFSFileSystem

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

the class TestHPSFPropertiesExtractor method test52258.

public void test52258() throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestVisioWithCodepage.vsd"));
    HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
    try {
        assertNotNull(ext.getDocSummaryInformation());
        assertNotNull(ext.getDocumentSummaryInformationText());
        assertNotNull(ext.getSummaryInformation());
        assertNotNull(ext.getSummaryInformationText());
        assertNotNull(ext.getText());
    } finally {
        ext.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem)

Example 39 with POIFSFileSystem

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

the class TestHPSFPropertiesExtractor method testConstructors.

public void testConstructors() throws IOException {
    POIFSFileSystem fs;
    HSSFWorkbook wb;
    try {
        fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
        wb = new HSSFWorkbook(fs);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ExcelExtractor excelExt = new ExcelExtractor(wb);
    final String fsText;
    HPSFPropertiesExtractor fsExt = new HPSFPropertiesExtractor(fs);
    // Don't close re-used test resources!
    fsExt.setFilesystem(null);
    try {
        fsText = fsExt.getText();
    } finally {
        fsExt.close();
    }
    final String hwText;
    HPSFPropertiesExtractor hwExt = new HPSFPropertiesExtractor(wb);
    // Don't close re-used test resources!
    hwExt.setFilesystem(null);
    try {
        hwText = hwExt.getText();
    } finally {
        hwExt.close();
    }
    final String eeText;
    HPSFPropertiesExtractor eeExt = new HPSFPropertiesExtractor(excelExt);
    // Don't close re-used test resources!
    eeExt.setFilesystem(null);
    try {
        eeText = eeExt.getText();
    } finally {
        eeExt.close();
        wb.close();
    }
    assertEquals(fsText, hwText);
    assertEquals(fsText, eeText);
    assertContains(fsText, "AUTHOR = marshall");
    assertContains(fsText, "TITLE = Titel: Äh");
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) ExcelExtractor(org.apache.poi.hssf.extractor.ExcelExtractor) IOException(java.io.IOException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 40 with POIFSFileSystem

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

the class TestAbortableListener method testAbortingBasics.

public void testAbortingBasics() throws Exception {
    AbortableCountingListener l = new AbortableCountingListener(1000);
    HSSFRequest req = new HSSFRequest();
    req.addListenerForAllRecords(l);
    HSSFEventFactory f = new HSSFEventFactory();
    assertEquals(0, l.countSeen);
    assertEquals(null, l.lastRecordSeen);
    POIFSFileSystem fs = openSample();
    short res = f.abortableProcessWorkbookEvents(req, fs);
    assertEquals(0, res);
    assertEquals(175, l.countSeen);
    assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest)

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