Class BigFileHashHandler
java.lang.Object
lib.pwss.hash.file_hash_handler.BigFileHashHandler
- All Implemented Interfaces:
FileHash
This class is designed to handle large files whose sizes exceed the available
memory in the Java Heap.
It provides an efficient way to calculate file hashes for very large files
without consuming excessive
heap memory. This implementation is particularly useful when working with
large datasets that cannot
be loaded entirely into memory at once.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringPrefix for BLAKE2b hash output.protected final intDigest size for BLAKE2b algorithm in bytes.protected final StringError string constant.protected final StringPrefix for SHA-256 hash output.protected final StringPrefix for SHA3 hash output. -
Constructor Summary
ConstructorsConstructorDescriptionBigFileHashHandler(long userDefinedMaxLimit) Constructor for BigFileHashHandler. -
Method Summary
Modifier and TypeMethodDescriptionprotected final StringbytesToHex(byte[] bytes) Convert a byte sequence to its hexadecimal string representation.final StringcalculateBlake2bHash(File file) Calculates the BLAKE2b hash of a given file, taking into account any size limits.final StringcalculateSha256Hash(File file) Calculates the SHA-256 hash of a given file, taking into account any size limits.final StringcalculateSha3Hash(File file) Calculates the SHA-3 hash of a given file, taking into account any size limits.final HashForFilesOutputGetAllHashes(File file) Calculates hashes of three different algorithms (SHA2,SHA3, BLAKE_2B) of a filefinal longGets the user-defined maximum file size limit.final voidsetUserDefinedMaxLimit(long userDefinedMaxLimit) Sets the user-defined maximum file size limit.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface FileHash
GetAllHashes
-
Field Details
-
DIGEST_SIZE_BLAKE_2B
protected final int DIGEST_SIZE_BLAKE_2BDigest size for BLAKE2b algorithm in bytes.- See Also:
-
ERROR
-
SHA256_PRINT_PREFIX
-
SHA3_PRINT_PREFIX
-
BLAKE_2B_PRINT_PREFIX
-
-
Constructor Details
-
BigFileHashHandler
public BigFileHashHandler(long userDefinedMaxLimit) Constructor for BigFileHashHandler.- Parameters:
userDefinedMaxLimit- The maximum file size limit defined by the user. A value of -1L indicates no limit.
-
-
Method Details
-
calculateSha256Hash
Calculates the SHA-256 hash of a given file, taking into account any size limits.- Specified by:
calculateSha256Hashin interfaceFileHash- Parameters:
file- The file for which to calculate the hash.- Returns:
- A string representing the SHA-256 hash or an error message if the file is too large.
-
calculateSha3Hash
Calculates the SHA-3 hash of a given file, taking into account any size limits.- Specified by:
calculateSha3Hashin interfaceFileHash- Parameters:
file- The file for which to calculate the hash.- Returns:
- A string representing the SHA-3 hash or an error message if the file is too large.
-
calculateBlake2bHash
Calculates the BLAKE2b hash of a given file, taking into account any size limits.- Specified by:
calculateBlake2bHashin interfaceFileHash- Parameters:
file- The file for which to calculate the hash.- Returns:
- A string representing the BLAKE2b hash or an error message if the file is too large.
-
getUserDefinedMaxLimit
public final long getUserDefinedMaxLimit()Gets the user-defined maximum file size limit. This method returns the maximum file size that has been set by the user. The class uses this value to determine whether it will attempt to extract a hash from files of this size or not.- Returns:
- the user-defined maximum file size limit in bytes
-
setUserDefinedMaxLimit
public final void setUserDefinedMaxLimit(long userDefinedMaxLimit) Sets the user-defined maximum file size limit. This method sets the maximum file size that the class will use to determine whether it should attempt to extract a hash from files of this size or not.- Parameters:
userDefinedMaxLimit- the new maximum file size limit in bytes
-
bytesToHex
Convert a byte sequence to its hexadecimal string representation. This function takes a bytes object and returns a string containing two hexadecimal digits for each byte in the input, using lowercase letters.- Parameters:
bytes- (bytes): The byte sequence to be converted to hexadecimal.- Returns:
- str: A string containing the hexadecimal representation of the bytes.
-
GetAllHashes
Calculates hashes of three different algorithms (SHA2,SHA3, BLAKE_2B) of a file- Parameters:
file- The file to extract hash from- Returns:
- A wrapper object containing the file and the three resulting hash strings
-