Class MD5

java.lang.Object
org.savantbuild.security.MD5

public final class MD5 extends Object
This class is a simple holder for a MD5 checksum. It holds the sum and the file name. It can also hold the MD5 sum bytes.
  • Field Details

    • bytes

      public final byte[] bytes
    • fileName

      public final String fileName
    • sum

      public final String sum
  • Constructor Details

    • MD5

      public MD5(String sum, byte[] bytes, String fileName)
  • Method Details

    • forBytes

      public static MD5 forBytes(byte[] bytes, String fileName) throws IOException
      Calculates the MD5 for the given bytes. This optionally takes a file name, which isn't required, but can be useful when calculating MD5s for files.
      Parameters:
      bytes - The bytes.
      fileName - (Optional) The file name.
      Returns:
      The MD5 and never null.
      Throws:
      IOException - If the MD5 fails for any reason.
    • forPath

      public static MD5 forPath(Path path) throws IOException
      Calculates the MD5 sum for the given Path.
      Parameters:
      path - The path to MD5.
      Returns:
      The MD5 sum and never null.
      Throws:
      IOException - If the file could not be MD5 summed.
    • load

      public static MD5 load(Path path) throws IOException
      Loads the MD5 file at the given Path. This doesn't calculate the MD5 for the given path. The given path must be an MD5 file.
      Parameters:
      path - The path to parse the MD5 sum from.
      Returns:
      The MD5.
      Throws:
      IOException - If the MD5 file is not a valid MD5 file or was unreadable.
    • writeMD5

      public static void writeMD5(MD5 md5, Path path) throws IOException
      Writes the MD5 information out to the given Path file.
      Parameters:
      md5 - The MD5.
      path - The path to write the MD5 to.
      Throws:
      IOException - If the write fails.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object