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();
}
Aggregations