Search in sources :

Example 56 with NPOIFSFileSystem

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

the class OutlookTextExtactor method main.

public static void main(String[] args) throws Exception {
    for (String filename : args) {
        NPOIFSFileSystem poifs = null;
        OutlookTextExtactor extractor = null;
        try {
            poifs = new NPOIFSFileSystem(new File(filename));
            extractor = new OutlookTextExtactor(poifs);
            System.out.println(extractor.getText());
        } finally {
            if (extractor != null)
                extractor.close();
            if (poifs != null)
                poifs.close();
        }
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) File(java.io.File)

Example 57 with NPOIFSFileSystem

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

the class TestBugs method bug51461.

/**
     * File with exactly 256 data blocks (+header block)
     *  shouldn't break on POIFS loading
     */
@SuppressWarnings("resource")
@Test
public void bug51461() throws Exception {
    byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls");
    HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
    HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
    assertEquals(2, wbPOIFS.getNumberOfSheets());
    assertEquals(2, wbNPOIFS.getNumberOfSheets());
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 58 with NPOIFSFileSystem

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

the class TestBugs method bug46904.

/**
     * java.io.IOException: block[ 0 ] already removed
     * (is an excel 95 file though)
     */
@Test
public void bug46904() throws Exception {
    try {
        OPOIFSFileSystem fs = new OPOIFSFileSystem(HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
        new HSSFWorkbook(fs.getRoot(), false).close();
        fail("Should catch exception here");
    } catch (OldExcelFormatException e) {
        assertTrue(e.getMessage().startsWith("The supplied spreadsheet seems to be Excel"));
    }
    try {
        NPOIFSFileSystem fs = new NPOIFSFileSystem(HSSFITestDataProvider.instance.openWorkbookStream("46904.xls"));
        try {
            new HSSFWorkbook(fs.getRoot(), false).close();
            fail("Should catch exception here");
        } finally {
            fs.close();
        }
    } catch (OldExcelFormatException e) {
        assertTrue(e.getMessage().startsWith("The supplied spreadsheet seems to be Excel"));
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) OldExcelFormatException(org.apache.poi.hssf.OldExcelFormatException) Test(org.junit.Test)

Example 59 with NPOIFSFileSystem

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

the class TestBugs method bug51535.

/**
     * Large row numbers and NPOIFS vs POIFS
     */
@SuppressWarnings("resource")
@Test
public void bug51535() throws Exception {
    byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51535.xls");
    HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
    HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
    for (HSSFWorkbook wb : new HSSFWorkbook[] { wbPOIFS, wbNPOIFS }) {
        assertEquals(3, wb.getNumberOfSheets());
        // Check directly
        HSSFSheet s = wb.getSheetAt(0);
        assertEquals("Top Left Cell", s.getRow(0).getCell(0).getStringCellValue());
        assertEquals("Top Right Cell", s.getRow(0).getCell(255).getStringCellValue());
        assertEquals("Bottom Left Cell", s.getRow(65535).getCell(0).getStringCellValue());
        assertEquals("Bottom Right Cell", s.getRow(65535).getCell(255).getStringCellValue());
        // Extract and check
        ExcelExtractor ex = new ExcelExtractor(wb);
        String text = ex.getText();
        assertContains(text, "Top Left Cell");
        assertContains(text, "Top Right Cell");
        assertContains(text, "Bottom Left Cell");
        assertContains(text, "Bottom Right Cell");
        ex.close();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ExcelExtractor(org.apache.poi.hssf.extractor.ExcelExtractor) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) Test(org.junit.Test)

Example 60 with NPOIFSFileSystem

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

the class HWPFDocument method write.

/**
     * Writes out the word file that is represented by an instance of this class.
     * 
     * If the {@link File} exists, it will be replaced, otherwise a new one 
     * will be created
     *
     * @param newFile The File to write to.
     * @throws IOException If there is an unexpected IOException from writing
     *         to the File.
     *         
     * @since 3.15 beta 3
     */
@Override
public void write(File newFile) throws IOException {
    NPOIFSFileSystem pfs = POIFSFileSystem.create(newFile);
    write(pfs, true);
    pfs.writeFilesystem();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem)

Aggregations

NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)101 Test (org.junit.Test)57 File (java.io.File)35 InputStream (java.io.InputStream)26 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 MAPIMessage (org.apache.poi.hsmf.MAPIMessage)14 FileOutputStream (java.io.FileOutputStream)12 TempFile (org.apache.poi.util.TempFile)12 FileInputStream (java.io.FileInputStream)11 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)10 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)10 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)9 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)9 IOException (java.io.IOException)8 OutputStream (java.io.OutputStream)8 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)7 TikaInputStream (org.apache.tika.io.TikaInputStream)6 AgileDecryptor (org.apache.poi.poifs.crypt.agile.AgileDecryptor)5 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)5