public final class ClassLoaders extends Object
Modifier and Type | Method and Description |
---|---|
static URL[] |
getAllSubresources(ClassLoader classLoader,
String name,
boolean includeDirectories)
Returns the locations of all resources "under" a given directory name.
|
static Map<String,URL> |
getSubresources(ClassLoader classLoader,
String name,
boolean includeDirectories)
Equivalent with
getSubresources(ClassLoader, String, boolean, boolean) with the recurse
parameter set to true . |
static Map<String,URL> |
getSubresources(ClassLoader classLoader,
String name,
boolean includeDirectories,
boolean recurse)
Returns a name-to-URL mapping of all resources "under" a given directory name.
|
static Map<String,URL> |
getSubresourcesOf(URL root,
String rootName,
boolean includeDirectories)
Equivalent with
getSubresourcesOf(URL, String, boolean, boolean) with the recurse
parameter set to true . |
static Map<String,URL> |
getSubresourcesOf(URL root,
String rootName,
boolean includeDirectories,
boolean recurse)
Returns a name-to-URL mapping of all resources "under" a given root resource.
|
public static URL[] getAllSubresources(@Nullable ClassLoader classLoader, String name, boolean includeDirectories) throws IOException
Iff the name does not end with a slash, then calling this method is equivalent with calling
ClassLoader.getResources(String)
.
Otherwise, if the name does end with a slash, then this method returns the locations of
all resources who's names begin with the given name. Iff includeDirectories is
true
, then name, and all the subdirectories underneath, are also included in the result
set.
Notice that it is not (reliably) possible to determine the names of the retrieved resources; to
get these, use getSubresources(ClassLoader, String, boolean)
.
classLoader
- The class loader to use; null
means use the system class loadername
- No leading slashIOException
public static Map<String,URL> getSubresources(@Nullable ClassLoader classLoader, String name, boolean includeDirectories) throws IOException
getSubresources(ClassLoader, String, boolean, boolean)
with the recurse
parameter set to true
.IOException
public static Map<String,URL> getSubresources(@Nullable ClassLoader classLoader, String name, boolean includeDirectories, boolean recurse) throws IOException
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.
Directories on the BOOTCLASSPATH do not work, e.g. "java/lang/"; directories on the CLASSPATH do work (e.g. "de/unkrig/commons/lang/");.
classLoader
- The class loader to use; null
means use the system class loadername
- No leading slashIOException
public static Map<String,URL> getSubresourcesOf(URL root, String rootName, boolean includeDirectories) throws IOException
getSubresourcesOf(URL, String, boolean, boolean)
with the recurse
parameter set to true
.IOException
public static Map<String,URL> getSubresourcesOf(URL root, String rootName, boolean includeDirectories, boolean recurse) throws IOException
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.
IOException
Copyright © 2018 Arno Unkrig. All rights reserved.