Package org.apache.lucene.analysis.util
Class FilesystemResourceLoader
- java.lang.Object
-
- org.apache.lucene.analysis.util.FilesystemResourceLoader
-
- All Implemented Interfaces:
ResourceLoader
public final class FilesystemResourceLoader extends java.lang.Object implements ResourceLoader
SimpleResourceLoaderthat opens resource files from the local file system, optionally resolving against a base directory.This loader wraps a delegate
ResourceLoaderthat is used to resolve all files, the current base directory does not contain.newInstance(java.lang.String, java.lang.Class<T>)is always resolved against the delegate, as aClassLoaderis needed.You can chain several
FilesystemResourceLoaders to allow lookup of files in more than one base directory.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.file.PathbaseDirectoryprivate ResourceLoaderdelegate
-
Constructor Summary
Constructors Constructor Description FilesystemResourceLoader(java.nio.file.Path baseDirectory)Deprecated.You should not use this ctor, because it uses the thread's context class loader as fallback for resource lookups, which is bad programming style.FilesystemResourceLoader(java.nio.file.Path baseDirectory, java.lang.ClassLoader delegate)Creates a resource loader that resolves resources against the given base directory (may benullto refer to CWD).FilesystemResourceLoader(java.nio.file.Path baseDirectory, ResourceLoader delegate)Creates a resource loader that resolves resources against the given base directory (may benullto refer to CWD).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.lang.Class<? extends T>findClass(java.lang.String cname, java.lang.Class<T> expectedType)Finds class of the name and expected type<T> TnewInstance(java.lang.String cname, java.lang.Class<T> expectedType)Creates an instance of the name and expected typejava.io.InputStreamopenResource(java.lang.String resource)Opens a named resource
-
-
-
Field Detail
-
baseDirectory
private final java.nio.file.Path baseDirectory
-
delegate
private final ResourceLoader delegate
-
-
Constructor Detail
-
FilesystemResourceLoader
@Deprecated public FilesystemResourceLoader(java.nio.file.Path baseDirectory)
Deprecated.You should not use this ctor, because it uses the thread's context class loader as fallback for resource lookups, which is bad programming style. Please specify aClassLoaderinstead.Creates a resource loader that resolves resources against the given base directory (may benullto refer to CWD). Files not found in file system and class lookups are delegated to context classloader.
-
FilesystemResourceLoader
public FilesystemResourceLoader(java.nio.file.Path baseDirectory, java.lang.ClassLoader delegate)Creates a resource loader that resolves resources against the given base directory (may benullto refer to CWD). Files not found in file system and class lookups are delegated to context classloader.
-
FilesystemResourceLoader
public FilesystemResourceLoader(java.nio.file.Path baseDirectory, ResourceLoader delegate)Creates a resource loader that resolves resources against the given base directory (may benullto refer to CWD). Files not found in file system and class lookups are delegated to the given delegateResourceLoader.
-
-
Method Detail
-
openResource
public java.io.InputStream openResource(java.lang.String resource) throws java.io.IOExceptionDescription copied from interface:ResourceLoaderOpens a named resource- Specified by:
openResourcein interfaceResourceLoader- Throws:
java.io.IOException
-
newInstance
public <T> T newInstance(java.lang.String cname, java.lang.Class<T> expectedType)Description copied from interface:ResourceLoaderCreates an instance of the name and expected type- Specified by:
newInstancein interfaceResourceLoader
-
findClass
public <T> java.lang.Class<? extends T> findClass(java.lang.String cname, java.lang.Class<T> expectedType)Description copied from interface:ResourceLoaderFinds class of the name and expected type- Specified by:
findClassin interfaceResourceLoader
-
-