Class ResourceUtils


  • public final class ResourceUtils
    extends java.lang.Object
    Provides utility methods for resources.
    Author:
    Middleware Services
    • Method Detail

      • setCustomResourceLoaders

        public static void setCustomResourceLoaders​(ResourceLoader... loaders)
        Sets the custom resource loaders.
        Parameters:
        loaders - custom resource loaders
      • isResource

        public static boolean isResource​(java.lang.String path,
                                         ResourceLoader... loaders)
        Returns whether the supplied path is supported by a ResourceLoader.
        Parameters:
        path - to inspect
        loaders - to invoke ResourceLoader.supports(String) on
        Returns:
        whether the supplied string represents a resource
      • isResource

        public static boolean isResource​(java.lang.String path)
        Invokes isResource(String, ResourceLoader...) with DEFAULT_RESOURCE_LOADERS.
        Parameters:
        path - to inspect
        Returns:
        whether the supplied string represents a resource
      • getResource

        public static java.io.InputStream getResource​(java.lang.String path,
                                                      ResourceLoader... loaders)
                                               throws java.io.IOException
        Attempts to find a ResourceLoader that supports the supplied path. If found, that resource loader is used to load the input stream.
        Parameters:
        path - that designates a resource
        loaders - to invoke ResourceLoader.load(String) on
        Returns:
        input stream to read the resource
        Throws:
        java.io.IOException - if the resource cannot be read
        java.lang.IllegalArgumentException - if path is not supported
      • getResource

        public static java.io.InputStream getResource​(java.lang.String path)
                                               throws java.io.IOException
        Invokes getResource(String, ResourceLoader...) with DEFAULT_RESOURCE_LOADERS.
        Parameters:
        path - that designates a resource
        Returns:
        input stream to read the resource
        Throws:
        java.io.IOException - if the resource cannot be read
        java.lang.IllegalArgumentException - if path is not supported
      • readResource

        public static byte[] readResource​(java.lang.String path)
                                   throws java.io.IOException
        Reads the data from the supplied resource path. See getResource(String) and LdapUtils.readInputStream(InputStream).
        Parameters:
        path - that designates a resource
        Returns:
        bytes read from the resource
        Throws:
        java.io.IOException - if the resource cannot be read