obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.net;
import java.io.ByteArrayOutputStream;
{
Certificate[] certs = getCertificates();
if (certs == null)
- return loader.noCertCodeSource;
+ return loader.noCertCodeSource;
else
- return new CodeSource(loader.baseURL, certs);
+ return new CodeSource(loader.baseURL, certs);
}
/**
JarFile jarfile = null;
try
{
- baseJarURL =
- new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
+ baseJarURL =
+ new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
- jarfile =
- ((JarURLConnection) baseJarURL.openConnection()).getJarFile();
+ jarfile =
+ ((JarURLConnection) baseJarURL.openConnection()).getJarFile();
}
catch (IOException ioe)
{
- /* ignored */
+ /* ignored */
}
this.baseJarURL = baseJarURL;
Resource getResource(String name)
{
if (jarfile == null)
- return null;
+ return null;
if (name.startsWith("/"))
- name = name.substring(1);
+ name = name.substring(1);
JarEntry je = jarfile.getJarEntry(name);
if (je != null)
- return new JarURLResource(this, name, je);
+ return new JarURLResource(this, name, je);
else
- return null;
+ return null;
}
Manifest getManifest()
{
try
{
- return (jarfile == null) ? null : jarfile.getManifest();
+ return (jarfile == null) ? null : jarfile.getManifest();
}
catch (IOException ioe)
{
- return null;
+ return null;
}
}
}
{
try
{
- return new URL(((JarURLLoader) loader).baseJarURL, name,
- loader.classloader.getURLStreamHandler("jar"));
+ return new URL(((JarURLLoader) loader).baseJarURL, name,
+ loader.classloader.getURLStreamHandler("jar"));
}
catch (MalformedURLException e)
{
- InternalError ie = new InternalError();
- ie.initCause(e);
- throw ie;
+ InternalError ie = new InternalError();
+ ie.initCause(e);
+ throw ie;
}
}
}
{
try
{
- URL url =
- new URL(baseURL, name, classloader.getURLStreamHandler(protocol));
- URLConnection connection = url.openConnection();
-
- // Open the connection and check the stream
- // just to be sure it exists.
- int length = connection.getContentLength();
- InputStream stream = connection.getInputStream();
-
- // We can do some extra checking if it is a http request
- if (connection instanceof HttpURLConnection)
- {
- int response =
- ((HttpURLConnection) connection).getResponseCode();
- if (response / 100 != 2)
- return null;
- }
-
- if (stream != null)
- return new RemoteResource(this, name, url, stream, length);
- else
- return null;
+ URL url =
+ new URL(baseURL, name, classloader.getURLStreamHandler(protocol));
+ URLConnection connection = url.openConnection();
+
+ // Open the connection and check the stream
+ // just to be sure it exists.
+ int length = connection.getContentLength();
+ InputStream stream = connection.getInputStream();
+
+ // We can do some extra checking if it is a http request
+ if (connection instanceof HttpURLConnection)
+ {
+ int response =
+ ((HttpURLConnection) connection).getResponseCode();
+ if (response / 100 != 2)
+ return null;
+ }
+
+ if (stream != null)
+ return new RemoteResource(this, name, url, stream, length);
+ else
+ return null;
}
catch (IOException ioe)
{
- return null;
+ return null;
}
}
}
{
File file = new File(dir, name);
if (file.exists() && ! file.isDirectory())
- return new FileResource(this, name, file);
+ return new FileResource(this, name, file);
return null;
}
}
{
try
{
- return new URL(loader.baseURL, name,
- loader.classloader.getURLStreamHandler("file"));
+ return new URL(loader.baseURL, name,
+ loader.classloader.getURLStreamHandler("file"));
}
catch (MalformedURLException e)
{
- InternalError ie = new InternalError();
- ie.initCause(e);
- throw ie;
+ InternalError ie = new InternalError();
+ ie.initCause(e);
+ throw ie;
}
}
}
addURLs(urls);
// If this factory is still not in factoryCache, add it,
- // since we only support three protocols so far, 5 is enough
+ // since we only support three protocols so far, 5 is enough
// for cache initial size
synchronized (factoryCache)
{
- if (factory != null && factoryCache.get(factory) == null)
- factoryCache.put(factory, new HashMap(5));
+ if (factory != null && factoryCache.get(factory) == null)
+ factoryCache.put(factory, new HashMap(5));
}
}
{
synchronized (urlloaders)
{
- if (newUrl == null)
- return; // Silently ignore...
-
- // Check global cache to see if there're already url loader
- // for this url.
- URLLoader loader = (URLLoader) urlloaders.get(newUrl);
- if (loader == null)
- {
- String file = newUrl.getFile();
- String protocol = newUrl.getProtocol();
- // Check that it is not a directory
+ if (newUrl == null)
+ return; // Silently ignore...
+
+ // Check global cache to see if there're already url loader
+ // for this url.
+ URLLoader loader = (URLLoader) urlloaders.get(newUrl);
+ if (loader == null)
+ {
+ String file = newUrl.getFile();
+ String protocol = newUrl.getProtocol();
+
+ // Check that it is not a directory
if ("gcjlib".equals(protocol))
loader = new SoURLLoader(this, newUrl);
else if (! (file.endsWith("/") || file.endsWith(File.separator)))
- loader = new JarURLLoader(this, newUrl);
- else if ("file".equals(protocol))
- loader = new FileURLLoader(this, newUrl);
- else
- loader = new RemoteURLLoader(this, newUrl);
-
- // Cache it.
- urlloaders.put(newUrl, loader);
- }
-
- urls.add(newUrl);
- urlinfos.add(loader);
+ loader = new JarURLLoader(this, newUrl);
+ else if ("file".equals(protocol))
+ loader = new FileURLLoader(this, newUrl);
+ else
+ loader = new RemoteURLLoader(this, newUrl);
+
+ // Cache it.
+ urlloaders.put(newUrl, loader);
+ }
+
+ urls.add(newUrl);
+ urlinfos.add(loader);
}
}
// construct the class (and watch out for those nasty IOExceptions)
try
{
- byte[] data;
- InputStream in = resource.getInputStream();
+ byte[] data;
+ InputStream in = resource.getInputStream();
int length = resource.getLength();
if (length != -1)
{
out.write(b, 0, l);
}
data = out.toByteArray();
- }
- final byte[] classData = data;
-
- // Now get the CodeSource
- final CodeSource source = resource.getCodeSource();
-
- // Find out package name
- String packageName = null;
- int lastDot = className.lastIndexOf('.');
- if (lastDot != -1)
- packageName = className.substring(0, lastDot);
-
- if (packageName != null && getPackage(packageName) == null)
- {
- // define the package
- Manifest manifest = resource.loader.getManifest();
- if (manifest == null)
- definePackage(packageName, null, null, null, null, null, null,
- null);
- else
- definePackage(packageName, manifest, resource.loader.baseURL);
- }
-
- // And finally construct the class!
- SecurityManager sm = System.getSecurityManager();
- if (sm != null && securityContext != null)
- {
+ }
+ final byte[] classData = data;
+
+ // Now get the CodeSource
+ final CodeSource source = resource.getCodeSource();
+
+ // Find out package name
+ String packageName = null;
+ int lastDot = className.lastIndexOf('.');
+ if (lastDot != -1)
+ packageName = className.substring(0, lastDot);
+
+ if (packageName != null && getPackage(packageName) == null)
+ {
+ // define the package
+ Manifest manifest = resource.loader.getManifest();
+ if (manifest == null)
+ definePackage(packageName, null, null, null, null, null, null,
+ null);
+ else
+ definePackage(packageName, manifest, resource.loader.baseURL);
+ }
+
+ // And finally construct the class!
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null && securityContext != null)
+ {
return (Class)AccessController.doPrivileged
- (new PrivilegedAction()
- {
- public Object run()
- {
- return defineClass(className, classData,
- 0, classData.length,
- source);
- }
- }, securityContext);
- }
- else
+ (new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return defineClass(className, classData,
+ 0, classData.length,
+ source);
+ }
+ }, securityContext);
+ }
+ else
return defineClass(className, classData, 0, classData.length, source);
}
catch (IOException ioe)
{
- throw new ClassNotFoundException(className, ioe);
+ throw new ClassNotFoundException(className, ioe);
}
}
int max = urls.size();
for (int i = 0; i < max; i++)
{
- URLLoader loader = (URLLoader) urlinfos.elementAt(i);
- if (loader == null)
- continue;
+ URLLoader loader = (URLLoader) urlinfos.elementAt(i);
+ if (loader == null)
+ continue;
- Resource resource = loader.getResource(resourceName);
- if (resource != null)
- return resource;
+ Resource resource = loader.getResource(resourceName);
+ if (resource != null)
+ return resource;
}
return null;
}
URLStreamHandler handler;
synchronized (factoryCache)
{
- // Check if there're handler for the same protocol in cache.
- HashMap cache = (HashMap) factoryCache.get(factory);
- handler = (URLStreamHandler) cache.get(protocol);
- if (handler == null)
- {
- // Add it to cache.
- handler = factory.createURLStreamHandler(protocol);
- cache.put(protocol, handler);
- }
+ // Check if there're handler for the same protocol in cache.
+ HashMap cache = (HashMap) factoryCache.get(factory);
+ handler = (URLStreamHandler) cache.get(protocol);
+ if (handler == null)
+ {
+ // Add it to cache.
+ handler = factory.createURLStreamHandler(protocol);
+ cache.put(protocol, handler);
+ }
}
return handler;
}
int max = urls.size();
for (int i = 0; i < max; i++)
{
- URLLoader loader = (URLLoader) urlinfos.elementAt(i);
- Resource resource = loader.getResource(resourceName);
- if (resource != null)
- resources.add(resource.getURL());
+ URLLoader loader = (URLLoader) urlinfos.elementAt(i);
+ Resource resource = loader.getResource(resourceName);
+ if (resource != null)
+ resources.add(resource.getURL());
}
return resources.elements();
}
String protocol = url.getProtocol();
if (protocol.equals("file"))
{
- String file = url.getFile();
-
- // If the file end in / it must be an directory.
- if (file.endsWith("/") || file.endsWith(File.separator))
- {
- // Grant permission to read everything in that directory and
- // all subdirectories.
- permissions.add(new FilePermission(file + "-", "read"));
- }
- else
- {
- // It is a 'normal' file.
- // Grant permission to access that file.
- permissions.add(new FilePermission(file, "read"));
- }
+ String file = url.getFile();
+
+ // If the file end in / it must be an directory.
+ if (file.endsWith("/") || file.endsWith(File.separator))
+ {
+ // Grant permission to read everything in that directory and
+ // all subdirectories.
+ permissions.add(new FilePermission(file + "-", "read"));
+ }
+ else
+ {
+ // It is a 'normal' file.
+ // Grant permission to access that file.
+ permissions.add(new FilePermission(file, "read"));
+ }
}
else
{
- // Grant permission to connect to and accept connections from host
- String host = url.getHost();
- if (host != null)
- permissions.add(new SocketPermission(host, "connect,accept"));
+ // Grant permission to connect to and accept connections from host
+ String host = url.getHost();
+ if (host != null)
+ permissions.add(new SocketPermission(host, "connect,accept"));
}
return permissions;
return new URLClassLoader(urls, parent);
else
{
- final Object securityContext = sm.getSecurityContext();
-
- // XXX - What to do with anything else then an AccessControlContext?
- if (! (securityContext instanceof AccessControlContext))
- throw new SecurityException("securityContext must be AccessControlContext: "
- + securityContext);
-
- URLClassLoader loader =
- (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction()
- {
- public Object run()
- {
- return new URLClassLoader(parent,
- (AccessControlContext) securityContext);
- }
- });
- loader.addURLs(urls);
- return loader;
+ final Object securityContext = sm.getSecurityContext();
+
+ // XXX - What to do with anything else then an AccessControlContext?
+ if (! (securityContext instanceof AccessControlContext))
+ throw new SecurityException("securityContext must be AccessControlContext: "
+ + securityContext);
+
+ URLClassLoader loader =
+ (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new URLClassLoader(parent,
+ (AccessControlContext) securityContext);
+ }
+ });
+ loader.addURLs(urls);
+ return loader;
}
}
}