Author: centic
Date: Sat Oct 15 06:54:26 2016
New Revision: 1765019
URL: http://svn.apache.org/viewvc?rev=1765019&view=rev
Log:
Close temp-file in test to not leak file-handles and fail deleting the file on Windows
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java?rev=1765019&r1=1765018&r2=1765019&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
Sat Oct 15 06:54:26 2016
@@ -133,10 +133,15 @@ public final class TestSXSSFWorkbookWith
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 TestSXSSFWorkbookWith
}
}
-
static class SheetDataWriterWithDecorator extends SheetDataWriter {
final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
SecretKeySpec skeySpec;
@@ -206,7 +210,6 @@ public final class TestSXSSFWorkbookWith
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 TestSXSSFWorkbookWith
}
void dispose() {
- tempFile.delete();
+ assertTrue("Could not delete tempfile " + tempFile + ": " + tempFile.exists(),
+ !tempFile.exists() || tempFile.delete());
}
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org
|