Any idea? Is event api ready to use? I see little doc or discussions about it.
On Mon, Mar 5, 2012 at 8:27 AM, Warren Tang <[email protected]> wrote: > Hi, everybody > > I came across performance issue when reading large Excel97 files with > usermodel. When the file size is over 15MB, the HSSFWorkbook's constructor > never returns or returns with an OutOfMemoryError (GC overhead limit > exceeded). > > So I've been trying to use eventusermodel to reduce the memory footprint, > but I have problem to pertain the value of the modified fields. Below is > the code. I need the modified value of an instance field (modifyMe); but > the value is always 0 rather than 100 which is what I want. > > > ----------------------------- HssfEventApiTest.java > ---------------------------------------- > import static org.junit.Assert.*; > import java.io.IOException; > import java.io.InputStream; > import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; > import org.apache.poi.hssf.eventusermodel.HSSFListener; > import org.apache.poi.hssf.eventusermodel.HSSFRequest; > import org.apache.poi.hssf.record.EOFRecord; > import org.apache.poi.hssf.record.Record; > import org.apache.poi.poifs.filesystem.POIFSFileSystem; > import org.junit.Test; > import com.tangcs.zhc.server.ServerTestBase; > > public class HssfEventApiTest extends ServerTestBase > implements HSSFListener > { > int modifyMe; // The instance field to be modified by the listener > > public void processRecord(Record record) > { > switch (record.getSid()) > { > case EOFRecord.sid: > modifyMe = 100; //Modified here. > System.out.println("End of file."); > break; > } > } > > @Test public void testEventApi() throws IOException > { > InputStream fin = getResourceAsStream("xls/exam-results-min.xls"); > POIFSFileSystem poifs = new POIFSFileSystem(fin); > InputStream din = poifs.createDocumentInputStream("Workbook"); > HSSFRequest req = new HSSFRequest(); > req.addListenerForAllRecords(new HssfEventApiTest()); > HSSFEventFactory factory = new HSSFEventFactory(); > factory.processEvents(req, din); > fin.close(); > din.close(); > > System.out.println("modifyMe = " + modifyMe); > assertEquals(100, modifyMe); //Fails here with actual == 0; > // The stdout is: > // End of file. > // End of file. > // modifyMe = 0 > } > > } > > -- > Regards, > Warren Tang <http://blog.tangcs.com> > -- Regards, Warren Tang <http://blog.tangcs.com>
