diff --git a/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java b/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java index a8ca9a91..1200fd00 100644 --- a/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java +++ b/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java @@ -1443,7 +1443,7 @@ protected Map writeToTmpFileAndGenerateChecksums( } // Calculate hex digests - try { + try (dataStream) { byte[] buffer = new byte[8192]; int bytesRead; while ((bytesRead = dataStream.read(buffer)) != -1) { @@ -1459,7 +1459,6 @@ protected Map writeToTmpFileAndGenerateChecksums( throw ioe; } finally { - dataStream.close(); os.flush(); os.close(); } diff --git a/src/main/java/org/dataone/hashstore/hashstoreconverter/FileHashStoreLinks.java b/src/main/java/org/dataone/hashstore/hashstoreconverter/FileHashStoreLinks.java index 6173ec5b..f04dd703 100644 --- a/src/main/java/org/dataone/hashstore/hashstoreconverter/FileHashStoreLinks.java +++ b/src/main/java/org/dataone/hashstore/hashstoreconverter/FileHashStoreLinks.java @@ -187,11 +187,11 @@ protected Map generateChecksums( } // Calculate hex digests - try { + try (dataStream) { byte[] buffer = new byte[8192]; int bytesRead; while ((bytesRead = dataStream.read(buffer)) != -1) { - forgi (MessageDigest digest : digestsToCalculate) { + for (MessageDigest digest : digestsToCalculate) { digest.update(buffer, 0, bytesRead); } } @@ -201,8 +201,6 @@ protected Map generateChecksums( logFileHashStoreLinks.error(errMsg); throw ioe; - } finally { - dataStream.close(); } // Create map of hash algorithms and corresponding hex digests