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