Class ChecksumHelper

java.lang.Object
one.x1f.sip.foundation.core.util.ChecksumHelper

public class ChecksumHelper extends Object
Utility class for building Checksums
  • Field Details

    • DEFAULT_RESOURCE_COMPARATOR

      public static final LambdaHelper.ThrowingComparator<org.springframework.core.io.Resource> DEFAULT_RESOURCE_COMPARATOR
      Comparator for Resources that uses URIs for comparison.
  • Constructor Details

    • ChecksumHelper

      public ChecksumHelper()
  • Method Details

    • calcualteReproducibleHashForResources

      public static String calcualteReproducibleHashForResources(Collection<org.springframework.core.io.Resource> resources, String algorithm, Optional<Comparator<org.springframework.core.io.Resource>> comparator) throws IOException
      Builds a reproducible hash over the given resources with the selected hashing- algorithm.

      To make the hashes reproducible, the given resources are sorted first using the given comparator before being fed into the hash digest. Therefore, two hashes on the same set of resources result only in the same, reproducible hash if the same algorithm and comparator is also used.

      Parameters:
      resources - Resources to use for creating the hash code
      algorithm - Algorith to use (see @MessageDigestAlgorithms)
      comparator - (Optional) comparator to use. If non is given, DEFAULT_RESOURCE_COMPARATOR is used
      Returns:
      Hash code
      Throws:
      IOException - Exception while reading the given resources