]> source.dussan.org Git - poi.git/commitdiff
Close temp-file in test to not leak file-handles and fail deleting the file on Windows
authorDominik Stadler <centic@apache.org>
Sat, 15 Oct 2016 06:54:26 +0000 (06:54 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 15 Oct 2016 06:54:26 +0000 (06:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765019 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java

index 31f29e2b7b18636c1492d3ef839539bb9c31152e..781b6df279bdd33a81a01ebb2d9a459dbd2c462b 100644 (file)
@@ -133,10 +133,15 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
         assertEquals(1, tempFiles.size());
         File tempFile = tempFiles.get(0);
         assertTrue("tempFile exists?", tempFile.exists());
-        byte[] data = IOUtils.toByteArray(new FileInputStream(tempFile));
-        String text = new String(data, UTF_8);
-        assertFalse(text.contains(sheetName));
-        assertFalse(text.contains(cellValue));
+        InputStream stream = new FileInputStream(tempFile);
+        try {
+            byte[] data = IOUtils.toByteArray(stream);
+            String text = new String(data, UTF_8);
+            assertFalse(text.contains(sheetName));
+            assertFalse(text.contains(cellValue));
+        } finally {
+            stream.close();
+        }
         workbook.dispose();
         assertFalse("tempFile deleted after dispose?", tempFile.exists());
     }
@@ -173,7 +178,6 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
         }
     }
     
-    
     static class SheetDataWriterWithDecorator extends SheetDataWriter {
         final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
         SecretKeySpec skeySpec;
@@ -206,7 +210,6 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
             Cipher ciDec = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.DECRYPT_MODE, "PKCS5Padding");
             return new CipherInputStream(fis, ciDec);
         }
-        
     }
     
     // a class to save and read an AES-encrypted workbook
@@ -237,8 +240,8 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
         }
         
         void dispose() {
-            tempFile.delete();
+            assertTrue("Could not delete tempfile " + tempFile + ": " + tempFile.exists(),
+                    !tempFile.exists() || tempFile.delete());
         }
     }
-    
 }