Top Description Inners Fields Constructors Methods
org.codehaus.commons.compiler.lang

public final Class ClassLoaders

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, java.net.JarURLConnection, .MalformedURLException, .URI, .URL, java.util.Collections, .Enumeration, .HashMap, .Map, .Set, java.util.jar.JarEntry, .JarFile, org.codehaus.commons.compiler.java8.java.util.function.Consumer, org.codehaus.commons.compiler.java9.java.lang.module.ModuleFinder, .ModuleReference, org.codehaus.commons.compiler.util.resource.LocatableResource, .Resource, .ResourceFinder, org.codehaus.commons.nullanalysis.NotNullByDefault, .Nullable

Utility methods around the java.lang.ClassLoader.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
public static final ClassLoader
BOOTCLASSPATH_CLASS_LOADER

The ClassLoader that loads the classes on the currently executing JVM's "boot class path", i.e. the JARs in the JRE's "lib" and "lib/ext" directories, but not the JARs and class directories specified through the --classpath command line option.

private static final ClassLoaders.SubresourceGetter
public static final ClassLoader
CLASSPATH_CLASS_LOADER

The ClassLoader that loads the classes on the currently executing JVM's "class path", i.e. the JARs in the JRE's "lib" and "lib/ext" directories, and the JARs and class directories specified through the class path.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static URL
fileUrl(File file)

private static Map<? extends String, ? extends URL>
getBootclasspathSubresourcesOf(final String name, boolean includeDirectories, final boolean recurse)

Finds subresources on the JVM's bootstrap classpath.

private static Map<String, URL>
getFileResources(URL fileUrl, String namePrefix, boolean includeDirectories, boolean recurse)

public static ClassLoader
public static Map<String, URL>

Returns:

Keys ending with a slash map to "directory resources", the other keys map to "content resources"
getSubresources
(ClassLoader
The class loader to use; null means use the system class loader
classLoader
,
final String
No leading slash
name
,
boolean includeDirectories, final boolean recurse)

Returns a name-to-URL mapping of all resources "under" a given directory name.

private static Map<String, URL>
getSubresources(URL jarFileUrl, JarFile jarFile, String namePrefix, boolean includeDirectories, boolean recurse)

public static Map<String, URL>

Returns:

Keys ending with a slash map to "directory resources", the other keys map to "content resources"
getSubresourcesOf
(URL root, String rootName, boolean includeDirectories, boolean recurse)

Returns a name-to-URL mapping of all resources "under" a given root resource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BOOTCLASSPATH_CLASS_LOADERback to summary
public static final ClassLoader BOOTCLASSPATH_CLASS_LOADER

The ClassLoader that loads the classes on the currently executing JVM's "boot class path", i.e. the JARs in the JRE's "lib" and "lib/ext" directories, but not the JARs and class directories specified through the --classpath command line option.

BOOTCLASSPATH_SUBRESOURCES_OFback to summary
private static final ClassLoaders.SubresourceGetter BOOTCLASSPATH_SUBRESOURCES_OF
CLASSPATH_CLASS_LOADERback to summary
public static final ClassLoader CLASSPATH_CLASS_LOADER

The ClassLoader that loads the classes on the currently executing JVM's "class path", i.e. the JARs in the JRE's "lib" and "lib/ext" directories, and the JARs and class directories specified through the class path.

Constructor Detail

ClassLoadersback to summary
private ClassLoaders()

Method Detail

fileUrlback to summary
private static URL fileUrl(File file)
getBootclasspathSubresourcesOfback to summary
private static Map<? extends String, ? extends URL> getBootclasspathSubresourcesOf(final String name, boolean includeDirectories, final boolean recurse) throws IOException

Finds subresources on the JVM's bootstrap classpath. This is kind of tricky because the .jar files on the BOOTCLASSPATH don't contain "directory entries".

getFileResourcesback to summary
private static Map<String, URL> getFileResources(URL fileUrl, String namePrefix, boolean includeDirectories, boolean recurse)
getsResourceAsStreamback to summary
public static ClassLoader getsResourceAsStream(final ResourceFinder finder, ClassLoader parent)

Creates and returns a ClassLoader that implements ClassLoader#getResourceAsStream(String) via a ResourceFinder.

ClassLoader#getResource(String) returns a non-null value iff then resoure finder finds a LocatableResource.

Notice that ClassLoader#getResources(String) is not overridden.

getSubresourcesback to summary
public static Map<String, URL> getSubresources(ClassLoader classLoader, final String name, boolean includeDirectories, final boolean recurse) throws IOException

Returns a name-to-URL mapping of all resources "under" a given directory name.

Iff the name does not end with a slash, then calling this method is equivalent with calling ClassLoader#getResource(String).

Otherwise, if the name does end with a slash, then this method returns a name-to-URL mapping of all content resources who's names begin with the given name. Iff recurse is false, then only immediate subresources are included. Iff includeDirectories is true, then also directory resources are included in the result set; their names all ending with a slash.

If multiple resources have the name, then the resources are retrieved from the first occurrence.

Parameters
classLoader:ClassLoader

The class loader to use; null means use the system class loader

name:String

No leading slash

Returns:Map<String, URL>

Keys ending with a slash map to "directory resources", the other keys map to "content resources"

getSubresourcesback to summary
private static Map<String, URL> getSubresources(URL jarFileUrl, JarFile jarFile, String namePrefix, boolean includeDirectories, boolean recurse)
getSubresourcesOfback to summary
public static Map<String, URL> getSubresourcesOf(URL root, String rootName, boolean includeDirectories, boolean recurse) throws IOException

Returns a name-to-URL mapping of all resources "under" a given root resource.

If the root designates a "content resource" (as opposed to a "directory resource"), then the method returns Collections.singletonMap(name, rootName).

Otherwise, if the root designates a "directory resource", then this method returns a name-to-URL mapping of all content resources that are located "under" the root resource. Iff recurse is false, then only immediate subresources are included. Iff includeDirectories is true, then directory resources are also included in the result set; their names all ending with a slash.

Returns:Map<String, URL>

Keys ending with a slash map to "directory resources", the other keys map to "content resources"

org.codehaus.commons.compiler.lang back to summary

pack-priv Interface ClassLoaders.SubresourceGetter


See Also
SubresourceGetter#get(String, boolean, boolean)

Method Summary

Modifier and TypeMethod and Description
public Map<? extends String, ? extends URL>

Returns:

All resources that exist "under" a given resource name
get
(String name, boolean includeDirectories, boolean recurse)

Method Detail

getback to summary
public Map<? extends String, ? extends URL> get(String name, boolean includeDirectories, boolean recurse) throws IOException
Returns:Map<? extends String, ? extends URL>

All resources that exist "under" a given resource name