--- old/src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java 2015-05-18 18:36:21.491765393 -0700 +++ new/src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java 2015-05-18 18:36:21.363765398 -0700 @@ -29,10 +29,12 @@ import java.io.IOException; import java.io.FileNotFoundException; import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import java.net.UnknownServiceException; +import java.nio.ByteBuffer; import java.util.Enumeration; import java.util.Map; import java.util.List; @@ -53,6 +55,9 @@ */ private static final JarFileFactory factory = JarFileFactory.getInstance(); + private static final sun.misc.JavaUtilZipFileAccess zipAccess + = sun.misc.SharedSecrets.getJavaUtilZipFileAccess(); + /* the url for the Jar file */ private URL jarFileURL; @@ -159,7 +164,16 @@ " not found in " + jarFile.getName()); } - result = new JarURLInputStream (jarFile.getInputStream(jarEntry)); + long size = jarEntry.getSize(); + if (size > 0 && size < 512 * 1024) { + byte[] bytes = new byte[(int) size]; + ByteBuffer bb = ByteBuffer.wrap(bytes); + zipAccess.fillByteBuffer(jarFile, jarEntry, bb); + result = new JarURLInputStream(new ByteArrayInputStream(bytes, 0, bb.position())); + } else { + // Unknown or too large ZipEntry size to use a array + result = new JarURLInputStream(jarFile.getInputStream(jarEntry)); + } } return result; }