public class BasicResourceFinder extends Object implements ResourceFinder
If the
The default behavior first searches the working filesystem directory for matching files.
Path traversals outside the working directory are not allowed for security reasons.
Support is provided for recursively searching for files up the class hierarchy chain.
ResourceFinder.Null
Modifier and Type | Field and Description |
---|---|
static BasicResourceFinder |
INSTANCE
Reusable instance.
|
Constructor and Description |
---|
BasicResourceFinder()
Constructor.
|
BasicResourceFinder(boolean includeFileSystem,
boolean recursive)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected InputStream |
findClasspathResource(Class<?> baseClass,
String name,
Locale locale)
Workhorse method for retrieving a resource from the classpath.
|
protected InputStream |
findFileSystemResource(String name,
Locale locale)
Workhorse method for retrieving a resource from the file system.
|
InputStream |
findResource(Class<?> baseClass,
String name,
Locale locale)
Returns the contents of the resource with the specified name.
|
public static final BasicResourceFinder INSTANCE
public BasicResourceFinder()
Same as calling
public BasicResourceFinder(boolean includeFileSystem, boolean recursive)
includeFileSystem
- Search the working filesystem directory for matching resources first. The default is recursive
- Recursively search up the parent class hierarchy for resources.public InputStream findResource(Class<?> baseClass, String name, Locale locale) throws IOException
ResourceFinder
findResource
in interface ResourceFinder
baseClass
- The class to use to retrieve the resource.name
- The resource name.
See Class.getResource(String)
for format.locale
- The locale of the resource to retrieve.
IOException
- Thrown by underlying stream.protected InputStream findClasspathResource(Class<?> baseClass, String name, Locale locale) throws IOException
This method can be overridden by subclasses to provide customized handling of resource retrieval from the classpath.
baseClass
- The base class providing the classloader.name
- The resource name.locale
- The resource locale.
IOException
- Thrown by underlying stream.protected InputStream findFileSystemResource(String name, Locale locale) throws IOException
This method can be overridden by subclasses to provide customized handling of resource retrieval from file systems.
name
- The resource name.locale
- The resource locale.
IOException
- Thrown by underlying stream.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.