Search in sources :

Example 1 with POIDocument

use of org.apache.poi.POIDocument 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

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