From: Yegor Kozlov Date: Mon, 7 Nov 2011 10:25:35 +0000 (+0000) Subject: Bugzilla 52062: ensure that temporary files in SXSSF are deleted X-Git-Tag: REL_3_8_BETA5~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8a841f238053e4b58b7776dfd468e9d6c163f11a;p=poi.git Bugzilla 52062: ensure that temporary files in SXSSF are deleted git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1198693 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 37acaacf3d..fce325aa74 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52062 - ensure that temporary files in SXSSF are deleted 50936 - Exception parsing MS Word 8.0 file (as duplicate of 47958) 47958 - ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during Escher tree walk 51944 - PAPFormattedDiskPage.getPAPX - IndexOutOfBounds diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index 8c1b998641..a0f30b8294 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -1284,7 +1284,7 @@ public class SXSSFSheet implements Sheet, Cloneable public SheetDataWriter() throws IOException { - _fd = File.createTempFile("poi-sxxsf-sheet", ".xml"); + _fd = File.createTempFile("poi-sxssf-sheet", ".xml"); _fd.deleteOnExit(); _out = new BufferedWriter(new FileWriter(_fd)); } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java index ab37fc9763..37394593a1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java @@ -186,30 +186,48 @@ public class SXSSFWorkbook implements Workbook private void injectData(File zipfile, OutputStream out) throws IOException { ZipFile zip = new ZipFile(zipfile); - - ZipOutputStream zos = new ZipOutputStream(out); - - @SuppressWarnings("unchecked") - Enumeration en = (Enumeration) zip.entries(); - while (en.hasMoreElements()) + try { - ZipEntry ze = en.nextElement(); - zos.putNextEntry(new ZipEntry(ze.getName())); - InputStream is = zip.getInputStream(ze); - XSSFSheet xSheet=getSheetFromZipEntryName(ze.getName()); - if(xSheet!=null) + ZipOutputStream zos = new ZipOutputStream(out); + try { - SXSSFSheet sxSheet=getSXSSFSheet(xSheet); - copyStreamAndInjectWorksheet(is,zos,sxSheet.getWorksheetXMLInputStream()); + @SuppressWarnings("unchecked") + Enumeration en = (Enumeration) zip.entries(); + while (en.hasMoreElements()) + { + ZipEntry ze = en.nextElement(); + zos.putNextEntry(new ZipEntry(ze.getName())); + InputStream is = zip.getInputStream(ze); + XSSFSheet xSheet=getSheetFromZipEntryName(ze.getName()); + if(xSheet!=null) + { + SXSSFSheet sxSheet=getSXSSFSheet(xSheet); + InputStream xis = sxSheet.getWorksheetXMLInputStream(); + try + { + copyStreamAndInjectWorksheet(is,zos,xis); + } + finally + { + xis.close(); + } + } + else + { + copyStream(is, zos); + } + is.close(); + } } - else + finally { - copyStream(is, zos); + zos.close(); } - is.close(); } - - zos.close(); + finally + { + zip.close(); + } } private static void copyStream(InputStream in, OutputStream out) throws IOException { byte[] chunk = new byte[1024]; @@ -649,7 +667,7 @@ public class SXSSFWorkbook implements Workbook } //Save the template - File tmplFile = File.createTempFile("poi-sxxsf-template", ".xlsx"); + File tmplFile = File.createTempFile("poi-sxssf-template", ".xlsx"); tmplFile.deleteOnExit(); FileOutputStream os = new FileOutputStream(tmplFile); _wb.write(os);