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 Object implements ResourceLoader
Simple `ResourceLoader` that opens resource files from the local file system, optionally resolving against a base directory.

This loader wraps a delegate `ResourceLoader` that 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 a `ClassLoader` is needed.

You can chain several `FilesystemResourceLoader`s to allow lookup of files in more than one base directory.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FilesystemResourceLoader(Path baseDirectory, ClassLoader delegate)`
  Creates a resource loader that resolves resources against the given base directory.
  `FilesystemResourceLoader(Path baseDirectory, Module delegate)`
  Creates a resource loader that resolves resources against the given base directory.
  `FilesystemResourceLoader(Path baseDirectory, ResourceLoader delegate)`
  Creates a resource loader that resolves resources against the given base directory.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> Class<? extends T>`
  `findClass(String cname, Class<T> expectedType)`
  `<T> T`
  `newInstance(String cname, Class<T> expectedType)`
  `InputStream`
  `openResource(String resource)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FilesystemResourceLoader

    public FilesystemResourceLoader(Path baseDirectory, ClassLoader delegate)
    Creates a resource loader that resolves resources against the given base directory. Files not found in file system and class lookups are delegated to `ClassLoader`.

    To use this constructor with the Java Module System, you must open all modules that contain resources to the `org.apache.lucene.core` module, otherwise resources can't be looked up. It is recommended to use `FilesystemResourceLoader(Path, Module)` for such use cases as this would limit to certain modules.

  - ### FilesystemResourceLoader

    public FilesystemResourceLoader(Path baseDirectory, Module delegate)
    Creates a resource loader that resolves resources against the given base directory. Files not found in file system and class lookups are delegated to `ModuleResourceLoader`.

    To use this constructor, you must open the module to the `org.apache.lucene.core` module, otherwise resources can't be looked up.

  - ### FilesystemResourceLoader

    public FilesystemResourceLoader(Path baseDirectory, ResourceLoader delegate)
    Creates a resource loader that resolves resources against the given base directory. Files not found in file system and class lookups are delegated to the given delegate `ResourceLoader`.

- ## Method Details

  - ### openResource

    public InputStream openResource(String resource) throws IOException
    Specified by:
      `openResource` in interface `ResourceLoader`
    Throws:
      `IOException`

  - ### newInstance

    public <T> T newInstance(String cname, Class<T> expectedType)
    Specified by:
      `newInstance` in interface `ResourceLoader`

  - ### findClass

    public <T> Class<? extends T> findClass(String cname, Class<T> expectedType)
    Specified by:
      `findClass` in interface `ResourceLoader`