APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.module

public final Class ModuleHashes

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .UncheckedIOException, java.lang.module.ModuleReader, .ModuleReference, java.nio.charset.StandardCharsets, java.security.MessageDigest, .NoSuchAlgorithmException, java.util.Arrays, .Collections, .HashMap, .Map, .Objects, .Set, .TreeMap, java.util.function.Supplier, java.util.stream.Stream

The result of hashing the contents of a number of module artifacts.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ModuleHashes.Builder

This is used by jdk.internal.module.SystemModules class generated at link time.

public static interface
ModuleHashes.HashSupplier

A supplier of a message digest.

Field Summary

Modifier and TypeField and Description
private final String
private final Map<String, byte[]>

Constructor Summary

AccessConstructor and Description
pack-priv
ModuleHashes(String
the algorithm used to create the hashes
algorithm
,
Map<String, byte[]>
the map of module name to hash value
nameToHash
)

Creates a ModuleHashes.

Method Summary

Modifier and TypeMethod and Description
public String
algorithm()

Returns the algorithm used to hash the modules ("SHA-256" for example).

private static byte[]

Returns:

the hash
computeHash
(ModuleReader
the module reader to access the module content
reader
,
String
the name of the message digest algorithm to use
algorithm
)

Computes a hash from the names and content of a module.

pack-priv static byte[]

Returns:

the hash
computeHash
(Supplier<ModuleReader>
supplies the module reader to access the module content
supplier
,
String
the name of the message digest algorithm to use
algorithm
)

Computes a hash from the names and content of a module.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv static ModuleHashes

Returns:

ModuleHashes that encapsulates the hashes
generate
(Set<ModuleReference>
the set of modules
mrefs
,
String
the name of the message digest algorithm to use
algorithm
)

Computes the hash from the names and content of a set of modules.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Map<String, byte[]>
hashes()

Returns unmodifiable map of module name to hash

public byte[]
hashFor(String mn)

Returns the hash for the given module name, null if there is no hash recorded for the module.

public Set<String>
names()

Returns the set of module names for which hashes are recorded.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

algorithmback to summary
private final String algorithm
nameToHashback to summary
private final Map<String, byte[]> nameToHash

Constructor Detail

ModuleHashesback to summary
pack-priv ModuleHashes(String algorithm, Map<String, byte[]> nameToHash)

Creates a ModuleHashes.

Parameters
algorithm:String

the algorithm used to create the hashes

nameToHash:Map<String, byte[]>

the map of module name to hash value

Method Detail

algorithmback to summary
public String algorithm()

Returns the algorithm used to hash the modules ("SHA-256" for example).

computeHashback to summary
private static byte[] computeHash(ModuleReader reader, String algorithm)

Computes a hash from the names and content of a module.

Parameters
reader:ModuleReader

the module reader to access the module content

algorithm:String

the name of the message digest algorithm to use

Returns:byte[]

the hash

Exceptions
IllegalArgumentException:
if digest algorithm is not supported
UncheckedIOException:
if an I/O error occurs
computeHashback to summary
pack-priv static byte[] computeHash(Supplier<ModuleReader> supplier, String algorithm)

Computes a hash from the names and content of a module.

Parameters
supplier:Supplier<ModuleReader>

supplies the module reader to access the module content

algorithm:String

the name of the message digest algorithm to use

Returns:byte[]

the hash

Exceptions
IllegalArgumentException:
if digest algorithm is not supported
UncheckedIOException:
if an I/O error occurs
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
generateback to summary
pack-priv static ModuleHashes generate(Set<ModuleReference> mrefs, String algorithm)

Computes the hash from the names and content of a set of modules. Returns a ModuleHashes to encapsulate the result.

Parameters
mrefs:Set<ModuleReference>

the set of modules

algorithm:String

the name of the message digest algorithm to use

Returns:ModuleHashes

ModuleHashes that encapsulates the hashes

Exceptions
IllegalArgumentException:
if digest algorithm is not supported
UncheckedIOException:
if an I/O error occurs
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hashesback to summary
public Map<String, byte[]> hashes()

Returns unmodifiable map of module name to hash

hashForback to summary
public byte[] hashFor(String mn)

Returns the hash for the given module name, null if there is no hash recorded for the module.

namesback to summary
public Set<String> names()

Returns the set of module names for which hashes are recorded.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
jdk.internal.module back to summary

public Class ModuleHashes.Builder

extends Object
Class Inheritance

This is used by jdk.internal.module.SystemModules class generated at link time.

Field Summary

Modifier and TypeField and Description
pack-priv final String
pack-priv final Map<String, byte[]>

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(String algorithm, int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
public ModuleHashes
build()

Builds a ModuleHashes.

public ModuleHashes.Builder
hashForModule(String mn, byte[] hash)

Sets the module hash for the given module name

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
pack-priv final String algorithm
nameToHashback to summary
pack-priv final Map<String, byte[]> nameToHash

Constructor Detail

Builderback to summary
pack-priv Builder(String algorithm, int initialCapacity)

Method Detail

buildback to summary
public ModuleHashes build()

Builds a ModuleHashes.

hashForModuleback to summary
public ModuleHashes.Builder hashForModule(String mn, byte[] hash)

Sets the module hash for the given module name

jdk.internal.module back to summary

public Interface ModuleHashes.HashSupplier


A supplier of a message digest.

Method Summary

Modifier and TypeMethod and Description
public byte[]
generate(String algorithm)

Method Detail

generateback to summary
public byte[] generate(String algorithm)