]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 52062: ensure that temporary files in SXSSF are deleted
authorYegor Kozlov <yegor@apache.org>
Mon, 7 Nov 2011 10:25:35 +0000 (10:25 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 7 Nov 2011 10:25:35 +0000 (10:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1198693 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java

index 37acaacf3d871060a0826de8869ddc768456bd11..fce325aa74b535ac572f14f5202a103d177d3f7b 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="fix">52062 - ensure that temporary files in SXSSF are deleted</action>
            <action dev="poi-developers" type="fix">50936 - Exception parsing MS Word 8.0 file (as duplicate of 47958)</action>
            <action dev="poi-developers" type="fix">47958 - ArrayIndexOutOfBoundsException from PicturesTable.getAllPictures() during Escher tree walk</action>
            <action dev="poi-developers" type="fix">51944 - PAPFormattedDiskPage.getPAPX - IndexOutOfBounds</action>
index 8c1b9986410ef79bc4a4aedb5240adb55f383f63..a0f30b82949334caab6c1544810d80c308e591f8 100644 (file)
@@ -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));
         }
index ab37fc976367da7f361772f6287addf06bd1107a..37394593a1cf42ce4afcc21feee71b263d4eab71 100644 (file)
@@ -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<ZipEntry> en = (Enumeration<ZipEntry>) 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<ZipEntry> en = (Enumeration<ZipEntry>) 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);