Use try-with-resources.

This commit is contained in:
Gary Gregory 2020-11-23 10:43:21 -05:00 committed by Gary Gregory
parent bf1822c55e
commit 460abd7474
2 changed files with 2 additions and 11 deletions

View File

@ -283,14 +283,8 @@ class HttpByteArrayCacheEntrySerializerTestUtils {
static void saveEntryToFile(final HttpCacheEntrySerializer<byte[]> serializer, final HttpCacheStorageEntry httpCacheStorageEntry, final File outFile) throws Exception {
final byte[] bytes = serializer.serialize(httpCacheStorageEntry);
OutputStream out = null;
try {
out = new FileOutputStream(outFile);
try (OutputStream out = new FileOutputStream(outFile)) {
out.write(bytes);
} finally {
if (out != null) {
out.close();
}
}
}

View File

@ -240,11 +240,8 @@ public class TestByteArrayCacheEntrySerializer {
private byte[] serializeProhibitedObject() throws IOException {
final BigDecimal bigDecimal = new BigDecimal("1000.00");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
try {
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(bigDecimal);
} finally {
oos.close();
}
return baos.toByteArray();
}