Class ClassLoaders
ClassLoader
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClassLoader
TheClassLoader
that loads the classes on the currently executing JVM's "boot class path", i.e.private static final ClassLoaders.SubresourceGetter
static final ClassLoader
TheClassLoader
that loads the classes on the currently executing JVM's "class path", i.e. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static URL
getBootclasspathSubresourcesOf
(String name, boolean includeDirectories, boolean recurse) Finds subresources on the JVM's bootstrap classpath.getFileResources
(URL fileUrl, String namePrefix, boolean includeDirectories, boolean recurse) static ClassLoader
getsResourceAsStream
(ResourceFinder finder, ClassLoader parent) Creates and returns aClassLoader
that implementsClassLoader.getResourceAsStream(String)
via aResourceFinder
.getSubresources
(ClassLoader classLoader, String name, boolean includeDirectories, boolean recurse) Returns a name-to-URL mapping of all resources "under" a given directory name.getSubresources
(URL jarFileUrl, JarFile jarFile, String namePrefix, boolean includeDirectories, boolean recurse) getSubresourcesOf
(URL root, String rootName, boolean includeDirectories, boolean recurse) Returns a name-to-URL mapping of all resources "under" a given root resource.
-
Field Details
-
CLASSPATH_CLASS_LOADER
TheClassLoader
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. -
BOOTCLASSPATH_CLASS_LOADER
TheClassLoader
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_OF
-
-
Constructor Details
-
ClassLoaders
private ClassLoaders()
-
-
Method Details
-
getsResourceAsStream
Creates and returns aClassLoader
that implementsClassLoader.getResourceAsStream(String)
via aResourceFinder
.ClassLoader.getResource(String)
returns a non-null
value iff then resoure finder finds aLocatableResource
.Notice that
ClassLoader.getResources(String)
is not overridden. -
getSubresources
public static Map<String,URL> getSubresources(@Nullable ClassLoader classLoader, String name, boolean includeDirectories, 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 istrue
, 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
- The class loader to use;null
means use the system class loadername
- No leading slash- Returns:
- Keys ending with a slash map to "directory resources", the other keys map to "content resources"
- Throws:
IOException
-
getBootclasspathSubresourcesOf
private static Map<? extends String,? extends URL> getBootclasspathSubresourcesOf(String name, boolean includeDirectories, 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".- Throws:
IOException
-
getSubresourcesOf
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 istrue
, then directory resources are also included in the result set; their names all ending with a slash.- Returns:
- Keys ending with a slash map to "directory resources", the other keys map to "content resources"
- Throws:
IOException
-
getSubresources
-
getFileResources
-
fileUrl
-