use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestCurrentUserAtom method writeNormal.
@Test
public void writeNormal() throws Exception {
// Get raw contents from a known file
POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(normalFile));
DocumentEntry docProps = (DocumentEntry) fs.getRoot().getEntry("Current User");
byte[] contents = new byte[docProps.getSize()];
InputStream in = fs.getRoot().createDocumentInputStream("Current User");
in.read(contents);
in.close();
fs.close();
// Now build up a new one
CurrentUserAtom cu = new CurrentUserAtom();
cu.setLastEditUsername("Hogwarts");
cu.setCurrentEditOffset(0x2942);
// Check it matches
ByteArrayOutputStream baos = new ByteArrayOutputStream();
cu.writeOut(baos);
byte[] out = baos.toByteArray();
assertArrayEquals(contents, out);
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestExOleObjStg method testRead.
@Test
public void testRead() throws Exception {
ExOleObjStg record = new ExOleObjStg(data, 0, data.length);
assertEquals(RecordTypes.ExOleObjStg.typeID, record.getRecordType());
int len = record.getDataLength();
byte[] oledata = readAll(record.getData());
assertEquals(len, oledata.length);
POIFSFileSystem fs = new POIFSFileSystem(record.getData());
assertTrue("Constructed POIFS from ExOleObjStg data", true);
DocumentEntry doc = (DocumentEntry) fs.getRoot().getEntry("Contents");
assertNotNull(doc);
assertTrue("Fetched the Contents stream containing OLE properties", true);
fs.close();
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestWordExtractor method testBug51686.
/**
* [RESOLVED FIXED] Bug 51686 - Update to POI 3.8 beta 4 causes
* ConcurrentModificationException in Tika's OfficeParser
*/
@Test
public void testBug51686() throws IOException {
InputStream is = docTests.openResourceAsStream("Bug51686.doc");
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
String text = null;
for (Entry entry : fs.getRoot()) {
if ("WordDocument".equals(entry.getName())) {
WordExtractor ex = new WordExtractor(fs);
try {
text = ex.getText();
} finally {
ex.close();
}
}
}
assertNotNull(text);
fs.close();
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestWordExtractor method testExtractorFromWord6Extractor.
@Test
public void testExtractorFromWord6Extractor() throws Exception {
InputStream is = POIDataSamples.getHPSFInstance().openResourceAsStream("TestMickey.doc");
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
Word6Extractor wExt = new Word6Extractor(fs);
try {
POITextExtractor ext = wExt.getMetadataTextExtractor();
try {
// Now overall
String text = ext.getText();
assertContains(text, "TEMPLATE = Normal");
assertContains(text, "SUBJECT = sample subject");
assertContains(text, "MANAGER = sample manager");
assertContains(text, "COMPANY = sample company");
} finally {
ext.close();
}
} finally {
wExt.close();
fs.close();
}
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestWordExtractor method testExtractFromEmbeded.
/**
* Test that we can get data from two different embedded word documents
*/
@Test
public void testExtractFromEmbeded() throws IOException {
InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls");
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
// Should have WordDocument and 1Table
assertNotNull(dirA.getEntry("1Table"));
assertNotNull(dirA.getEntry("WordDocument"));
assertNotNull(dirB.getEntry("1Table"));
assertNotNull(dirB.getEntry("WordDocument"));
// Check each in turn
HWPFDocument docA = new HWPFDocument(dirA);
WordExtractor extractorA = new WordExtractor(docA);
assertNotNull(extractorA.getText());
assertTrue(extractorA.getText().length() > 20);
assertEqualsTrim("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractorA.getText());
assertEquals("Sample Doc 1", extractorA.getSummaryInformation().getTitle());
assertEquals("Sample Test", extractorA.getSummaryInformation().getSubject());
HWPFDocument docB = new HWPFDocument(dirB);
WordExtractor extractorB = new WordExtractor(docB);
assertNotNull(extractorB.getText());
assertTrue(extractorB.getText().length() > 20);
assertEqualsTrim("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", extractorB.getText());
assertEquals("Sample Doc 2", extractorB.getSummaryInformation().getTitle());
assertEquals("Another Sample Test", extractorB.getSummaryInformation().getSubject());
extractorA.close();
docA.close();
extractorB.close();
docB.close();
fs.close();
}
Aggregations