ur_rna.Utilities

## Class ResourceLoader

- java.lang.Object
- - ur_rna.Utilities.ResourceLoader

-     public class ResourceLoader
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.util.List<java.lang.String>` | `allSearchDirs`
    `protected java.lang.String` | `baseDir`
    `protected java.lang.ClassLoader` | `loader`
    `protected static char` | `pathSep`
    `protected java.util.List<java.lang.String>` | `searchDirs`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceLoader()`
    `ResourceLoader(java.lang.Class resourcePeerClass, java.lang.String pathRelativeToClassPackage)` Create a new ResourceLoader and set its resource directory based on the package name of the specified class by converting each dot (.) in the package name to a slash (/).
    `ResourceLoader(java.lang.String resourceBaseDir)`
    `ResourceLoader(java.lang.String resourceBaseDir, java.lang.ClassLoader loader)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addSearchDir(java.lang.String dir)` Add a sub-directory (relative to the resource base directory) that will be searched to find requested resources.
    `void` | `addSearchDirs(java.lang.String... dirs)` Add a list of sub-directories (relative to the resource base directory) that will be searched to find requested resources.
    `private static java.io.IOException` | `createNotFoundException(java.lang.String path)`
    `java.util.List<java.lang.String>` | `getAllSearchDirs()`
    `java.lang.String` | `getBaseDir()`
    `static java.lang.String` | `getDirFromPackage(java.lang.Class<?> c, java.lang.String relativeSubDir)`
    `static java.lang.String` | `getDirFromPackage(java.lang.Package p, java.lang.String relativeSubDir)`
    `java.lang.String` | `getResourceLocation(java.lang.String resourceName)` Returns the full path to a resource if it is found, or null otherwise.
    `java.util.List<java.lang.String>` | `getSearchDirs()`
    `java.io.InputStream` | `getStream(java.lang.String resourceName)` Searches for the specified resource in all search directories and returns an an InputStream representing the resource.
    `java.io.InputStream` | `getStream(java.lang.String resourceName, boolean ignoreMissing)`
    `boolean` | `hasResource(java.lang.String resourceName)` Determine whether the specified resource exists.
    `void` | `setBaseDir(java.lang.Class<?> resourcePeerClass, java.lang.String pathRelativeToClassPackage)` Set the resource directory based on the package name of the specified class by converting each dot (.) in the package name to a slash (/).
    `void` | `setBaseDir(java.lang.String pathRelativeToClassPath)`
    `void` | `setLoader(java.lang.ClassLoader c)`
    `java.io.InputStream` | `tryGetStream(java.lang.String resourceName)` Searches for the specified resource in all search directories and returns either an InputStream (if the resource is found) or null (if it cannot be found).

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

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

