< prev index next >
src/java.base/share/classes/java/util/jar/JarFile.java
Print this page
@@ -32,14 +32,11 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.*;
import java.security.CodeSigner;
import java.security.cert.Certificate;
-import java.security.AccessController;
import java.security.CodeSource;
-import sun.misc.IOUtils;
-import sun.security.action.GetPropertyAction;
import sun.security.util.ManifestEntryVerifier;
import sun.misc.SharedSecrets;
import sun.security.util.SignatureFileVerifier;
/**
@@ -83,10 +80,13 @@
// Set up JavaUtilJarAccess in SharedSecrets
static {
SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
}
+ private static final sun.misc.JavaUtilZipFileAccess zipAccess
+ = sun.misc.SharedSecrets.getJavaUtilZipFileAccess();
+
/**
* The JAR manifest file name.
*/
public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
@@ -183,23 +183,19 @@
private Manifest getManifestFromReference() throws IOException {
Manifest man = manRef != null ? manRef.get() : null;
if (man == null) {
- JarEntry manEntry = getManEntry();
+ JarEntry entry = getManEntry();
// If found then load the manifest
- if (manEntry != null) {
- if (verify) {
- byte[] b = getBytes(manEntry);
+ if (entry != null) {
+ byte[] b = zipAccess.getBytes(this, entry);
man = new Manifest(new ByteArrayInputStream(b));
- if (!jvInitialized) {
+ if (verify && !jvInitialized) {
jv = new JarVerifier(b);
}
- } else {
- man = new Manifest(super.getInputStream(manEntry));
- }
manRef = new SoftReference<>(man);
}
}
return man;
}
@@ -374,11 +370,11 @@
}
if (mev == null) {
mev = new ManifestEntryVerifier
(getManifestFromReference());
}
- byte[] b = getBytes(e);
+ byte[] b = zipAccess.getBytes(this, e);
if (b != null && b.length > 0) {
jv.beginEntry(e, mev);
jv.update(b.length, b, 0, b.length, mev);
jv.update(-1, null, 0, 0, mev);
}
@@ -414,20 +410,10 @@
verify = false;
}
}
}
- /*
- * Reads all the bytes for a given entry. Used to process the
- * META-INF files.
- */
- private byte[] getBytes(ZipEntry ze) throws IOException {
- try (InputStream is = super.getInputStream(ze)) {
- return IOUtils.readFully(is, (int)ze.getSize(), true);
- }
- }
-
/**
* Returns an input stream for reading the contents of the specified
* zip file entry.
* @param ze the zip file entry
* @return an input stream for reading the contents of the specified
@@ -546,13 +532,13 @@
* On first invocation, check if the JAR file has the Class-Path
* attribute. A no-op on subsequent calls.
*/
private void checkForSpecialAttributes() throws IOException {
if (hasCheckedSpecialAttributes) return;
- JarEntry manEntry = getManEntry();
- if (manEntry != null) {
- byte[] b = getBytes(manEntry);
+ JarEntry entry = getManEntry();
+ if (entry != null) {
+ byte[] b = zipAccess.getBytes(this, entry);
if (match(CLASSPATH_CHARS, b, CLASSPATH_LASTOCC, CLASSPATH_OPTOSFT))
hasClassPathAttribute = true;
}
hasCheckedSpecialAttributes = true;
}
< prev index next >