开发者

SXSSF: to where does it flush rows not in the window prior to output to file?

开发者 https://www.devze.com 2023-04-05 07:51 出处:网络
According to the SXSSF (Streaming Usermodel API) documentation: SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheet

According to the SXSSF (Streaming Usermodel API) documentation:

SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.

However, in the provided example the flush happens before the workbook is given the file location at which to write the file.

public static void main(String[] args) throws Throwable {
    Workbook wb = new SXSSFWorkbook(100)开发者_如何学编程; // keep 100 rows in memory, exceeding rows will be flushed to disk
    Sheet sh = wb.createSheet();
    for(int rownum = 0; rownum < 1000; rownum++){
        Row row = sh.createRow(rownum);
        for(int cellnum = 0; cellnum < 10; cellnum++){
            Cell cell = row.createCell(cellnum);
            String address = new CellReference(cell).formatAsString();
            cell.setCellValue(address);
        }

    }

    // Rows with rownum < 900 are flushed and not accessible
    for(int rownum = 0; rownum < 900; rownum++){
      Assert.assertNull(sh.getRow(rownum));
    }

    // ther last 100 rows are still in memory
    for(int rownum = 900; rownum < 1000; rownum++){
        Assert.assertNotNull(sh.getRow(rownum));
    }

    FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx");
    wb.write(out);
    out.close();
}

So this begs the questions:

  • Where on the file system is it storing the data?
  • Is it just creating a temp file in the default temp directory?
  • Is this safe for all / most implementations?


The class that does the buffering is SheetDataWriter in org.apache.poi.xssf.streaming.SXSSFSheet

The magic line you're probably interested in is:

_fd = File.createTempFile("poi-sxxsf-sheet", ".xml");

In terms of is that safe, probably, but not certainly... It's likely worth opening a bug in the poi bugzilla, and requesting it be switched to using org.apache.poi.util.TempFile which allows a bit more control. In general though, as long as you specify a valid property for java.io.tmpdir (or the default is sensible for you) you should be fine

0

精彩评论

暂无评论...
验证码 换一张
取 消