use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class POIFSLister method viewFileOld.
public static void viewFileOld(final String filename, boolean withSizes) throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
displayDirectory(fs.getRoot(), "", withSizes);
fs.close();
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestWorkbookFactory method testCreateNative.
@Test
public void testCreateNative() throws Exception {
Workbook wb;
// POIFS -> hssf
wb = WorkbookFactory.create(new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)));
assertNotNull(wb);
assertTrue(wb instanceof HSSFWorkbook);
assertCloseDoesNotModifyFile(xls, wb);
// Package -> xssf
wb = WorkbookFactory.create(OPCPackage.open(HSSFTestDataSamples.openSampleFileStream(xlsx)));
assertNotNull(wb);
assertTrue(wb instanceof XSSFWorkbook);
assertCloseDoesNotModifyFile(xlsx, wb);
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestAbortableListener method testAbortStops.
public void testAbortStops() throws Exception {
AbortableCountingListener l = new AbortableCountingListener(1);
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(1234, res);
assertEquals(1, l.countSeen);
assertEquals(BOFRecord.sid, l.lastRecordSeen.getSid());
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestEventWorkbookBuilder method setUp.
@Override
public void setUp() {
HSSFRequest req = new HSSFRequest();
mockListen = new MockHSSFListener();
listener = new SheetRecordCollectingListener(mockListen);
req.addListenerForAllRecords(listener);
HSSFEventFactory factory = new HSSFEventFactory();
try {
InputStream is = HSSFTestDataSamples.openSampleFileStream("3dFormulas.xls");
POIFSFileSystem fs = new POIFSFileSystem(is);
factory.processWorkbookEvents(req, fs);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestHSSFEventFactory method testWithCrazyContinueRecords.
public void testWithCrazyContinueRecords() throws Exception {
// Some files have crazy ordering of their continue records
// Check that we don't break on them (bug #42844)
HSSFRequest req = new HSSFRequest();
MockHSSFListener mockListen = new MockHSSFListener();
req.addListenerForAllRecords(mockListen);
POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls"));
HSSFEventFactory factory = new HSSFEventFactory();
factory.processWorkbookEvents(req, fs);
Record[] recs = mockListen.getRecords();
// Check we got the records
assertTrue(recs.length > 100);
// And none of them are continue ones
for (Record rec : recs) {
assertFalse(rec instanceof ContinueRecord);
}
// Check that the last few records are as we expect
// (Makes sure we don't accidently skip the end ones)
int numRec = recs.length;
assertEquals(DVALRecord.class, recs[numRec - 4].getClass());
assertEquals(DVRecord.class, recs[numRec - 3].getClass());
assertEquals(FeatHdrRecord.class, recs[numRec - 2].getClass());
assertEquals(EOFRecord.class, recs[numRec - 1].getClass());
}
Aggregations