< prev index next >
src/java.base/share/classes/java/util/jar/JarFile.java
Print this page
@@ -26,10 +26,11 @@
package java.util.jar;
import java.io.*;
import java.lang.ref.SoftReference;
import java.net.URL;
+import java.nio.ByteBuffer;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.*;
import java.security.CodeSigner;
@@ -83,10 +84,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";
@@ -187,19 +191,15 @@
JarEntry manEntry = getManEntry();
// If found then load the manifest
if (manEntry != null) {
- if (verify) {
byte[] b = getBytes(manEntry);
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;
}
@@ -419,12 +419,17 @@
/*
* 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);
+ ByteBuffer bb = zipAccess.getByteBuffer(this, ze);
+ if (bb.hasArray()) {
+ return bb.array();
+ } else {
+ byte[] bytes = new byte[bb.remaining()];
+ bb.get(bytes);
+ return bytes;
}
}
/**
* Returns an input stream for reading the contents of the specified
< prev index next >