Package nl.rrd.wool.utils
Class ClassLoaderResourceLocator
- java.lang.Object
-
- nl.rrd.wool.utils.ClassLoaderResourceLocator
-
- All Implemented Interfaces:
ResourceLocator
public class ClassLoaderResourceLocator extends Object implements ResourceLocator
This resource locator can locate resources using the class loader or a specified class. When using a specified class, the resource is searched from the package path of that class. Otherwise the resource is searched from the root.
-
-
Constructor Summary
Constructors Constructor Description ClassLoaderResourceLocator()Constructs a new resource locator that will locate resources using the class loader.ClassLoaderResourceLocator(Class<?> loadClass)Constructs a new resource locator that will locate resources using the specified class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStreamopenResource(String path)Opens the resource at the specified path.booleanresourceExists(String path)Returns whether the specified resource exists.
-
-
-
Constructor Detail
-
ClassLoaderResourceLocator
public ClassLoaderResourceLocator()
Constructs a new resource locator that will locate resources using the class loader.
-
ClassLoaderResourceLocator
public ClassLoaderResourceLocator(Class<?> loadClass)
Constructs a new resource locator that will locate resources using the specified class. If you set the load class to null, it will locate resources using the class loader.- Parameters:
loadClass- the load class or null
-
-
Method Detail
-
resourceExists
public boolean resourceExists(String path)
Description copied from interface:ResourceLocatorReturns whether the specified resource exists.- Specified by:
resourceExistsin interfaceResourceLocator- Parameters:
path- the resource path- Returns:
- true if the resource exists, false otherwise
-
openResource
public InputStream openResource(String path) throws IOException
Description copied from interface:ResourceLocatorOpens the resource at the specified path.- Specified by:
openResourcein interfaceResourceLocator- Parameters:
path- the resource path- Returns:
- the input stream
- Throws:
IOException- if the resource doesn't exist or can't be opened
-
-