From ba76969968b5f9cad46ee607d5a1b1a60739d64c Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 15 Oct 2016 06:54:26 +0000 Subject: [PATCH] Close temp-file in test to not leak file-handles and fail deleting the file on Windows git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765019 13f79535-47bb-0310-9956-ffa450edef68 --- ...SXSSFWorkbookWithCustomZipEntrySource.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java index 31f29e2b7b..781b6df279 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java @@ -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()); } } - } -- 2.39.5