|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|
|
|
|
import java.security.DigestInputStream;
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.util.HexFormat;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Utility class used to calculate digests.
|
|
|
|
@ -41,11 +42,8 @@ final class Digest {
|
|
|
|
|
try {
|
|
|
|
|
try (DigestInputStream inputStream = new DigestInputStream(supplier.openStream(),
|
|
|
|
|
MessageDigest.getInstance("SHA-1"))) {
|
|
|
|
|
byte[] buffer = new byte[4098];
|
|
|
|
|
while (inputStream.read(buffer) != -1) {
|
|
|
|
|
// Read the entire stream
|
|
|
|
|
}
|
|
|
|
|
return bytesToHex(inputStream.getMessageDigest().digest());
|
|
|
|
|
inputStream.readAllBytes();
|
|
|
|
|
return HexFormat.of().formatHex(inputStream.getMessageDigest().digest());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (NoSuchAlgorithmException ex) {
|
|
|
|
@ -53,12 +51,4 @@ final class Digest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String bytesToHex(byte[] bytes) {
|
|
|
|
|
StringBuilder hex = new StringBuilder();
|
|
|
|
|
for (byte b : bytes) {
|
|
|
|
|
hex.append(String.format("%02x", b));
|
|
|
|
|
}
|
|
|
|
|
return hex.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|