feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
222
jdkSrc/jdk8/sun/net/www/protocol/jar/Handler.java
Normal file
222
jdkSrc/jdk8/sun/net/www/protocol/jar/Handler.java
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
/*
|
||||
* Jar URL Handler
|
||||
*/
|
||||
public class Handler extends java.net.URLStreamHandler {
|
||||
|
||||
private static final String separator = "!/";
|
||||
|
||||
protected java.net.URLConnection openConnection(URL u)
|
||||
throws IOException {
|
||||
return new JarURLConnection(u, this);
|
||||
}
|
||||
|
||||
private static int indexOfBangSlash(String spec) {
|
||||
int indexOfBang = spec.length();
|
||||
while((indexOfBang = spec.lastIndexOf('!', indexOfBang)) != -1) {
|
||||
if ((indexOfBang != (spec.length() - 1)) &&
|
||||
(spec.charAt(indexOfBang + 1) == '/')) {
|
||||
return indexOfBang + 1;
|
||||
} else {
|
||||
indexOfBang--;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two jar URLs
|
||||
*/
|
||||
@Override
|
||||
protected boolean sameFile(URL u1, URL u2) {
|
||||
if (!u1.getProtocol().equals("jar") || !u2.getProtocol().equals("jar"))
|
||||
return false;
|
||||
|
||||
String file1 = u1.getFile();
|
||||
String file2 = u2.getFile();
|
||||
int sep1 = file1.indexOf(separator);
|
||||
int sep2 = file2.indexOf(separator);
|
||||
|
||||
if (sep1 == -1 || sep2 == -1) {
|
||||
return super.sameFile(u1, u2);
|
||||
}
|
||||
|
||||
String entry1 = file1.substring(sep1 + 2);
|
||||
String entry2 = file2.substring(sep2 + 2);
|
||||
|
||||
if (!entry1.equals(entry2))
|
||||
return false;
|
||||
|
||||
URL enclosedURL1 = null, enclosedURL2 = null;
|
||||
try {
|
||||
enclosedURL1 = new URL(file1.substring(0, sep1));
|
||||
enclosedURL2 = new URL(file2.substring(0, sep2));
|
||||
} catch (MalformedURLException unused) {
|
||||
return super.sameFile(u1, u2);
|
||||
}
|
||||
|
||||
if (!super.sameFile(enclosedURL1, enclosedURL2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int hashCode(URL u) {
|
||||
int h = 0;
|
||||
|
||||
String protocol = u.getProtocol();
|
||||
if (protocol != null)
|
||||
h += protocol.hashCode();
|
||||
|
||||
String file = u.getFile();
|
||||
int sep = file.indexOf(separator);
|
||||
|
||||
if (sep == -1)
|
||||
return h + file.hashCode();
|
||||
|
||||
URL enclosedURL = null;
|
||||
String fileWithoutEntry = file.substring(0, sep);
|
||||
try {
|
||||
enclosedURL = new URL(fileWithoutEntry);
|
||||
h += enclosedURL.hashCode();
|
||||
} catch (MalformedURLException unused) {
|
||||
h += fileWithoutEntry.hashCode();
|
||||
}
|
||||
|
||||
String entry = file.substring(sep + 2);
|
||||
h += entry.hashCode();
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
public String checkNestedProtocol(String spec) {
|
||||
if (spec.regionMatches(true, 0, "jar:", 0, 4)) {
|
||||
return "Nested JAR URLs are not supported";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void parseURL(URL url, String spec,
|
||||
int start, int limit) {
|
||||
String file = null;
|
||||
String ref = null;
|
||||
// first figure out if there is an anchor
|
||||
int refPos = spec.indexOf('#', limit);
|
||||
boolean refOnly = refPos == start;
|
||||
if (refPos > -1) {
|
||||
ref = spec.substring(refPos + 1, spec.length());
|
||||
if (refOnly) {
|
||||
file = url.getFile();
|
||||
}
|
||||
}
|
||||
// then figure out if the spec is
|
||||
// 1. absolute (jar:)
|
||||
// 2. relative (i.e. url + foo/bar/baz.ext)
|
||||
// 3. anchor-only (i.e. url + #foo), which we already did (refOnly)
|
||||
boolean absoluteSpec = false;
|
||||
if (spec.length() >= 4) {
|
||||
absoluteSpec = spec.substring(0, 4).equalsIgnoreCase("jar:");
|
||||
}
|
||||
spec = spec.substring(start, limit);
|
||||
|
||||
String exceptionMessage = checkNestedProtocol(spec);
|
||||
if (exceptionMessage != null) {
|
||||
// NPE will be transformed into MalformedURLException by the caller
|
||||
throw new NullPointerException(exceptionMessage);
|
||||
}
|
||||
|
||||
if (absoluteSpec) {
|
||||
file = parseAbsoluteSpec(spec);
|
||||
} else if (!refOnly) {
|
||||
file = parseContextSpec(url, spec);
|
||||
|
||||
// Canonize the result after the bangslash
|
||||
int bangSlash = indexOfBangSlash(file);
|
||||
String toBangSlash = file.substring(0, bangSlash);
|
||||
String afterBangSlash = file.substring(bangSlash);
|
||||
sun.net.www.ParseUtil canonizer = new ParseUtil();
|
||||
afterBangSlash = canonizer.canonizeString(afterBangSlash);
|
||||
file = toBangSlash + afterBangSlash;
|
||||
}
|
||||
setURL(url, "jar", "", -1, file, ref);
|
||||
}
|
||||
|
||||
private String parseAbsoluteSpec(String spec) {
|
||||
URL url = null;
|
||||
int index = -1;
|
||||
// check for !/
|
||||
if ((index = indexOfBangSlash(spec)) == -1) {
|
||||
throw new NullPointerException("no !/ in spec");
|
||||
}
|
||||
// test the inner URL
|
||||
try {
|
||||
String innerSpec = spec.substring(0, index - 1);
|
||||
url = new URL(innerSpec);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new NullPointerException("invalid url: " +
|
||||
spec + " (" + e + ")");
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
private String parseContextSpec(URL url, String spec) {
|
||||
String ctxFile = url.getFile();
|
||||
// if the spec begins with /, chop up the jar back !/
|
||||
if (spec.startsWith("/")) {
|
||||
int bangSlash = indexOfBangSlash(ctxFile);
|
||||
if (bangSlash == -1) {
|
||||
throw new NullPointerException("malformed " +
|
||||
"context url:" +
|
||||
url +
|
||||
": no !/");
|
||||
}
|
||||
ctxFile = ctxFile.substring(0, bangSlash);
|
||||
}
|
||||
if (!ctxFile.endsWith("/") && (!spec.startsWith("/"))){
|
||||
// chop up the last component
|
||||
int lastSlash = ctxFile.lastIndexOf('/');
|
||||
if (lastSlash == -1) {
|
||||
throw new NullPointerException("malformed " +
|
||||
"context url:" +
|
||||
url);
|
||||
}
|
||||
ctxFile = ctxFile.substring(0, lastSlash + 1);
|
||||
}
|
||||
return (ctxFile + spec);
|
||||
}
|
||||
}
|
||||
173
jdkSrc/jdk8/sun/net/www/protocol/jar/JarFileFactory.java
Normal file
173
jdkSrc/jdk8/sun/net/www/protocol/jar/JarFileFactory.java
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.jar.JarFile;
|
||||
import java.security.Permission;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
/* A factory for cached JAR file. This class is used to both retrieve
|
||||
* and cache Jar files.
|
||||
*
|
||||
* @author Benjamin Renaud
|
||||
* @since JDK1.2
|
||||
*/
|
||||
class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
|
||||
/* the url to file cache */
|
||||
private static final HashMap<String, JarFile> fileCache = new HashMap<>();
|
||||
|
||||
/* the file to url cache */
|
||||
private static final HashMap<JarFile, URL> urlCache = new HashMap<>();
|
||||
|
||||
private static final JarFileFactory instance = new JarFileFactory();
|
||||
|
||||
private JarFileFactory() { }
|
||||
|
||||
public static JarFileFactory getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
URLConnection getConnection(JarFile jarFile) throws IOException {
|
||||
URL u;
|
||||
synchronized (instance) {
|
||||
u = urlCache.get(jarFile);
|
||||
}
|
||||
if (u != null)
|
||||
return u.openConnection();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public JarFile get(URL url) throws IOException {
|
||||
return get(url, true);
|
||||
}
|
||||
|
||||
JarFile get(URL url, boolean useCaches) throws IOException {
|
||||
if (url.getProtocol().equalsIgnoreCase("file")) {
|
||||
// Deal with UNC pathnames specially. See 4180841
|
||||
|
||||
String host = url.getHost();
|
||||
if (host != null && !host.equals("") &&
|
||||
!host.equalsIgnoreCase("localhost")) {
|
||||
|
||||
url = new URL("file", "", "//" + host + url.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
JarFile result;
|
||||
JarFile local_result;
|
||||
|
||||
if (useCaches) {
|
||||
synchronized (instance) {
|
||||
result = getCachedJarFile(url);
|
||||
}
|
||||
if (result == null) {
|
||||
local_result = URLJarFile.getJarFile(url, this);
|
||||
synchronized (instance) {
|
||||
result = getCachedJarFile(url);
|
||||
if (result == null) {
|
||||
fileCache.put(URLUtil.urlNoFragString(url), local_result);
|
||||
urlCache.put(local_result, url);
|
||||
result = local_result;
|
||||
} else {
|
||||
if (local_result != null) {
|
||||
local_result.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = URLJarFile.getJarFile(url, this);
|
||||
}
|
||||
if (result == null)
|
||||
throw new FileNotFoundException(url.toString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method of the URLJarFileCloseController to
|
||||
* indicate that the JarFile is close. This way we can
|
||||
* remove the JarFile from the cache
|
||||
*/
|
||||
public void close(JarFile jarFile) {
|
||||
synchronized (instance) {
|
||||
URL urlRemoved = urlCache.remove(jarFile);
|
||||
if (urlRemoved != null)
|
||||
fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
private JarFile getCachedJarFile(URL url) {
|
||||
assert Thread.holdsLock(instance);
|
||||
JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
|
||||
|
||||
/* if the JAR file is cached, the permission will always be there */
|
||||
if (result != null) {
|
||||
Permission perm = getPermission(result);
|
||||
if (perm != null) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
try {
|
||||
sm.checkPermission(perm);
|
||||
} catch (SecurityException se) {
|
||||
// fallback to checkRead/checkConnect for pre 1.2
|
||||
// security managers
|
||||
if ((perm instanceof java.io.FilePermission) &&
|
||||
perm.getActions().indexOf("read") != -1) {
|
||||
sm.checkRead(perm.getName());
|
||||
} else if ((perm instanceof
|
||||
java.net.SocketPermission) &&
|
||||
perm.getActions().indexOf("connect") != -1) {
|
||||
sm.checkConnect(url.getHost(), url.getPort());
|
||||
} else {
|
||||
throw se;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Permission getPermission(JarFile jarFile) {
|
||||
try {
|
||||
URLConnection uc = getConnection(jarFile);
|
||||
if (uc != null)
|
||||
return uc.getPermission();
|
||||
} catch (IOException ioe) {
|
||||
// gulp
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
376
jdkSrc/jdk8/sun/net/www/protocol/jar/JarURLConnection.java
Normal file
376
jdkSrc/jdk8/sun/net/www/protocol/jar/JarURLConnection.java
Normal file
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.UnknownServiceException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.security.Permission;
|
||||
|
||||
/**
|
||||
* @author Benjamin Renaud
|
||||
* @since 1.2
|
||||
*/
|
||||
public class JarURLConnection extends java.net.JarURLConnection {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
/* the Jar file factory. It handles both retrieval and caching.
|
||||
*/
|
||||
private static final JarFileFactory factory = JarFileFactory.getInstance();
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
private Permission permission;
|
||||
|
||||
/* the url connection for the JAR file */
|
||||
private URLConnection jarFileURLConnection;
|
||||
|
||||
/* the entry name, if any */
|
||||
private String entryName;
|
||||
|
||||
/* the JarEntry */
|
||||
private JarEntry jarEntry;
|
||||
|
||||
/* the jar file corresponding to this connection */
|
||||
private JarFile jarFile;
|
||||
|
||||
/* the content type for this connection */
|
||||
private String contentType;
|
||||
|
||||
public JarURLConnection(URL url, Handler handler)
|
||||
throws MalformedURLException, IOException {
|
||||
super(url);
|
||||
|
||||
jarFileURL = getJarFileURL();
|
||||
jarFileURLConnection = jarFileURL.openConnection();
|
||||
entryName = getEntryName();
|
||||
}
|
||||
|
||||
public JarFile getJarFile() throws IOException {
|
||||
connect();
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
public JarEntry getJarEntry() throws IOException {
|
||||
connect();
|
||||
return jarEntry;
|
||||
}
|
||||
|
||||
public Permission getPermission() throws IOException {
|
||||
return jarFileURLConnection.getPermission();
|
||||
}
|
||||
|
||||
class JarURLInputStream extends java.io.FilterInputStream {
|
||||
JarURLInputStream (InputStream src) {
|
||||
super (src);
|
||||
}
|
||||
public void close () throws IOException {
|
||||
try {
|
||||
super.close();
|
||||
} finally {
|
||||
if (!getUseCaches()) {
|
||||
jarFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void connect() throws IOException {
|
||||
if (!connected) {
|
||||
/* the factory call will do the security checks */
|
||||
jarFile = factory.get(getJarFileURL(), getUseCaches());
|
||||
|
||||
/* we also ask the factory the permission that was required
|
||||
* to get the jarFile, and set it as our permission.
|
||||
*/
|
||||
if (getUseCaches()) {
|
||||
boolean oldUseCaches = jarFileURLConnection.getUseCaches();
|
||||
jarFileURLConnection = factory.getConnection(jarFile);
|
||||
jarFileURLConnection.setUseCaches(oldUseCaches);
|
||||
}
|
||||
|
||||
if ((entryName != null)) {
|
||||
jarEntry = (JarEntry)jarFile.getEntry(entryName);
|
||||
if (jarEntry == null) {
|
||||
try {
|
||||
if (!getUseCaches()) {
|
||||
jarFile.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new FileNotFoundException("JAR entry " + entryName +
|
||||
" not found in " +
|
||||
jarFile.getName());
|
||||
}
|
||||
}
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
connect();
|
||||
|
||||
InputStream result = null;
|
||||
|
||||
if (entryName == null) {
|
||||
throw new IOException("no entry name specified");
|
||||
} else {
|
||||
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() {
|
||||
long result = getContentLengthLong();
|
||||
if (result > Integer.MAX_VALUE)
|
||||
return -1;
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
public long getContentLengthLong() {
|
||||
long result = -1;
|
||||
try {
|
||||
connect();
|
||||
if (jarEntry == null) {
|
||||
/* if the URL referes to an archive */
|
||||
result = jarFileURLConnection.getContentLengthLong();
|
||||
} else {
|
||||
/* if the URL referes to an archive entry */
|
||||
result = getJarEntry().getSize();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object getContent() throws IOException {
|
||||
Object result = null;
|
||||
|
||||
connect();
|
||||
if (entryName == null) {
|
||||
result = jarFile;
|
||||
} else {
|
||||
result = super.getContent();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
if (contentType == null) {
|
||||
if (entryName == null) {
|
||||
contentType = "x-java/jar";
|
||||
} else {
|
||||
try {
|
||||
connect();
|
||||
InputStream in = jarFile.getInputStream(jarEntry);
|
||||
contentType = guessContentTypeFromStream(
|
||||
new BufferedInputStream(in));
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// don't do anything
|
||||
}
|
||||
}
|
||||
if (contentType == null) {
|
||||
contentType = guessContentTypeFromName(entryName);
|
||||
}
|
||||
if (contentType == null) {
|
||||
contentType = "content/unknown";
|
||||
}
|
||||
}
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public String getHeaderField(String name) {
|
||||
return jarFileURLConnection.getHeaderField(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the general request property.
|
||||
*
|
||||
* @param key the keyword by which the request is known
|
||||
* (e.g., "<code>accept</code>").
|
||||
* @param value the value associated with it.
|
||||
*/
|
||||
public void setRequestProperty(String key, String value) {
|
||||
jarFileURLConnection.setRequestProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the named general request property for this
|
||||
* connection.
|
||||
*
|
||||
* @return the value of the named general request property for this
|
||||
* connection.
|
||||
*/
|
||||
public String getRequestProperty(String key) {
|
||||
return jarFileURLConnection.getRequestProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a general request property specified by a
|
||||
* key-value pair. This method will not overwrite
|
||||
* existing values associated with the same key.
|
||||
*
|
||||
* @param key the keyword by which the request is known
|
||||
* (e.g., "<code>accept</code>").
|
||||
* @param value the value associated with it.
|
||||
*/
|
||||
public void addRequestProperty(String key, String value) {
|
||||
jarFileURLConnection.addRequestProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable Map of general request
|
||||
* properties for this connection. The Map keys
|
||||
* are Strings that represent the request-header
|
||||
* field names. Each Map value is a unmodifiable List
|
||||
* of Strings that represents the corresponding
|
||||
* field values.
|
||||
*
|
||||
* @return a Map of the general request properties for this connection.
|
||||
*/
|
||||
public Map<String,List<String>> getRequestProperties() {
|
||||
return jarFileURLConnection.getRequestProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the <code>allowUserInteraction</code> field of
|
||||
* this <code>URLConnection</code>.
|
||||
*
|
||||
* @param allowuserinteraction the new value.
|
||||
* @see java.net.URLConnection#allowUserInteraction
|
||||
*/
|
||||
public void setAllowUserInteraction(boolean allowuserinteraction) {
|
||||
jarFileURLConnection.setAllowUserInteraction(allowuserinteraction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>allowUserInteraction</code> field for
|
||||
* this object.
|
||||
*
|
||||
* @return the value of the <code>allowUserInteraction</code> field for
|
||||
* this object.
|
||||
* @see java.net.URLConnection#allowUserInteraction
|
||||
*/
|
||||
public boolean getAllowUserInteraction() {
|
||||
return jarFileURLConnection.getAllowUserInteraction();
|
||||
}
|
||||
|
||||
/*
|
||||
* cache control
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets the value of the <code>useCaches</code> field of this
|
||||
* <code>URLConnection</code> to the specified value.
|
||||
* <p>
|
||||
* Some protocols do caching of documents. Occasionally, it is important
|
||||
* to be able to "tunnel through" and ignore the caches (e.g., the
|
||||
* "reload" button in a browser). If the UseCaches flag on a connection
|
||||
* is true, the connection is allowed to use whatever caches it can.
|
||||
* If false, caches are to be ignored.
|
||||
* The default value comes from DefaultUseCaches, which defaults to
|
||||
* true.
|
||||
*
|
||||
* @see java.net.URLConnection#useCaches
|
||||
*/
|
||||
public void setUseCaches(boolean usecaches) {
|
||||
jarFileURLConnection.setUseCaches(usecaches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this <code>URLConnection</code>'s
|
||||
* <code>useCaches</code> field.
|
||||
*
|
||||
* @return the value of this <code>URLConnection</code>'s
|
||||
* <code>useCaches</code> field.
|
||||
* @see java.net.URLConnection#useCaches
|
||||
*/
|
||||
public boolean getUseCaches() {
|
||||
return jarFileURLConnection.getUseCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the <code>ifModifiedSince</code> field of
|
||||
* this <code>URLConnection</code> to the specified value.
|
||||
*
|
||||
* @param value the new value.
|
||||
* @see java.net.URLConnection#ifModifiedSince
|
||||
*/
|
||||
public void setIfModifiedSince(long ifmodifiedsince) {
|
||||
jarFileURLConnection.setIfModifiedSince(ifmodifiedsince);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value of the <code>useCaches</code> field to the
|
||||
* specified value.
|
||||
*
|
||||
* @param defaultusecaches the new value.
|
||||
* @see java.net.URLConnection#useCaches
|
||||
*/
|
||||
public void setDefaultUseCaches(boolean defaultusecaches) {
|
||||
jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value of a <code>URLConnection</code>'s
|
||||
* <code>useCaches</code> flag.
|
||||
* <p>
|
||||
* Ths default is "sticky", being a part of the static state of all
|
||||
* URLConnections. This flag applies to the next, and all following
|
||||
* URLConnections that are created.
|
||||
*
|
||||
* @return the default value of a <code>URLConnection</code>'s
|
||||
* <code>useCaches</code> flag.
|
||||
* @see java.net.URLConnection#useCaches
|
||||
*/
|
||||
public boolean getDefaultUseCaches() {
|
||||
return jarFileURLConnection.getDefaultUseCaches();
|
||||
}
|
||||
}
|
||||
286
jdkSrc/jdk8/sun/net/www/protocol/jar/URLJarFile.java
Normal file
286
jdkSrc/jdk8/sun/net/www/protocol/jar/URLJarFile.java
Normal file
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.security.CodeSigner;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
/* URL jar file is a common JarFile subtype used for JarURLConnection */
|
||||
public class URLJarFile extends JarFile {
|
||||
|
||||
/*
|
||||
* Interface to be able to call retrieve() in plugin if
|
||||
* this variable is set.
|
||||
*/
|
||||
private static URLJarFileCallBack callback = null;
|
||||
|
||||
/* Controller of the Jar File's closing */
|
||||
private URLJarFileCloseController closeController = null;
|
||||
|
||||
private static int BUF_SIZE = 2048;
|
||||
|
||||
private Manifest superMan;
|
||||
private Attributes superAttr;
|
||||
private Map<String, Attributes> superEntries;
|
||||
|
||||
static JarFile getJarFile(URL url) throws IOException {
|
||||
return getJarFile(url, null);
|
||||
}
|
||||
|
||||
static JarFile getJarFile(URL url, URLJarFileCloseController closeController) throws IOException {
|
||||
if (isFileURL(url))
|
||||
return new URLJarFile(url, closeController);
|
||||
else {
|
||||
return retrieve(url, closeController);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Changed modifier from private to public in order to be able
|
||||
* to instantiate URLJarFile from sun.plugin package.
|
||||
*/
|
||||
public URLJarFile(File file) throws IOException {
|
||||
this(file, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Changed modifier from private to public in order to be able
|
||||
* to instantiate URLJarFile from sun.plugin package.
|
||||
*/
|
||||
public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException {
|
||||
super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
|
||||
this.closeController = closeController;
|
||||
}
|
||||
|
||||
private URLJarFile(URL url, URLJarFileCloseController closeController) throws IOException {
|
||||
super(ParseUtil.decode(url.getFile()));
|
||||
this.closeController = closeController;
|
||||
}
|
||||
|
||||
private static boolean isFileURL(URL url) {
|
||||
if (url.getProtocol().equalsIgnoreCase("file")) {
|
||||
/*
|
||||
* Consider this a 'file' only if it's a LOCAL file, because
|
||||
* 'file:' URLs can be accessible through ftp.
|
||||
*/
|
||||
String host = url.getHost();
|
||||
if (host == null || host.equals("") || host.equals("~") ||
|
||||
host.equalsIgnoreCase("localhost"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* close the jar file.
|
||||
*/
|
||||
protected void finalize() throws IOException {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>ZipEntry</code> for the given entry name or
|
||||
* <code>null</code> if not found.
|
||||
*
|
||||
* @param name the JAR file entry name
|
||||
* @return the <code>ZipEntry</code> for the given entry name or
|
||||
* <code>null</code> if not found
|
||||
* @see java.util.zip.ZipEntry
|
||||
*/
|
||||
public ZipEntry getEntry(String name) {
|
||||
ZipEntry ze = super.getEntry(name);
|
||||
if (ze != null) {
|
||||
if (ze instanceof JarEntry)
|
||||
return new URLJarFileEntry((JarEntry)ze);
|
||||
else
|
||||
throw new InternalError(super.getClass() +
|
||||
" returned unexpected entry type " +
|
||||
ze.getClass());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Manifest getManifest() throws IOException {
|
||||
|
||||
if (!isSuperMan()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Manifest man = new Manifest();
|
||||
Attributes attr = man.getMainAttributes();
|
||||
attr.putAll((Map)superAttr.clone());
|
||||
|
||||
// now deep copy the manifest entries
|
||||
if (superEntries != null) {
|
||||
Map<String, Attributes> entries = man.getEntries();
|
||||
for (String key : superEntries.keySet()) {
|
||||
Attributes at = superEntries.get(key);
|
||||
entries.put(key, (Attributes) at.clone());
|
||||
}
|
||||
}
|
||||
|
||||
return man;
|
||||
}
|
||||
|
||||
/* If close controller is set the notify the controller about the pending close */
|
||||
public void close() throws IOException {
|
||||
if (closeController != null) {
|
||||
closeController.close(this);
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
// optimal side-effects
|
||||
private synchronized boolean isSuperMan() throws IOException {
|
||||
|
||||
if (superMan == null) {
|
||||
superMan = super.getManifest();
|
||||
}
|
||||
|
||||
if (superMan != null) {
|
||||
superAttr = superMan.getMainAttributes();
|
||||
superEntries = superMan.getEntries();
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a URL, retrieves a JAR file, caches it to disk, and creates a
|
||||
* cached JAR file object.
|
||||
*/
|
||||
private static JarFile retrieve(final URL url) throws IOException {
|
||||
return retrieve(url, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a URL, retrieves a JAR file, caches it to disk, and creates a
|
||||
* cached JAR file object.
|
||||
*/
|
||||
private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
|
||||
/*
|
||||
* See if interface is set, then call retrieve function of the class
|
||||
* that implements URLJarFileCallBack interface (sun.plugin - to
|
||||
* handle the cache failure for JARJAR file.)
|
||||
*/
|
||||
if (callback != null)
|
||||
{
|
||||
return callback.retrieve(url);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
JarFile result = null;
|
||||
|
||||
/* get the stream before asserting privileges */
|
||||
try (final InputStream in = url.openConnection().getInputStream()) {
|
||||
result = AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<JarFile>() {
|
||||
public JarFile run() throws IOException {
|
||||
Path tmpFile = Files.createTempFile("jar_cache", null);
|
||||
try {
|
||||
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController);
|
||||
tmpFile.toFile().deleteOnExit();
|
||||
return jarFile;
|
||||
} catch (Throwable thr) {
|
||||
try {
|
||||
Files.delete(tmpFile);
|
||||
} catch (IOException ioe) {
|
||||
thr.addSuppressed(ioe);
|
||||
}
|
||||
throw thr;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException pae) {
|
||||
throw (IOException) pae.getException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the call back interface to call retrive function in sun.plugin
|
||||
* package if plugin is running.
|
||||
*/
|
||||
public static void setCallBack(URLJarFileCallBack cb)
|
||||
{
|
||||
callback = cb;
|
||||
}
|
||||
|
||||
|
||||
private class URLJarFileEntry extends JarEntry {
|
||||
private JarEntry je;
|
||||
|
||||
URLJarFileEntry(JarEntry je) {
|
||||
super(je);
|
||||
this.je=je;
|
||||
}
|
||||
|
||||
public Attributes getAttributes() throws IOException {
|
||||
if (URLJarFile.this.isSuperMan()) {
|
||||
Map<String, Attributes> e = URLJarFile.this.superEntries;
|
||||
if (e != null) {
|
||||
Attributes a = e.get(getName());
|
||||
if (a != null)
|
||||
return (Attributes)a.clone();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public java.security.cert.Certificate[] getCertificates() {
|
||||
Certificate[] certs = je.getCertificates();
|
||||
return certs == null? null: certs.clone();
|
||||
}
|
||||
|
||||
public CodeSigner[] getCodeSigners() {
|
||||
CodeSigner[] csg = je.getCodeSigners();
|
||||
return csg == null? null: csg.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public interface URLJarFileCloseController {
|
||||
public void close(JarFile jarFile);
|
||||
}
|
||||
}
|
||||
39
jdkSrc/jdk8/sun/net/www/protocol/jar/URLJarFileCallBack.java
Normal file
39
jdkSrc/jdk8/sun/net/www/protocol/jar/URLJarFileCallBack.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
|
||||
/*
|
||||
* This interface is used to call back to sun.plugin package.
|
||||
*/
|
||||
public interface URLJarFileCallBack
|
||||
{
|
||||
public JarFile retrieve (URL url) throws IOException;
|
||||
}
|
||||
Reference in New Issue
Block a user