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

public final Class ImageReader

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
jdk.internal.jimage.ImageLocation.LocationType, java.io.IOException, java.nio.ByteBuffer, .ByteOrder, .IntBuffer, java.nio.file.Files, .Path, java.nio.file.attribute.BasicFileAttributes, java.util.ArrayList, .Arrays, .Collections, .Comparator, .HashMap, .HashSet, .List, .Map, .Objects, .Set, .TreeMap, java.util.function.Function, .Supplier, java.util.stream.Stream

A view over the entries of a jimage file with a unified namespace suitable for file system use. The jimage entries (resources, module and package information) are mapped into a unified hierarchy of named nodes, which serve as the underlying structure for JrtFileSystem and other utilities.

Entries in jimage are expressed as one of three Node types; resource nodes, directory nodes and link nodes.

When remapping jimage entries, jimage location names (e.g. "/java.base/java/lang/Integer.class") are prefixed with "/modules" to form the names of resource nodes. This aligns with the naming of module entries in jimage (e.g. "/modules/java.base/java/lang"), which appear as directory nodes in ImageReader.

Package entries (e.g. "/packages/java.lang" appear as directory nodes containing link nodes, which resolve back to the root directory of the module in which that package exists (e.g. "/modules/java.base"). Unlike other nodes, the jimage file does not contain explicit entries for link nodes, and their existence is derived only from the contents of the parent directory.

While similar to BasicImageReader, this class is not a conceptual subtype of it, and deliberately hides types such as ImageLocation to give a focused API based only on nodes.

Implementation Note

This class needs to maintain JDK 8 source compatibility. It is used internally in the JDK to implement jimage/jrtfs access, but also compiled and delivered as part of the jrtfs.jar to support access to the jimage file provided by the shipped JDK by tools running on JDK 8.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ImageReader.Directory

Directory node (referenced from a full path, without a trailing '/').

private static class
ImageReader.LinkNode

Link node (a symbolic link to a top-level modules directory).

public abstract static class
ImageReader.Node

A directory, resource or symbolic link.

private static class
ImageReader.Resource

Resource node (e.g. a ".class" entry, or any other data resource).

private static class

Field Summary

Modifier and TypeField and Description
private volatile boolean
private static final String
private final ImageReader.SharedImageReader

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public boolean
containsResource(String
The module name of the resource being tested for.
moduleName
,
String
Trailing module-relative resource path, not starting with '/'.
resourcePath
)

Returns whether a resource exists in the given module.

private void
public ImageReader.Node

Returns:

a node representing a resource, directory or symbolic link.
findNode
(String
a node name of the form "/modules/<module>/... or "/packages/<package>/....
name
)

Finds the node with the given name.

public ImageReader.Node
findResourceNode(String
The module name of the requested resource.
moduleName
,
String
Trailing module-relative resource path, not starting with '/'.
resourcePath
)

Returns a resource node in the given module, or null if no resource of that name exists.

public byte[]
getResource(ImageReader.Node node)

Returns a copy of the content of a resource node.

public ByteBuffer
getResourceBuffer(ImageReader.Node node)

Returns the content of a resource node in a newly allocated byte buffer.

pack-priv ResourceEntries
public static ImageReader
open(Path
file system path of the jimage file.
imagePath
,
PreviewMode
whether to return preview resources.
mode
)

Opens an image reader for a jimage file at the specified path.

public static ImageReader
open(Path
file system path of the jimage file.
imagePath
,
ByteOrder
the byte-order to be used when reading the jimage file.
byteOrder
,
PreviewMode
controls whether preview resources are visible.
mode
)

Opens an image reader for a jimage file at the specified path.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait