https://issues.apache.org/bugzilla/show_bug.cgi?id=53493
--- Comment #3 from Alex Geller <[email protected]> --- Yes, you are right but that is another issue (bug). There is nothing in the documentation that says that you can call (S)XSSFSheet.write() only once. To fix it, the statements flushRows(0) and _writer.close() in SXSSFSheet.getWorksheetXMLInputStream() should be done only if the sheet has not already been flushed to the disk so that the function should look something like this: public InputStream getWorksheetXMLInputStream() throws IOException { // flush all remaining data and close the temp file writer if not already done if(isModifiable()) { flushRows(0); _writer.close(); } return _writer.getWorksheetXMLInputStream(); } /** Is this sheet modifiable. Sheets created before a workbook is saved become immutable after saving*/ public boolean isModifiable() { return !_writer.isClosed(); } The method isModifiable() also documents another detail in the constraints in terms of "order of calls" that the streaming nature of SXSSF imposes over XSSF. Perhaps we should consider introducing an unchecked "StreamingConstraintException" when one violates the calling rules (e.g. if you try to add data to a closed sheet). However, I think that the general rule should be to avoid constraints when we have the choice between a constrained and a non constrained implementation of a public API method. In the case of SXSSFWorkbook.write() I see no reason why the number of calls should be restricted to calling it only once. I even suspect that that saving a workbook, adding sheets and saving again will work with the suggested fix. On the other hand, if you run into more difficult issues then it might not be worth it and we should document that you may call the function SXSSFWorkbook.write() only once. Regarding your correct observation that the current code already contains code to delete the temporary data file of a sheet, my question is, why that isn't sufficient for your problem? If you make sure that your application does not reference the SXSSFWorkbook after saving it then the temporary files should get deleted some tome after that when the garbage collector collects the sheets. If this doesn't happen than that is a bug. Apparently the general advice is not to use finalize() for temp file deletion but the arguments I have heard so far are not convincing. I will read up the relevant chapter in Effective Java and if it turns out to be an issue then I agree that we will have to remove the files explicitly. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
