Top Description Fields Constructors Methods
com.sun.istack.tools

public Class ParallelWorldClassLoader

extends ClassLoader
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.InputStream, .ByteArrayOutputStream, .Closeable, .File, .IOException, java.net.JarURLConnection, .URISyntaxException, .URL, .MalformedURLException, .URLConnection, java.util.Collections, .Enumeration, .HashSet, .Set, java.util.jar.JarFile, java.util.logging.Level, .Logger

Load classes/resources from a side folder, so that classes of the same package can live in a single jar file.

For example, with the following jar file:

 /
 +- foo
    +- X.class
 +- bar
    +- X.class

ParallelWorldClassLoader("foo/") would load X.class from /foo/X.class (note that X is defined in the root package, not foo.X.

This can be combined with MaskingClassLoader to mask classes which are loaded by the parent class loader so that the child class loader classes living in different folders are loaded before the parent class loader loads classes living the jar file publicly visible For example, with the following jar file:

 /
 +- foo
    +- X.class
 +- bar
    +-foo
       +- X.class

ParallelWorldClassLoader(MaskingClassLoader.class.getClassLoader()) would load foo.X.class from /bar/foo.X.class not the foo.X.class in the publicly visible place in the jar file, thus masking the parent classLoader from loading the class from foo.X.class (note that X is defined in the package foo, not bar.foo.X.

Author
Kohsuke Kawaguchi

Field Summary

Modifier and TypeField and Description
private final Set<JarFile>
private final String
prefix

Strings like "prefix/", "abc/", or "" to indicate classes should be loaded normally.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

protected Class<?>
findClass(String name)

Overrides java.lang.ClassLoader.findClass.

Finds the class with the specified binary name.

protected URL
findResource(String name)

Overrides java.lang.ClassLoader.findResource.

Finds the resource with the given name.

protected Enumeration<URL>
findResources(String name)

Overrides java.lang.ClassLoader.findResources.

Returns an enumeration of URL objects representing all the resources with the given name.

public static URL

Returns:

URL to the conaining jar file
toJarUrl
(URL
Resource in a jar
res
)

Given the URL inside jar, returns the URL to the jar itself.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

jarsback to summary
private final Set<JarFile> jars
prefixback to summary
private final String prefix

Strings like "prefix/", "abc/", or "" to indicate classes should be loaded normally.

Constructor Detail

ParallelWorldClassLoaderback to summary
public ParallelWorldClassLoader(ClassLoader parent, String prefix)

Method Detail

closeback to summary
public synchronized void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
findClassback to summary
protected Class<?> findClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

Doc from java.lang.ClassLoader.findClass.

Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class.

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
findResourceback to summary
protected URL findResource(String name)

Overrides java.lang.ClassLoader.findResource.

Doc from java.lang.ClassLoader.findResource.

Finds the resource with the given name. Class loader implementations should override this method.

For resources in named modules then the method must implement the rules for encapsulation specified in the Module getResourceAsStream method. Additionally, it must not find non-".class" resources in packages of named modules unless the package is opened unconditionally.

Annotations
@Override
findResourcesback to summary
protected Enumeration<URL> findResources(String name) throws IOException

Overrides java.lang.ClassLoader.findResources.

Doc from java.lang.ClassLoader.findResources.

Returns an enumeration of URL objects representing all the resources with the given name. Class loader implementations should override this method.

For resources in named modules then the method must implement the rules for encapsulation specified in the Module getResourceAsStream method. Additionally, it must not find non-".class" resources in packages of named modules unless the package is opened unconditionally.

Annotations
@Override
Exceptions
IOException:
If I/O errors occur
toJarUrlback to summary
public static URL toJarUrl(URL res) throws ClassNotFoundException, MalformedURLException

Given the URL inside jar, returns the URL to the jar itself.

Parameters
res:URL

Resource in a jar

Returns:URL

URL to the conaining jar file

Exceptions
ClassNotFoundException:
if res does not denote jar URL
MalformedURLException:
if computed URL is invalid