Class ChecksumUtil
java.lang.Object
com.dua3.gradle.jdkprovider.provision.ChecksumUtil
Utility class for calculating and verifying SHA-256 file checksums.
This class is final and cannot be instantiated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringComputes the SHA-256 checksum of the contents of the specified file and returns it as a hexadecimal string.static voidverifySha256(Path file, String expectedHex) Verifies that the SHA-256 checksum of the specified file matches the expected checksum.
-
Method Details
-
sha256Hex
Computes the SHA-256 checksum of the contents of the specified file and returns it as a hexadecimal string.- Parameters:
file- the path to the file whose SHA-256 checksum is to be computed- Returns:
- the SHA-256 checksum of the file as a hexadecimal string
- Throws:
IOException- if an I/O error occurs while reading the fileIllegalStateException- if the SHA-256 algorithm is not available
-
verifySha256
Verifies that the SHA-256 checksum of the specified file matches the expected checksum. If the expected checksum is null or blank, the method is a no-op and does not perform verification.- Parameters:
file- the path to the file whose checksum is to be verifiedexpectedHex- the expected SHA-256 checksum in hexadecimal format- Throws:
IOException- if an I/O error occurs while reading the file or if the checksum does not match
-