// write using streaming writer
{
ExcelDataContext dc = new ExcelDataContext(file);
ExcelUpdateCallback callback = new ExcelUpdateCallback(dc);
SXSSFSheet sheet = (SXSSFSheet) callback.createSheet("foobar");
Field windowSizeField = SXSSFSheet.class
.getDeclaredField("_randomAccessWindowSize");
windowSizeField.setAccessible(true);
int windowSize = windowSizeField.getInt(sheet);
assertEquals(1000, windowSize);
Field rowsField = SXSSFSheet.class.getDeclaredField("_rows");
rowsField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<Integer, SXSSFRow> rows = (Map<Integer, SXSSFRow>) rowsField
.get(sheet);
assertEquals(0, rows.size());
// create 5x the amound of rows as the streaming sheet will hold in
// memory
for (int i = 0; i < windowSize * 5; i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell(0);
cell.setCellValue("value" + i);
assertTrue(rows.size() <= 1000);
}
assertEquals(1000, rows.size());
ExcelUtils.writeWorkbook(dc, sheet.getWorkbook());
}
assertTrue("Usually the file size will be circa 42000, but it was: "
+ file.length(), file.length() > 40000 && file.length() < 45000);