Module java.base
Package java.lang.module

Interface ModuleReader

All Superinterfaces:
AutoCloseable,Closeable

public interfaceModuleReaderextendsCloseable
Provides access to the content of a module.

A module reader is intended for cases where access to the resources in a module is required, regardless of whether the module has been loaded. A framework that scans a collection of packaged modules on the file system, for example, may use a module reader to access a specific resource in each module. A module reader is also intended to be used byClassLoader implementations that load classes and resources from modules.

A resource in a module is identified by an abstract name that is a '/'-separated path string. For example, modulejava.base may have a resource "java/lang/Object.class" that, by convention, is the class file forjava.lang.Object. A module reader may treat directories in the module content as resources (whether it does or not is module reader specific). Where the module content contains a directory that can be located as a resource then its name ends with a slash ('/'). The directory can also be located with a name that drops the trailing slash.

AModuleReader isopen upon creation and is closed by invoking theclose method. Failure to close a module reader may result in a resource leak. The try-with-resources statement provides a useful construct to ensure that module readers are closed.

AModuleReader implementation may require permissions to access resources in the module. Consequently thefind,open,read, andlist methods may throw SecurityException if access is denied by the security manager.

Implementation Requirements:
Implementations ofModuleReader should take great care when translating an abstract resource name to the location of a resource in a packaged module or on the file system. Implementations are advised to treat resource names with elements such as '., '..', elements containing file separators, or empty elements as "not found". More generally, if the resource name is not in the stream of elements that thelist method returns then the resource should be treated as "not found" to avoid inconsistencies.
Since:
9
See Also: