< prev index next >
src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java
Print this page
*** 27,40 ****
--- 27,42 ----
import java.io.InputStream;
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;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
*** 51,60 ****
--- 53,65 ----
/* the Jar file factory. It handles both retrieval and caching.
*/
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;
/* the permission to get this JAR file. This is the actual, ultimate,
* permission, returned by the jar file factory.
*** 157,167 ****
if (jarEntry == null) {
throw new FileNotFoundException("JAR entry " + entryName +
" not found in " +
jarFile.getName());
}
! result = new JarURLInputStream (jarFile.getInputStream(jarEntry));
}
return result;
}
public int getContentLength() {
--- 162,181 ----
if (jarEntry == null) {
throw new FileNotFoundException("JAR entry " + entryName +
" not found in " +
jarFile.getName());
}
! 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;
}
public int getContentLength() {
< prev index next >