java SXSSF:在输出到文件之前,它将不在窗口中的行刷新到哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7417558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SXSSF: to where does it flush rows not in the window prior to output to file?
提问by John B
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.
SXSSF (package:
org.apache.poi.xssf.streaming
) 是XSSF的 API 兼容流扩展,可在必须生成非常大的电子表格且堆空间有限时使用。SXSSF 通过限制对滑动窗口内的行的访问来实现其低内存占用,而 XSSF 允许访问文档中的所有行。不再出现在窗口中的旧行将无法访问,因为它们被写入磁盘。
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?
- 它在文件系统的哪个位置存储数据?
- 它只是在默认临时目录中创建一个临时文件吗?
- 这对所有/大多数实现安全吗?
回答by Gagravarr
The class that does the buffering is SheetDataWriter
in org.apache.poi.xssf.streaming.SXSSFSheet
进行缓冲的类SheetDataWriter
在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
就安全而言,可能,但不确定......可能值得在 poi bugzilla 中打开一个错误,并要求将其切换为使用org.apache.poi.util.TempFile
,这允许更多的控制。但总的来说,只要您为java.io.tmpdir
(或默认值对您来说是合理的)指定了一个有效的属性,您就应该没问题