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());
}
}
}
-
static class SheetDataWriterWithDecorator extends SheetDataWriter {
final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
SecretKeySpec skeySpec;
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
}
void dispose() {
- tempFile.delete();
+ assertTrue("Could not delete tempfile " + tempFile + ": " + tempFile.exists(),
+ !tempFile.exists() || tempFile.delete());
}
}
-
}