Search in sources :

Example 21 with NPOIFSFileSystem

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

the class TestOutlookTextExtractor method testConstructors.

@Test
public void testConstructors() throws Exception {
    FileInputStream fis = new FileInputStream(samples.getFile("simple_test_msg.msg"));
    OutlookTextExtactor ext = new OutlookTextExtactor(fis);
    String inp = ext.getText();
    ext.close();
    fis.close();
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
    ext = new OutlookTextExtactor(poifs);
    String poifsTxt = ext.getText();
    ext.close();
    poifs.close();
    fis = new FileInputStream(samples.getFile("simple_test_msg.msg"));
    ext = new OutlookTextExtactor(new MAPIMessage(fis));
    String mapi = ext.getText();
    ext.close();
    fis.close();
    assertEquals(inp, poifsTxt);
    assertEquals(inp, mapi);
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 22 with NPOIFSFileSystem

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

the class TestReadAllFiles method readCustomPropertiesFromFiles.

/**
     * <p>Tests the simplified custom properties by reading them from the
     * available test files.</p>
     *
     * @throws Throwable if anything goes wrong.
     */
@Test
public void readCustomPropertiesFromFiles() throws Exception {
    /* Read a test document <em>doc</em> into a POI filesystem. */
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(file);
    try {
        /*
             * If there is a document summry information stream, read it from
             * the POI filesystem, else create a new one.
             */
        DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
        if (dsi == null) {
            dsi = PropertySetFactory.newDocumentSummaryInformation();
        }
        final CustomProperties cps = dsi.getCustomProperties();
        if (cps == null) {
            /* The document does not have custom properties. */
            return;
        }
        for (CustomProperty cp : cps.properties()) {
            assertNotNull(cp.getName());
            assertNotNull(cp.getValue());
        }
    } finally {
        poifs.close();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) CustomProperty(org.apache.poi.hpsf.CustomProperty) CustomProperties(org.apache.poi.hpsf.CustomProperties) Test(org.junit.Test)

Example 23 with NPOIFSFileSystem

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

the class TestRVA method data.

@Parameters(name = "{1}")
public static Collection<Object[]> data() throws Exception {
    poifs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("testRVA.xls"), true);
    workbook = new HSSFWorkbook(poifs);
    sheet = workbook.getSheetAt(0);
    List<Object[]> data = new ArrayList<Object[]>();
    for (int rowIdx = 0; true; rowIdx++) {
        HSSFRow row = sheet.getRow(rowIdx);
        if (row == null) {
            break;
        }
        HSSFCell cell = row.getCell(0);
        if (cell == null || cell.getCellTypeEnum() == CellType.BLANK) {
            break;
        }
        String formula = cell.getCellFormula();
        data.add(new Object[] { cell, formula });
    }
    return data;
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) ArrayList(java.util.ArrayList) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Parameters(org.junit.runners.Parameterized.Parameters)

Example 24 with NPOIFSFileSystem

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

the class OldExcelExtractor method open.

private void open(InputStream biffStream) throws IOException {
    BufferedInputStream bis = (biffStream instanceof BufferedInputStream) ? (BufferedInputStream) biffStream : new BufferedInputStream(biffStream, 8);
    if (NPOIFSFileSystem.hasPOIFSHeader(bis)) {
        NPOIFSFileSystem poifs = new NPOIFSFileSystem(bis);
        try {
            open(poifs);
        } finally {
            poifs.close();
        }
    } else {
        ris = new RecordInputStream(bis);
        toClose = bis;
        prepare();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) BufferedInputStream(java.io.BufferedInputStream) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream)

Example 25 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.
     * 
     * For better performance when writing to files, use {@link #write(File)}.
     * If {@code stream} has a high cost/latency associated with each written byte,
     * consider wrapping the OutputStream in a {@link java.io.BufferedOutputStream}
     * to improve write performance.
     *
     * @param out The OutputStream to write to.
     * @throws IOException If there is an unexpected IOException from the passed
     *         in OutputStream.
     */
public void write(OutputStream out) throws IOException {
    NPOIFSFileSystem pfs = new NPOIFSFileSystem();
    write(pfs, true);
    pfs.writeFilesystem(out);
}
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