Package org.openstreetmap.josm.tools
Class ResourceProvider
- java.lang.Object
-
- org.openstreetmap.josm.tools.ResourceProvider
-
public final class ResourceProvider extends Object
Unified provider that looks up for resource in various classloaders (josm, plugins, etc.).- Since:
- 15416
-
-
Field Summary
Fields Modifier and Type Field Description private static Set<ClassLoader>
classLoaders
set of class loaders to take resources from
-
Constructor Summary
Constructors Modifier Constructor Description private
ResourceProvider()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addAdditionalClassLoader(ClassLoader additionalClassLoader)
Add an additional class loader to search image for.static boolean
addAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders)
Add a collection of additional class loaders to search image for.private static <T> T
getFirstNotNull(Function<ClassLoader,T> function)
static URL
getResource(String name)
Finds the resource with the given name.static InputStream
getResourceAsStream(String name)
Finds a resource with a given name, with robustness to known JDK bugs.
-
-
-
Field Detail
-
classLoaders
private static final Set<ClassLoader> classLoaders
set of class loaders to take resources from
-
-
Constructor Detail
-
ResourceProvider
private ResourceProvider()
-
-
Method Detail
-
addAdditionalClassLoader
public static boolean addAdditionalClassLoader(ClassLoader additionalClassLoader)
Add an additional class loader to search image for.- Parameters:
additionalClassLoader
- class loader to add to the internal set- Returns:
true
if the set changed as a result of the call
-
addAdditionalClassLoaders
public static boolean addAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders)
Add a collection of additional class loaders to search image for.- Parameters:
additionalClassLoaders
- class loaders to add to the internal set- Returns:
true
if the set changed as a result of the call
-
getFirstNotNull
private static <T> T getFirstNotNull(Function<ClassLoader,T> function)
-
getResource
public static URL getResource(String name)
Finds the resource with the given name.- Parameters:
name
- The resource name- Returns:
- A
URL
object for reading the resource, ornull
if the resource could not be found or the invoker doesn't have adequate privileges to get the resource. - See Also:
ClassLoader.getResource(java.lang.String)
-
getResourceAsStream
public static InputStream getResourceAsStream(String name)
Finds a resource with a given name, with robustness to known JDK bugs.- Parameters:
name
- name of the desired resource- Returns:
- A
InputStream
object ornull
if no resource with this name is found
-
-