Class ChecksumUtil

java.lang.Object
com.dua3.gradle.jdkprovider.provision.ChecksumUtil

public final class ChecksumUtil extends Object
Utility class for calculating and verifying SHA-256 file checksums. This class is final and cannot be instantiated.
  • Method Details

    • sha256Hex

      public static String sha256Hex(Path file) throws IOException
      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 file
      IllegalStateException - if the SHA-256 algorithm is not available
    • verifySha256

      public static void verifySha256(Path file, String expectedHex) throws IOException
      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 verified
      expectedHex - 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