use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestHWPFWrite method testWriteNewFile.
/**
* Write to a new file
*/
@Test
public void testWriteNewFile() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
Range r = doc.getRange();
assertEquals("I am a test document\r", r.getParagraph(0).text());
File file = TempFile.createTempFile("TestDocument", ".doc");
doc.write(file);
doc.close();
// Check reading from File and Stream
doc = new HWPFDocument(new FileInputStream(file));
r = doc.getRange();
assertEquals("I am a test document\r", r.getParagraph(0).text());
doc.close();
doc = new HWPFDocument(new POIFSFileSystem(file));
r = doc.getRange();
assertEquals("I am a test document\r", r.getParagraph(0).text());
doc.close();
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestHPSFPropertiesExtractor method testNormalProperties.
public void testNormalProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
try {
// Check each bit in turn
String summary = ext.getSummaryInformationText();
String docsummary = ext.getDocumentSummaryInformationText();
assertContains(summary, "TEMPLATE = Normal");
assertContains(summary, "SUBJECT = sample subject");
assertContains(docsummary, "MANAGER = sample manager");
assertContains(docsummary, "COMPANY = sample company");
// 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();
}
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestHPSFPropertiesExtractor method test52258.
public void test52258() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestVisioWithCodepage.vsd"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
try {
assertNotNull(ext.getDocSummaryInformation());
assertNotNull(ext.getDocumentSummaryInformationText());
assertNotNull(ext.getSummaryInformation());
assertNotNull(ext.getSummaryInformationText());
assertNotNull(ext.getText());
} finally {
ext.close();
}
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestHPSFPropertiesExtractor method testConstructors.
public void testConstructors() throws IOException {
POIFSFileSystem fs;
HSSFWorkbook wb;
try {
fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
throw new RuntimeException(e);
}
ExcelExtractor excelExt = new ExcelExtractor(wb);
final String fsText;
HPSFPropertiesExtractor fsExt = new HPSFPropertiesExtractor(fs);
// Don't close re-used test resources!
fsExt.setFilesystem(null);
try {
fsText = fsExt.getText();
} finally {
fsExt.close();
}
final String hwText;
HPSFPropertiesExtractor hwExt = new HPSFPropertiesExtractor(wb);
// Don't close re-used test resources!
hwExt.setFilesystem(null);
try {
hwText = hwExt.getText();
} finally {
hwExt.close();
}
final String eeText;
HPSFPropertiesExtractor eeExt = new HPSFPropertiesExtractor(excelExt);
// Don't close re-used test resources!
eeExt.setFilesystem(null);
try {
eeText = eeExt.getText();
} finally {
eeExt.close();
wb.close();
}
assertEquals(fsText, hwText);
assertEquals(fsText, eeText);
assertContains(fsText, "AUTHOR = marshall");
assertContains(fsText, "TITLE = Titel: Äh");
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestAbortableListener method testAbortingBasics.
public void testAbortingBasics() throws Exception {
AbortableCountingListener l = new AbortableCountingListener(1000);
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(l);
HSSFEventFactory f = new HSSFEventFactory();
assertEquals(0, l.countSeen);
assertEquals(null, l.lastRecordSeen);
POIFSFileSystem fs = openSample();
short res = f.abortableProcessWorkbookEvents(req, fs);
assertEquals(0, res);
assertEquals(175, l.countSeen);
assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
}
Aggregations