Interface ResourceLoader


  • public interface ResourceLoader
    A loader for resources.

    The Java module system does not allow access to non-exported packages. That also includes access to resources in folders that don't match exported packages. The TestResource annotation will fail to load such resources. This interface makes it possible to define a custom resource loader that does have access to non-exported resources. In most cases, an implementation will simply delegate to Class.getResourceAsStream(String) to access resources from its own module.

    Author:
    Rob Spoor
    Since:
    3.2
    • Method Detail

      • loadResource

        InputStream loadResource​(Class<?> c,
                                 String path)
        Opens a resource if possible. The resource will be loaded relative to the class where the field, constructor or method is defined.
        Parameters:
        c - The class that acts as base path for the resource to open.
        path - The path to the resource, relative to the given class.
        Returns:
        An InputStream to the resource, or null if the resource could not be found.