Package nl.knaw.dans.bagit.hash
Class Hasher
java.lang.Object
nl.knaw.dans.bagit.hash.Hasher
Convenience class for generating a HEX formatted string of the checksum hash.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final org.slf4j.Loggerprivate static final ResourceBundle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddMessageDigestHashToManifest(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) static Map<Manifest,MessageDigest> createManifestToMessageDigestMap(Collection<SupportedAlgorithm> algorithms) private static StringformatMessageDigest(MessageDigest messageDigest) static Stringhash(Path path, MessageDigest messageDigest) Create a HEX formatted string checksum hash of the filestatic voidhash(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) Update the Manifests with the file's hash(package private) static voidupdateMessageDigests(Path path, Collection<MessageDigest> messageDigests)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
_64_KB
private static final int _64_KB- See Also:
-
CHUNK_SIZE
private static final int CHUNK_SIZE- See Also:
-
messages
-
-
Constructor Details
-
Hasher
private Hasher()
-
-
Method Details
-
hash
Create a HEX formatted string checksum hash of the file- Parameters:
path- thePath(file) to hashmessageDigest- theMessageDigestobject representing the hashing algorithm- Returns:
- the hash as a hex formated string
- Throws:
IOException- if there is a problem reading the file
-
hash
public static void hash(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) throws IOExceptionUpdate the Manifests with the file's hash- Parameters:
path- thePath(file) to hashmanifestToMessageDigestMap- the map betweenManifestandMessageDigest- Throws:
IOException- if there is a problem reading the file
-
updateMessageDigests
static void updateMessageDigests(Path path, Collection<MessageDigest> messageDigests) throws IOException - Throws:
IOException
-
addMessageDigestHashToManifest
private static void addMessageDigestHashToManifest(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) -
formatMessageDigest
-
createManifestToMessageDigestMap
public static Map<Manifest,MessageDigest> createManifestToMessageDigestMap(Collection<SupportedAlgorithm> algorithms) throws NoSuchAlgorithmException - Parameters:
algorithms- theSupportedAlgorithmthat you which to map toMessageDigest- Returns:
- mapping between
ManifestandMessageDigest - Throws:
NoSuchAlgorithmException- ifMessageDigestdoesn't support the algorithm
-