Class BigFileHashHandler

java.lang.Object
lib.pwss.hash.file_hash_handler.BigFileHashHandler
All Implemented Interfaces:
FileHash

public final class BigFileHashHandler extends Object implements 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 Details

  • 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

      public final String calculateSha256Hash(File file)
      Calculates the SHA-256 hash of a given file, taking into account any size limits.
      Specified by:
      calculateSha256Hash in interface FileHash
      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

      public final String calculateSha3Hash(File file)
      Calculates the SHA-3 hash of a given file, taking into account any size limits.
      Specified by:
      calculateSha3Hash in interface FileHash
      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

      public final String calculateBlake2bHash(File file)
      Calculates the BLAKE2b hash of a given file, taking into account any size limits.
      Specified by:
      calculateBlake2bHash in interface FileHash
      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

      protected final String bytesToHex(byte[] bytes)
      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

      public final HashForFilesOutput GetAllHashes(File file)
      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