Search in sources :

Example 1 with HPSFPropertiesOnlyDocument

use of org.apache.poi.hpsf.HPSFPropertiesOnlyDocument in project poi by apache.

the class HPSFFileHandler method handleFile.

@Override
public void handleFile(InputStream stream, String path) throws Exception {
    Assume.assumeFalse(EXCLUDES_HANDLE_FILE.contains(path));
    POIFSFileSystem poifs = new POIFSFileSystem(stream);
    HPSFPropertiesOnlyDocument hpsf = new HPSFPropertiesOnlyDocument(poifs);
    DocumentSummaryInformation dsi = hpsf.getDocumentSummaryInformation();
    SummaryInformation si = hpsf.getSummaryInformation();
    boolean hasDSI = hasPropertyStream(poifs, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    boolean hasSI = hasPropertyStream(poifs, SummaryInformation.DEFAULT_STREAM_NAME);
    assertEquals(hasDSI, dsi != null);
    assertEquals(hasSI, si != null);
    handlePOIDocument(hpsf);
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) HPSFPropertiesOnlyDocument(org.apache.poi.hpsf.HPSFPropertiesOnlyDocument)

Example 2 with HPSFPropertiesOnlyDocument

use of org.apache.poi.hpsf.HPSFPropertiesOnlyDocument in project poi by apache.

the class TestPOIDocumentScratchpad method testWriteReadProperties.

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

Example 3 with HPSFPropertiesOnlyDocument

use of org.apache.poi.hpsf.HPSFPropertiesOnlyDocument 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 4 with HPSFPropertiesOnlyDocument

use of org.apache.poi.hpsf.HPSFPropertiesOnlyDocument in project poi by apache.

the class TestHPSFBugs method test54233.

/**
    * Some files seem to want the length and data to be on a 4-byte boundary,
    * and without that you'll hit an ArrayIndexOutOfBoundsException after
    * reading junk
    */
@Test
public void test54233() throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
    InputStream is = _samples.openResourceAsStream("TestNon4ByteBoundary.doc");
    NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
    is.close();
    SummaryInformation si = (SummaryInformation) PropertySetFactory.create(fs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
    DocumentSummaryInformation dsi = (DocumentSummaryInformation) PropertySetFactory.create(fs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    // Test
    assertEquals("Microsoft Word 10.0", si.getApplicationName());
    assertEquals("", si.getTitle());
    assertEquals("", si.getAuthor());
    assertEquals("Cour de Justice", dsi.getCompany());
    // Write out and read back, should still be valid
    POIDocument doc = new HPSFPropertiesOnlyDocument(fs);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doc.write(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    doc = new HPSFPropertiesOnlyDocument(new NPOIFSFileSystem(bais));
    // Check properties are still there
    assertEquals("Microsoft Word 10.0", si.getApplicationName());
    assertEquals("", si.getTitle());
    assertEquals("", si.getAuthor());
    assertEquals("Cour de Justice", dsi.getCompany());
    doc.close();
    fs.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) POIDocument(org.apache.poi.POIDocument) HPSFPropertiesOnlyDocument(org.apache.poi.hpsf.HPSFPropertiesOnlyDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

HPSFPropertiesOnlyDocument (org.apache.poi.hpsf.HPSFPropertiesOnlyDocument)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)3 Test (org.junit.Test)3 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)2 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)2 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)2 InputStream (java.io.InputStream)1 POIDocument (org.apache.poi.POIDocument)1 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)1