@@ -822,7 +822,9 @@ private Optional<MetadataBLOB> refreshBlobInternal(
822
822
823
823
log .debug ("Writing new BLOB to cache..." );
824
824
if (blobCacheFile != null ) {
825
- new FileOutputStream (blobCacheFile ).write (downloadedBytes .getBytes ());
825
+ try (FileOutputStream f = new FileOutputStream (blobCacheFile )) {
826
+ f .write (downloadedBytes .getBytes ());
827
+ }
826
828
}
827
829
828
830
if (blobCacheConsumer != null ) {
@@ -886,7 +888,9 @@ private X509Certificate retrieveTrustRootCert()
886
888
cert .checkValidity (Date .from (clock .instant ()));
887
889
888
890
if (trustRootCacheFile != null ) {
889
- new FileOutputStream (trustRootCacheFile ).write (downloaded .getBytes ());
891
+ try (FileOutputStream f = new FileOutputStream (trustRootCacheFile )) {
892
+ f .write (downloaded .getBytes ());
893
+ }
890
894
}
891
895
892
896
if (trustRootCacheConsumer != null ) {
@@ -955,8 +959,8 @@ private Optional<MetadataBLOB> loadCachedBlobOnly(X509Certificate trustRootCerti
955
959
956
960
private Optional <ByteArray > readCacheFile (File cacheFile ) throws IOException {
957
961
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 ));
960
964
} catch (FileNotFoundException e ) {
961
965
throw new RuntimeException (
962
966
"This exception should be impossible, please file a bug report." , e );
0 commit comments