- - ### Field Detail

    - #### allSearchDirs

          private java.util.List<java.lang.String> allSearchDirs

    - #### baseDir

          protected java.lang.String baseDir

    - #### loader

          protected java.lang.ClassLoader loader

    - #### pathSep

          protected static final char pathSep

      See Also:
        Constant Field Values

    - #### searchDirs

          protected java.util.List<java.lang.String> searchDirs

  - ### Constructor Detail

    - #### ResourceLoader

          public ResourceLoader()

    - #### ResourceLoader

          public ResourceLoader(java.lang.Class resourcePeerClass,
                                java.lang.String pathRelativeToClassPackage)

      Create a new ResourceLoader and set its resource directory based on the package name of the specified class by converting each dot (.) in the package name to a slash (/). If sub-directory is also specified, it will be appended to the package-derived directory. E.g. `ResourceLoader(my.package.MyClass.class, "resources")` would set the resource base directory to `my/package/resources`.
      Parameters:
        `resourcePeerClass` - The Class from which to obtain the package name.
        `pathRelativeToClassPackage` - This specifies a sub-directory relative to the package-derived directory from which resources can be obtained. (This can be null or empty, in which case resources will be served directly from the package-derived directory).

    - #### ResourceLoader

          public ResourceLoader(java.lang.String resourceBaseDir)

    - #### ResourceLoader

          public ResourceLoader(java.lang.String resourceBaseDir,
                                java.lang.ClassLoader loader)

  - ### Method Detail

    - #### addSearchDir

          public void addSearchDir(java.lang.String dir)

      Add a sub-directory (relative to the resource base directory) that will be searched to find requested resources.
      Parameters:
        `dir` - The subdirectory to add. If the directory starts with a slash (/) it indicates that it is an absolute directory instead of being relative to the resource base directory.

    - #### addSearchDirs

          public void addSearchDirs(java.lang.String... dirs)

      Add a list of sub-directories (relative to the resource base directory) that will be searched to find requested resources.
      Parameters:
        `dirs` - A list of subdirectories to add. If a directory starts with a slash (/) it indicates that it is an absolute directory instead of being relative to the resource base directory.

    - #### createNotFoundException

          private static java.io.IOException createNotFoundException(java.lang.String path)

    - #### getAllSearchDirs

          public java.util.List<java.lang.String> getAllSearchDirs()

    - #### getBaseDir

          public java.lang.String getBaseDir()

    - #### getDirFromPackage

          public static java.lang.String getDirFromPackage(@NotNull
                                                           java.lang.Class<?> c,
                                                           java.lang.String relativeSubDir)

    - #### getDirFromPackage

          public static java.lang.String getDirFromPackage(@NotNull
                                                           java.lang.Package p,
                                                           java.lang.String relativeSubDir)

    - #### getResourceLocation

          public java.lang.String getResourceLocation(java.lang.String resourceName)

      Returns the full path to a resource if it is found, or null otherwise.

    - #### getSearchDirs

          public java.util.List<java.lang.String> getSearchDirs()

    - #### getStream

          public java.io.InputStream getStream(java.lang.String resourceName)
                                        throws java.io.IOException

      Searches for the specified resource in all search directories and returns an an InputStream representing the resource.
      Parameters:
        `resourceName` - The name of the resource to find.
      Returns:
        An InputStream representing the resource if it is found.
      Throws:
        `java.io.IOException` - - The specified resource was not found or could not be loaded.

    - #### getStream

          public java.io.InputStream getStream(java.lang.String resourceName,
                                               boolean ignoreMissing)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### hasResource

          public boolean hasResource(java.lang.String resourceName)

      Determine whether the specified resource exists.
      Parameters:
        `resourceName` - The resource to locate.
      Returns:
        True if the resource could be found in one of the search directories or false otherwise.

    - #### setBaseDir

          public void setBaseDir(@NotNull
                                 java.lang.Class<?> resourcePeerClass,
                                 java.lang.String pathRelativeToClassPackage)

      Set the resource directory based on the package name of the specified class by converting each dot (.) in the package name to a slash (/). If a non-empty sub-directory is also specified, it will be appended to the package-derived directory. E.g. `ResourceLoader(my.package.MyClass.class, "resources")` would set the resource base directory to `my/package/resources`.
      Parameters:
        `resourcePeerClass` - The Class from which to obtain the package name.
        `pathRelativeToClassPackage` - This specifies a sub-directory relative to the package-derived directory from which resources can be obtained. (This can be null or empty, in which case resources will be served directly from the package-derived directory).

    - #### setBaseDir

          public void setBaseDir(java.lang.String pathRelativeToClassPath)

    - #### setLoader

          public void setLoader(@Nullable
                                java.lang.ClassLoader c)

    - #### tryGetStream

          public java.io.InputStream tryGetStream(java.lang.String resourceName)

      Searches for the specified resource in all search directories and returns either an InputStream (if the resource is found) or null (if it cannot be found).
      Parameters:
        `resourceName` - The name of the resource to find.
      Returns:
        An InputStream representing the resource if it is found, or null otherwise.