Package one.x1f.sip.foundation.core.util
Class ChecksumHelper
java.lang.Object
one.x1f.sip.foundation.core.util.ChecksumHelper
Utility class for building Checksums
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LambdaHelper.ThrowingComparator<org.springframework.core.io.Resource>
Comparator forResource
s that usesURI
s for comparison. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
calcualteReproducibleHashForResources
(Collection<org.springframework.core.io.Resource> resources, String algorithm, Optional<Comparator<org.springframework.core.io.Resource>> comparator) Builds a reproducible hash over the givenresources
with the selected hashing-algorithm
.
-
Field Details
-
DEFAULT_RESOURCE_COMPARATOR
public static final LambdaHelper.ThrowingComparator<org.springframework.core.io.Resource> DEFAULT_RESOURCE_COMPARATORComparator forResource
s that usesURI
s 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 givenresources
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 codealgorithm
- 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
-