org.apache.lucene.analysis.util

## Class ClasspathResourceLoader

- java.lang.Object
- - org.apache.lucene.analysis.util.ClasspathResourceLoader

- All Implemented Interfaces:
    ResourceLoader

      public final class ClasspathResourceLoader
      extends Object
      implements ResourceLoader

  Simple `ResourceLoader` that uses `ClassLoader.getResourceAsStream(String)` and `Class.forName(String,boolean,ClassLoader)` to open resources and classes, respectively.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClasspathResourceLoader()` Deprecated. You should not use this ctor, because it uses the thread's context class loader, which is bad programming style. Please specify a reference class or a `ClassLoader` instead.
    `ClasspathResourceLoader(Class<?> clazz)` Creates an instance using the context classloader to load Resources and classes Resources are resolved relative to the given class, if path is not absolute.
    `ClasspathResourceLoader(ClassLoader loader)` Creates an instance using the given classloader to load Resources and classes.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> Class<? extends T>` | `findClass(String cname, Class<T> expectedType)` Finds class of the name and expected type
    `<T> T` | `newInstance(String cname, Class<T> expectedType)` Creates an instance of the name and expected type
    `InputStream` | `openResource(String resource)` Opens a named resource

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

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

- - ### Constructor Detail

    - #### ClasspathResourceLoader

          @Deprecated
          public ClasspathResourceLoader()

      Deprecated. You should not use this ctor, because it uses the thread's context class loader, which is bad programming style. Please specify a reference class or a `ClassLoader` instead.
      Creates an instance using the context classloader to load resources and classes. Resource paths must be absolute.
      See Also:
        `ClasspathResourceLoader(ClassLoader)`, `ClasspathResourceLoader(Class)`

    - #### ClasspathResourceLoader

          public ClasspathResourceLoader(ClassLoader loader)

      Creates an instance using the given classloader to load Resources and classes. Resource paths must be absolute.

    - #### ClasspathResourceLoader

          public ClasspathResourceLoader(Class<?> clazz)

      Creates an instance using the context classloader to load Resources and classes Resources are resolved relative to the given class, if path is not absolute.

  - ### Method Detail

    - #### openResource

          public InputStream openResource(String resource)
                                   throws IOException

      Description copied from interface: `ResourceLoader`
      Opens a named resource
      Specified by:
        `openResource` in interface `ResourceLoader`
      Throws:
        `IOException`

    - #### findClass

          public <T> Class<? extends T> findClass(String cname,
                                                  Class<T> expectedType)

      Description copied from interface: `ResourceLoader`
      Finds class of the name and expected type
      Specified by:
        `findClass` in interface `ResourceLoader`

    - #### newInstance

          public <T> T newInstance(String cname,
                                   Class<T> expectedType)

      Description copied from interface: `ResourceLoader`
      Creates an instance of the name and expected type
      Specified by:
        `newInstance` in interface `ResourceLoader`

Copyright © 2000-2022 Apache Software Foundation. All Rights Reserved.