gpt4 book ai didi

java - SXSSF:在输出到文件之前,它会将不在窗口中的行刷新到哪里?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:44:04 24 4
gpt4 key购买 nike

根据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.

但是,在提供的示例中,刷新发生在工作簿被赋予写入文件的文件位置之前。

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();
}

所以这引出了问题:

  • 它在文件系统的什么地方存储数据?
  • 它只是在默认的临时目录中创建一个临时文件吗?
  • 这对所有/大多数实现是否安全?

最佳答案

执行缓冲的类是 org.apache.poi.xssf.streaming.SXSSFSheet 中的 SheetDataWriter

您可能感兴趣的魔法线是:

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

就安全而言,可能,但不确定...可能值得在 poi bugzilla 中打开一个错误,并请求将其切换为使用 org.apache.poi.util.TempFile 允许更多的控制。不过,一般来说,只要您为 java.io.tmpdir 指定一个有效的属性(或者默认值对您来说是合理的)就应该没问题

关于java - SXSSF:在输出到文件之前,它会将不在窗口中的行刷新到哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7417558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com