Class ResourceUtil

    • Constructor Detail

      • ResourceUtil

        public ResourceUtil()
    • Method Detail

      • findResource

        public static URL findResource​(ClassLoader classloader,
                                       String name)
        Invokes the findResource method of the given class loader.

        In case of URLClassLoader the underlying public method is invoked directly. Otherwise the protected method of the ClassLoader is invoked through the reflection.

        Parameters:
        classloader - the class loader object.
        name - the name of the resource (parameter passed to the underlying findResource method)
        Returns:
        a URL for the resource, or null if the resource could not be found.
        See Also:
        URLClassLoader.findResource(String)
      • toURLs

        public static URL[] toURLs​(Enumeration<URL> en)
        Converts the Enumeration to an array of URLs.
        Parameters:
        en - an Enumeration of URLs (not null).
        Returns:
        an array of URLs.
        See Also:
        toEnumeration(URL[])
      • toEnumeration

        public static Enumeration<URL> toEnumeration​(URL[] urls)
        Converts the array of URLs to an Enumeration.
        Parameters:
        urls - an array of URLs (not null).
        Returns:
        an Enumeration of URLs
        See Also:
        toURLs(Enumeration)
      • concat

        public static URL[] concat​(URL[] first,
                                   URL[] second)
        Concatenates two arrays of URLs into one.
        Parameters:
        first - first array of URLs (maybe null)
        second - second array of URLs (maybe null)
        Returns:
        array of URLs containing all elements (maybe null).
      • concatClassPath

        public static String concatClassPath​(String first,
                                             String second)
        Concatenates two class paths.
        Parameters:
        first - first class path.
        second - second class path.
        Returns:
        result containing both class path entries.
      • toClassPath

        public static String toClassPath​(URL[] urls)
        Converts an array of URLs into a class path.

        URL will be separated by File.pathSeparators.

        Parameters:
        urls - array of URLs (maybe null)
        Returns:
        class path.
      • getClassResource

        public static org.zeroturnaround.javarebel.Resource getClassResource​(org.zeroturnaround.javarebel.ResourceSource source,
                                                                             String className)
        Finds a class resource using a resource finder.

        This is used in BaseClassResourceSource which is the base implementation of ClassResourceSource.

        The class name is converted to a resource name by replacing all dots with slashes and adding .class to the end.

        Parameters:
        source - the resource finder.
        className - the name of the class.
        Returns:
        Resource that corresponds to the given class.
        See Also:
        ResourceSource, ClassResourceSource, BaseClassResourceSource
      • asArray

        public static org.zeroturnaround.javarebel.Resource[] asArray​(org.zeroturnaround.javarebel.Resource resource)
        Creates a one-element array of Resources.
        Parameters:
        resource - the Resource element.
        Returns:
        a one-element array with the given element or null if the element was null.
      • asResource

        public static org.zeroturnaround.javarebel.Resource asResource​(URL url)
        Creates a new Resource object based on the given URL.

        If a file or vfsfile protocol is used a FileResource will be created. Otherwise a new URLResource instance will be returned.

        Parameters:
        url - the resource URL.
        Returns:
        new Resource object based on the given URL.
      • asResources

        public static org.zeroturnaround.javarebel.Resource[] asResources​(URL[] urls)
        Creates an array of Resource objects based on the given URL objects.
        Parameters:
        urls - the resource URL objects.
        Returns:
        new Resource objects.
      • asResources

        public static org.zeroturnaround.javarebel.Resource[] asResources​(Enumeration<URL> urls)
        Creates an array of Resource objects based on the given URL objects.
        Parameters:
        urls - the resource URL objects.
        Returns:
        new Resource objects.
      • asResources

        public static org.zeroturnaround.javarebel.Resource[] asResources​(List<URL> urls)
        Creates an array of Resource objects based on the given URL objects.
        Parameters:
        urls - the resource URL objects.
        Returns:
        new Resource objects.
      • asRawInputStream

        public static InputStream asRawInputStream​(URL url)
        Creates a raw input stream from the given URL.
        Parameters:
        url - URL object.
        Returns:
        a raw input stream.
        See Also:
        asInputStream(URL)
      • asInputStream

        public static InputStream asInputStream​(URL url)
        Creates a byte input stream from the given URL.
        Parameters:
        url - URL object.
        Returns:
        a byte input stream.
        See Also:
        asRawInputStream(URL)
      • getFileFromURL

        public static File getFileFromURL​(URL url)
        Converts a URL into a File.
        Parameters:
        url - URL.
        Returns:
        File object.