public final class ModuleReference extends Object
A module reference contains the module's descriptor and its location, if
known. It also has the ability to create a ModuleReader
in order to
access the module's content, which may be inside the Java run-time system
itself or in an artifact such as a modular JAR file.
ModuleFinder
,
ModuleReader
Constructor | Description |
---|---|
ModuleReference(ModuleDescriptor descriptor,
URI location,
Supplier<ModuleReader> readerSupplier) |
Constructs a new instance of this class.
|
Modifier and Type | Method | Description |
---|---|---|
ModuleDescriptor |
descriptor() |
Returns the module descriptor.
|
boolean |
equals(Object ob) |
Tests this module reference for equality with the given object.
|
int |
hashCode() |
Computes a hash code for this module reference.
|
Optional<URI> |
location() |
Returns the location of this module's content, if known.
|
ModuleReader |
open() |
Opens the module content for reading.
|
String |
toString() |
Returns a string describing this module reference.
|
public ModuleReference(ModuleDescriptor descriptor, URI location, Supplier<ModuleReader> readerSupplier)
The readSupplier
parameter is the supplier of the ModuleReader
that may be used to read the module content. Its get()
method throws UncheckedIOException
if an
I/O error occurs opening the module content. The get()
method
throws SecurityException
if opening the module is denied by the
security manager.
descriptor
- The module descriptorlocation
- The module location or null
if not knownreaderSupplier
- The Supplier
of the ModuleReader
public ModuleDescriptor descriptor()
public Optional<URI> location()
This URI, when present, is used as the location value of a CodeSource
so that a module's classes can be
granted specific permissions when loaded by a SecureClassLoader
.
Optional
if not knownpublic ModuleReader open() throws IOException
This method opens the module content by invoking the get()
method of the readSupplier
specified at
construction time.
ModuleReader
to read the moduleIOException
- If an I/O error occursSecurityException
- If denied by the security managerpublic int hashCode()
The hash code is based upon the components of the reference, and
satisfies the general contract of the Object.hashCode
method.
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean equals(Object ob)
If the given object is not a ModuleReference
then this
method returns false
. Two module references are equal if their
module descriptors are equal, their locations are equal or both unknown,
and were created with equal supplier objects to access the module
content.
This method satisfies the general contract of the Object.equals
method.
equals
in class Object
ob
- the object to which this object is to be comparedtrue
if, and only if, the given object is a module
reference that is equal to this module referenceObject.hashCode()
,
HashMap
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-Ubuntu+0-9b144-1ubuntu1