Record Class ModuleHash

java.lang.Object
java.lang.Record
com.netflix.module.ModuleHash
Record Components:
type - the kind of content represented by the hash
algorithm - the lowercase digest algorithm name
digest - the encoded digest

public record ModuleHash(ModuleHash.Type type, String algorithm, String digest) extends Record
Content identity of a resolved module or module patch.
  • Constructor Details

  • Method Details

    • parse

      public static ModuleHash parse(String value)
      Parses the type:algorithm:digest external form.
      Parameters:
      value - the external form
      Returns:
      the parsed hash
      Throws:
      IllegalArgumentException - if the value is not a valid module hash
    • moduleSha256

      public static ModuleHash moduleSha256(ModuleReference reference) throws IOException
      Computes a SHA-256 identity from the names and bytes of a module's resources using the ModuleHashes algorithm in JDK 15. Resource names are ordered, encoded as UTF-8, and followed directly by their content. Directory names participate in the hash, but are not opened so exploded modules can be hashed.
      Parameters:
      reference - the module to hash
      Returns:
      the module hash
      Throws:
      IOException - if the module or one of its resources cannot be read
    • patchSha256

      public static ModuleHash patchSha256(Path path) throws IOException
      Computes a SHA-256 identity for a patch archive or directory.
      Parameters:
      path - the patch archive or directory
      Returns:
      the patch hash
      Throws:
      IOException - if the path does not exist or cannot be read
    • read

      public static ModuleHash read(Path path) throws IOException
      Reads a hash in external form from a single-line file.
      Parameters:
      path - the file to read
      Returns:
      the parsed hash
      Throws:
      IOException - if the file cannot be read or does not contain one valid hash
    • write

      public void write(Path path) throws IOException
      Writes this hash in external form followed by a line terminator.
      Parameters:
      path - the destination file
      Throws:
      IOException - if the hash cannot be written
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public ModuleHash.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • algorithm

      public String algorithm()
      Returns the value of the algorithm record component.
      Returns:
      the value of the algorithm record component
    • digest

      public String digest()
      Returns the value of the digest record component.
      Returns:
      the value of the digest record component