Search in sources :

Example 81 with POIFSFileSystem

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();
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) FileInputStream(java.io.FileInputStream)

Example 82 with POIFSFileSystem

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);
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 83 with POIFSFileSystem

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());
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest)

Example 84 with POIFSFileSystem

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);
    }
}
Also used : SheetRecordCollectingListener(org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener) InputStream(java.io.InputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) IOException(java.io.IOException)

Example 85 with POIFSFileSystem

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());
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) FeatHdrRecord(org.apache.poi.hssf.record.FeatHdrRecord) SelectionRecord(org.apache.poi.hssf.record.SelectionRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) DVALRecord(org.apache.poi.hssf.record.DVALRecord) DVRecord(org.apache.poi.hssf.record.DVRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord)

Aggregations

POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)121 Test (org.junit.Test)58 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)38 InputStream (java.io.InputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 FileInputStream (java.io.FileInputStream)31 File (java.io.File)25 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)15 FileOutputStream (java.io.FileOutputStream)14 OutputStream (java.io.OutputStream)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)13 TempFile (org.apache.poi.util.TempFile)13 IOException (java.io.IOException)12 MutablePropertySet (org.apache.poi.hpsf.MutablePropertySet)7 MutableSection (org.apache.poi.hpsf.MutableSection)7 HashMap (java.util.HashMap)6 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)6 NDocumentOutputStream (org.apache.poi.poifs.filesystem.NDocumentOutputStream)6