Skip to content

Commit 5e75688

Browse files
committed
Use try-with-resources in FidoMetadataDownloader
1 parent 0b2baba commit 5e75688

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

webauthn-server-attestation/src/main/java/com/yubico/fido/metadata/FidoMetadataDownloader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,9 @@ private Optional<MetadataBLOB> refreshBlobInternal(
822822

823823
log.debug("Writing new BLOB to cache...");
824824
if (blobCacheFile != null) {
825-
new FileOutputStream(blobCacheFile).write(downloadedBytes.getBytes());
825+
try (FileOutputStream f = new FileOutputStream(blobCacheFile)) {
826+
f.write(downloadedBytes.getBytes());
827+
}
826828
}
827829

828830
if (blobCacheConsumer != null) {
@@ -886,7 +888,9 @@ private X509Certificate retrieveTrustRootCert()
886888
cert.checkValidity(Date.from(clock.instant()));
887889

888890
if (trustRootCacheFile != null) {
889-
new FileOutputStream(trustRootCacheFile).write(downloaded.getBytes());
891+
try (FileOutputStream f = new FileOutputStream(trustRootCacheFile)) {
892+
f.write(downloaded.getBytes());
893+
}
890894
}
891895

892896
if (trustRootCacheConsumer != null) {
@@ -955,8 +959,8 @@ private Optional<MetadataBLOB> loadCachedBlobOnly(X509Certificate trustRootCerti
955959

956960
private Optional<ByteArray> readCacheFile(File cacheFile) throws IOException {
957961
if (cacheFile.exists() && cacheFile.canRead() && cacheFile.isFile()) {
958-
try {
959-
return Optional.of(readAll(new FileInputStream(cacheFile)));
962+
try (FileInputStream f = new FileInputStream(cacheFile)) {
963+
return Optional.of(readAll(f));
960964
} catch (FileNotFoundException e) {
961965
throw new RuntimeException(
962966
"This exception should be impossible, please file a bug report.", e);

0 commit comments

Comments
 (0)