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
Modifier and TypeFieldDescriptionprivate static final int
private static final int
private static final org.slf4j.Logger
private static final ResourceBundle
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addMessageDigestHashToManifest
(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) static Map<Manifest,
MessageDigest> createManifestToMessageDigestMap
(Collection<SupportedAlgorithm> algorithms) private static String
formatMessageDigest
(MessageDigest messageDigest) static String
hash
(Path path, MessageDigest messageDigest) Create a HEX formatted string checksum hash of the filestatic void
hash
(Path path, Map<Manifest, MessageDigest> manifestToMessageDigestMap) Update the Manifests with the file's hash(package private) static void
updateMessageDigests
(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
- theMessageDigest
object 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 betweenManifest
andMessageDigest
- 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
- theSupportedAlgorithm
that you which to map toMessageDigest
- Returns:
- mapping between
Manifest
andMessageDigest
- Throws:
NoSuchAlgorithmException
- ifMessageDigest
doesn't support the algorithm
-