Interface ResourceLoader

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
JarFileResourceLoader, PathResourceLoader, URLResourceLoader

public interface ResourceLoader extends Closeable
A loader which can find resources by their path.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ResourceLoader
    A resource loader containing no resources.
  • Method Summary

    Modifier and Type
    Method
    Description
    default URL
    Returns the base URL for this loader.
    default void
    Release any system resources or allocations associated with this resource loader.
    Find a resource from this loader.
    Get a child resource loader for the given child path.
    default Manifest
    Get the manifest for this resource loader, if any.
    default void
    Hint that this resource loader is unlikely to be used in the near future.
  • Field Details

    • EMPTY

      static final ResourceLoader EMPTY
      A resource loader containing no resources.
  • Method Details

    • findResource

      Resource findResource(String path) throws IOException
      Find a resource from this loader.
      Parameters:
      path - the resource path (must not be null)
      Returns:
      the loaded resource, or null if no resource is found at the given path
      Throws:
      IOException - if the resource could not be loaded
    • baseUrl

      default URL baseUrl()
      Returns the base URL for this loader.
      Returns:
      the base URL for this loader
    • getChildLoader

      default ResourceLoader getChildLoader(String path)
      Get a child resource loader for the given child path. This method always returns a resource loader, even if the path does not exist. Closing the child loader does not close the enclosing loader.
      Parameters:
      path - the relative sub-path (must not be null)
      Returns:
      the resource loader (not null, may be empty)
    • manifest

      default Manifest manifest() throws IOException
      Get the manifest for this resource loader, if any. The default implementation constructs a new instance every time, so the caller should avoid repeated invocation of this method, caching as needed.
      Returns:
      the manifest, or null if no manifest was found
      Throws:
      IOException - if the manifest resource could not be loaded
    • release

      default void release()
      Hint that this resource loader is unlikely to be used in the near future.
    • close

      default void close()
      Release any system resources or allocations associated with this resource loader.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable