Skip to content

Commit

Permalink
Further optimize code to generate checksums by using try-resources on…
Browse files Browse the repository at this point in the history
… InputStream object
  • Loading branch information
doulikecookiedough committed Aug 19, 2024
1 parent dc6d84d commit 7f2b315
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ protected Map<String, String> writeToTmpFileAndGenerateChecksums(
}

// Calculate hex digests
try {
try (dataStream) {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = dataStream.read(buffer)) != -1) {
Expand All @@ -1459,7 +1459,6 @@ protected Map<String, String> writeToTmpFileAndGenerateChecksums(
throw ioe;

} finally {
dataStream.close();
os.flush();
os.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ protected Map<String, String> 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);
}
}
Expand All @@ -201,8 +201,6 @@ protected Map<String, String> generateChecksums(
logFileHashStoreLinks.error(errMsg);
throw ioe;

} finally {
dataStream.close();
}

// Create map of hash algorithms and corresponding hex digests
Expand Down

0 comments on commit 7f2b315

Please sign in to comment.