Class URLs


  • public final class URLs
    extends Object
    • Method Detail

      • listContents

        public static Collection<URL> listContents​(URL directory)
        Recursively lists the contents of the referenced directory. Directories are excluded from the result. Supported protocols include file and jar.
        Parameters:
        directory - The directory whose contents should be listed.
        Returns:
        A collection of URLs representing the directory's contents.
        See Also:
        listContents(URL, boolean, boolean)
      • listContents

        public static Collection<URL> listContents​(URL directory,
                                                   boolean recurse,
                                                   boolean filesOnly)
        Lists all contents of the referenced directory. Supported protocols include file and jar.
        Parameters:
        directory - The directory whose contents should be listed.
        recurse - Whether to list contents recursively, as opposed to only the directory's direct contents.
        filesOnly - Whether to exclude directories in the resulting collection of contents.
        Returns:
        A collection of URLs representing the directory's contents.
      • appendContents

        public static Collection<URL> appendContents​(Collection<URL> result,
                                                     URL directory)
        Recursively adds contents from the referenced directory to an existing collection. Directories are excluded from the result. Supported protocols include file and jar.
        Parameters:
        result - The collection to which contents should be added.
        directory - The directory whose contents should be listed.
        Returns:
        A collection of URLs representing the directory's contents.
        See Also:
        appendContents(Collection, URL, boolean, boolean)
      • appendContents

        public static Collection<URL> appendContents​(Collection<URL> result,
                                                     URL directory,
                                                     boolean recurse,
                                                     boolean filesOnly)
        Add contents from the referenced directory to an existing collection. Supported protocols include file and jar.
        Parameters:
        result - The collection to which contents should be added.
        directory - The directory whose contents should be listed.
        recurse - Whether to append contents recursively, as opposed to only the directory's direct contents.
        filesOnly - Whether to exclude directories in the resulting collection of contents.
        Returns:
        A collection of URLs representing the directory's contents.
      • toFile

        public static File toFile​(URL url)
        Converts the given URL to its corresponding File.

        This method is similar to calling new File(url.toURI()) except that it also handles "jar:file:" URLs, returning the path to the JAR file.

        Parameters:
        url - The URL to convert.
        Returns:
        A file path suitable for use with e.g. FileInputStream
        Throws:
        IllegalArgumentException - if the URL does not correspond to a file.
      • toFile

        public static File toFile​(String url)
        Converts the given URL string to its corresponding File.
        Parameters:
        url - The URL to convert.
        Returns:
        A file path suitable for use with e.g. FileInputStream
        Throws:
        IllegalArgumentException - if the URL does not correspond to a file.