JarFile class is used to read the contents of a jar file
from any file that can be opened with java.io.RandomAccessFile.
It extends the class java.util.zip.ZipFile with support
for reading an optional Manifest entry, and support for
processing multi-release jar files. The Manifest can be used
to specify meta-information about the jar file and its entries.
A multi-release jar file is a jar file that
contains a manifest with a main attribute named "Multi-Release",
a set of "base" entries, some of which are public classes with public
or protected methods that comprise the public interface of the jar file,
and a set of "versioned" entries contained in subdirectories of the
"META-INF/versions" directory. The versioned entries are partitioned by the
major version of the Java platform. A versioned entry, with a version
n, 8 < n, in the "META-INF/versions/{n}" directory overrides
the base entry as well as any entry with a version number i where
8 < i < n.
By default, a JarFile for a multi-release jar file is configured
to process the multi-release jar file as if it were a plain (unversioned) jar
file, and as such an entry name is associated with at most one base entry.
The JarFile may be configured to process a multi-release jar file by
creating the JarFile with the
JarFile#JarFile(File, boolean, int, Runtime. constructor. The
Runtime.Version object sets a maximum version used when searching for
versioned entries. When so configured, an entry name
can correspond with at most one base entry and zero or more versioned
entries. A search is required to associate the entry name with the latest
versioned entry whose version is less than or equal to the maximum version
(see getEntry(String)).
Class loaders that utilize JarFile to load classes from the
contents of JarFile entries should construct the JarFile
by invoking the JarFile#JarFile(File, boolean, int, Runtime.
constructor with the value Runtime.version() assigned to the last
argument. This assures that classes compatible with the major
version of the running JVM are loaded from multi-release jar files.
If the verify flag is on when opening a signed jar file, the content
of the jar entry is verified against the signature embedded inside the manifest
that is associated with its path name. For a
multi-release jar file, the content of a versioned entry is verified against
its own signature and JarEntry#getCodeSigners() returns its own signers.
Please note that the verification process does not include validating the
signer's certificate. A caller should inspect the return value of
JarEntry#getCodeSigners() to further determine if the signature
can be trusted.
Unless otherwise noted, passing a null argument to a constructor
or method in this class will cause a NullPointerException to be
thrown.
Implementation Note
JarFile (e.g. to override
the configuration of a compiled application or library), two System
properties are available.
jdk.util.jar.version can be assigned a value that is the
String representation of a non-negative integer
<= Runtime.version().feature(). The value is used to set the effective
runtime version to something other than the default value obtained by
evaluating Runtime.version().feature(). The effective runtime version
is the version that the JarFile#JarFile(File, boolean, int, Runtime.Version)
constructor uses when the value of the last argument is
JarFile.runtimeVersion().
jdk.util.jar.enableMultiRelease can be assigned one of the three
String values true, false, or force. The
value true, the default value, enables multi-release jar file
processing. The value false disables multi-release jar processing,
ignoring the "Multi-Release" manifest attribute, and the versioned
directories in a multi-release jar file if they exist. Furthermore,
the method JarFile#isMultiRelease() returns false. The value
force causes the JarFile to be initialized to runtime
versioning after construction. It effectively does the same as this code:
(new JarFile(File, boolean, int, JarFile.runtimeVersion()).
Manifest, java.util.zip.ZipFile , java.util.jar.JarEntry
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Runtime. | |
| private static final int | |
| private static final byte[] | |
| private static final byte[] | |
| private static final byte[] | |
| private volatile boolean | |
| private boolean | |
| private static final ScopedValue | |
| pack-priv static final String | INDEX_NAME
The 'JAR index' feature has been removed, but JarInputStream and JarVerifier's verification of signed jars still need to be able to skip this entry. |
| private boolean | |
| private static final JavaUtilZipFileAccess | |
| private JarVerifier | |
| private boolean | |
| private JarEntry | |
| public static final String | MANIFEST_NAME
The JAR manifest file name. |
| private SoftReference | |
| private static final String | |
| private static final String | |
| private static final boolean | |
| private static final boolean | |
| private static final byte[] | |
| private static final byte[] | |
| private static final byte[] | |
| private static final Runtime. | |
| private boolean | |
| private final Runtime. | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| public | |
| public | JarFile(File
the jar file to be opened for reading file, boolean whether or not to verify the jar file if
it is signed. verify, int the mode in which the file is to be opened mode, Runtime.specifies the release version for a multi-release jar file versionCreates a new |
| Modifier and Type | Method and Description |
|---|---|
| public static Runtime. | Returns: the version that represents the unversioned configurationReturns the version that represents the unversioned configuration of a multi-release jar file. |
| private void | checkForSpecialAttributes()
On first invocation, check if the JAR file has the Class-Path and the Multi-Release attribute. |
| pack-priv synchronized void | |
| public Enumeration | Returns: an enumeration of the jar file entriesOverrides java. Returns an enumeration of the jar file entries. |
| pack-priv JarEntry | |
| private String | |
| private byte[] | |
| public ZipEntry | Returns: theZipEntry for the given entry name or
the versioned entry name or null if not foundthe jar file entry name name)Overrides java. Returns the |
| public synchronized InputStream | Returns: an input stream for reading the contents of the specified ZIP file entry or null if the ZIP file entry does not exist within the jar filethe ZIP file entry ze)Overrides java. Returns an input stream for reading the contents of the specified ZIP file entry. |
| public JarEntry | Returns: theJarEntry for the given entry name, or
the versioned entry name, or null if not foundthe jar file entry name name)Returns the |
| private JarEntry | |
| public Manifest | Returns: the jar file manifest, ornull if noneReturns the jar file manifest, or |
| private Manifest | |
| pack-priv String | |
| public final Runtime. | Returns: the maximum versionReturns the maximum version used when searching for versioned entries. |
| private JarEntry | |
| pack-priv boolean | |
| private void | |
| pack-priv static boolean | Returns: true if the current thread is initializing a JAR verifier, false otherwiseReturns true if the current thread is initializing a JAR verifier, false otherwise. |
| public final boolean | Returns: true if this JarFile is a multi-release jar fileIndicates whether or not this jar file is a multi-release jar file. |
| private int | match(byte[] src, byte[] b, byte[] lastOcc, byte[] optoSft)
Returns true if the pattern |
| private void | |
| public static Runtime. | Returns: the version that represents the runtime versioned configurationReturns the version that represents the effective runtime versioned configuration of a multi-release jar file. |
| public Stream | Returns: an orderedStream of entries in this jar fileOverrides java. Returns an ordered |
| private JarEntry | |
| public Stream | Returns: stream of versioned entriesReturns a |
| BASE_VERSION | back to summary |
|---|---|
| private static final Runtime. | |
| BASE_VERSION_FEATURE | back to summary |
|---|---|
| private static final int BASE_VERSION_FEATURE | |
| CLASSPATH_CHARS | back to summary |
|---|---|
| private static final byte[] CLASSPATH_CHARS | |
| CLASSPATH_LASTOCC | back to summary |
|---|---|
| private static final byte[] CLASSPATH_LASTOCC | |
| CLASSPATH_OPTOSFT | back to summary |
|---|---|
| private static final byte[] CLASSPATH_OPTOSFT | |
| hasCheckedSpecialAttributes | back to summary |
|---|---|
| private volatile boolean hasCheckedSpecialAttributes | |
| hasClassPathAttribute | back to summary |
|---|---|
| private boolean hasClassPathAttribute | |
| IN_VERIFIER_INIT | back to summary |
|---|---|
| private static final ScopedValue<Boolean> IN_VERIFIER_INIT | |
| INDEX_NAME | back to summary |
|---|---|
| pack-priv static final String INDEX_NAME The 'JAR index' feature has been removed, but JarInputStream and JarVerifier's verification of signed jars still need to be able to skip this entry. | |
| isMultiRelease | back to summary |
|---|---|
| private boolean isMultiRelease | |
| JUZFA | back to summary |
|---|---|
| private static final JavaUtilZipFileAccess JUZFA | |
| jv | back to summary |
|---|---|
| private JarVerifier jv | |
| jvInitialized | back to summary |
|---|---|
| private boolean jvInitialized | |
| manEntry | back to summary |
|---|---|
| private JarEntry manEntry | |
| MANIFEST_NAME | back to summary |
|---|---|
| public static final String MANIFEST_NAME The JAR manifest file name. | |
| manRef | back to summary |
|---|---|
| private SoftReference<Manifest> manRef | |
| META_INF | back to summary |
|---|---|
| private static final String META_INF | |
| META_INF_VERSIONS | back to summary |
|---|---|
| private static final String META_INF_VERSIONS | |
| MULTI_RELEASE_ENABLED | back to summary |
|---|---|
| private static final boolean MULTI_RELEASE_ENABLED | |
| MULTI_RELEASE_FORCED | back to summary |
|---|---|
| private static final boolean MULTI_RELEASE_FORCED | |
| MULTIRELEASE_CHARS | back to summary |
|---|---|
| private static final byte[] MULTIRELEASE_CHARS | |
| MULTIRELEASE_LASTOCC | back to summary |
|---|---|
| private static final byte[] MULTIRELEASE_LASTOCC | |
| MULTIRELEASE_OPTOSFT | back to summary |
|---|---|
| private static final byte[] MULTIRELEASE_OPTOSFT | |
| RUNTIME_VERSION | back to summary |
|---|---|
| private static final Runtime. | |
| verify | back to summary |
|---|---|
| private boolean verify | |
| version | back to summary |
|---|---|
| private final Runtime. | |
| versionFeature | back to summary |
|---|---|
| private final int versionFeature | |
| JarFile | back to summary |
|---|---|
| public JarFile(String name) throws IOException Creates a new
| |
| JarFile | back to summary |
|---|---|
| public JarFile(String name, boolean verify) throws IOException Creates a new
| |
| JarFile | back to summary |
|---|---|
| public JarFile(File file) throws IOException Creates a new
| |
| JarFile | back to summary |
|---|---|
| public JarFile(File file, boolean verify) throws IOException Creates a new
| |
| JarFile | back to summary |
|---|---|
| public JarFile(File file, boolean verify, int mode) throws IOException Creates a new
| |
| JarFile | back to summary |
|---|---|
| public JarFile(File file, boolean verify, int mode, Runtime. Creates a new
The canonical form derived from the version parameter is
| |
| baseVersion | back to summary |
|---|---|
| public static Runtime. Returns the version that represents the unversioned configuration of a multi-release jar file. | |
| checkForSpecialAttributes | back to summary |
|---|---|
| private void checkForSpecialAttributes() throws IOException On first invocation, check if the JAR file has the Class-Path and the Multi-Release attribute. A no-op on subsequent calls. | |
| ensureInitialization | back to summary |
|---|---|
| pack-priv synchronized void ensureInitialization() | |
| entries | back to summary |
|---|---|
| public Enumeration Overrides java. Returns an enumeration of the jar file entries.
| |
| entryFor | back to summary |
|---|---|
| pack-priv JarEntry entryFor(String name) Creates a ZipEntry suitable for the given ZipFile. | |
| getBasename | back to summary |
|---|---|
| private String getBasename(String name) | |
| getBytes | back to summary |
|---|---|
| private byte[] getBytes(ZipEntry ze) throws IOException | |
| getEntry | back to summary |
|---|---|
| public ZipEntry getEntry(String name) Overrides java. Returns the If this Implementation Specification
This implementation may return a versioned entry for the requested name
even if there is not a corresponding base entry. This can occur
if there is a private or package-private versioned entry that matches.
If a subclass overrides this method, assure that the override method
invokes
super.getEntry(name) to obtain all versioned entries.
| |
| getInputStream | back to summary |
|---|---|
| public synchronized InputStream getInputStream(ZipEntry ze) throws IOException Overrides java. Returns an input stream for reading the contents of the specified ZIP file entry. API Note The
| |
| getJarEntry | back to summary |
|---|---|
| public JarEntry getJarEntry(String name) Returns the If this Implementation Specification
This implementation invokes
JarFile#getEntry(String).
| |
| getManEntry | back to summary |
|---|---|
| private JarEntry getManEntry() | |
| getManifest | back to summary |
|---|---|
| public Manifest getManifest() throws IOException Returns the jar file manifest, or
| |
| getManifestFromReference | back to summary |
|---|---|
| private Manifest getManifestFromReference() throws IOException | |
| getRealName | back to summary |
|---|---|
| pack-priv String getRealName(JarEntry entry) | |
| getVersion | back to summary |
|---|---|
| public final Runtime. Returns the maximum version used when searching for versioned entries.
If this | |
| getVersionedEntry | back to summary |
|---|---|
| private JarEntry getVersionedEntry(String name, JarEntry defaultEntry) | |
| hasClassPathAttribute | back to summary |
|---|---|
| pack-priv boolean hasClassPathAttribute() throws IOException Returns | |
| initializeVerifier | back to summary |
|---|---|
| private void initializeVerifier() | |
| isInitializing | back to summary |
|---|---|
| pack-priv static boolean isInitializing() Returns true if the current thread is initializing a JAR verifier, false otherwise.
| |
| isMultiRelease | back to summary |
|---|---|
| public final boolean isMultiRelease() Indicates whether or not this jar file is a multi-release jar file.
| |
| match | back to summary |
|---|---|
| private int match(byte[] src, byte[] b, byte[] lastOcc, byte[] optoSft) Returns true if the pattern | |
| maybeInstantiateVerifier | back to summary |
|---|---|
| private void maybeInstantiateVerifier() throws IOException | |
| runtimeVersion | back to summary |
|---|---|
| public static Runtime. Returns the version that represents the effective runtime versioned configuration of a multi-release jar file.
By default the feature version number of the returned | |
| stream | back to summary |
|---|---|
| public Stream Overrides java. Returns an ordered
| |
| verifiableEntry | back to summary |
|---|---|
| private JarEntry verifiableEntry(ZipEntry ze) throws ZipException | |
| versionedStream | back to summary |
|---|---|
| public Stream Returns a If this | |
| Modifier and Type | Field and Description |
|---|---|
| private String |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Attributes | getAttributes()
Overrides java. Returns the |
| public Certificate[] | getCertificates()
Overrides java. Returns the |
| public CodeSigner[] | getCodeSigners()
Overrides java. Returns the |
| public String | |
| public String | |
| pack-priv JarFile. | |
| pack-priv JarFile. |
| basename | back to summary |
|---|---|
| private String basename | |
| JarFileEntry | back to summary |
|---|---|
| pack-priv JarFileEntry(String name) | |
| JarFileEntry | back to summary |
|---|---|
| pack-priv JarFileEntry(String name, ZipEntry vze) | |
| getAttributes | back to summary |
|---|---|
| public Attributes getAttributes() throws IOException Overrides java. Doc from java. Returns the
| |
| getCertificates | back to summary |
|---|---|
| public Certificate[] getCertificates() Overrides java. Doc from java. Returns the It is recommended to use the The returned certificate array comprises all the signer certificates that were used to verify this entry. Each signer certificate is followed by its supporting certificate chain (which may be empty). Each signer certificate and its supporting certificate chain are ordered bottom-to-top (i.e., with the signer certificate first and the (root) certificate authority last).
| |
| getCodeSigners | back to summary |
|---|---|
| public CodeSigner[] getCodeSigners() Overrides java. Doc from java. Returns the The returned array comprises all the code signers that have signed this entry.
| |
| getName | back to summary |
|---|---|
| public String getName() Overrides java. Doc from java. Returns the name of the entry.
| |
| getRealName | back to summary |
|---|---|
| public String getRealName() Overrides java. Doc from java. Returns the real name of this
| |
| realEntry | back to summary |
|---|---|
| pack-priv JarFile. | |
| withBasename | back to summary |
|---|---|
| pack-priv JarFile. | |