Class ResourceURL


  • public class ResourceURL
    extends Object
    Helper methods for dealing with URL objects for local resources.
    • Method Detail

      • isDirectory

        public static boolean isDirectory​(URL resourceURL)
                                   throws URISyntaxException
        Returns true if the URL passed to it corresponds to a directory. This is slightly tricky due to some quirks of the JarFile API. Only jar:// and file:// URLs are supported.
        Parameters:
        resourceURL - the URL to check
        Returns:
        true if resource is a directory
        Throws:
        URISyntaxException
      • appendTrailingSlash

        public static URL appendTrailingSlash​(URL originalURL)
        Appends a trailing '/' to a URL object. Does not append a slash if one is already present.
        Parameters:
        originalURL - The URL to append a slash to
        Returns:
        a new URL object that ends in a slash
      • getLastModified

        public static long getLastModified​(URL resourceURL)
        Returns the last modified time for file:// and jar:// URLs. This is slightly tricky for a couple of reasons: 1) calling getConnection on a URLConnection to a file opens an InputStream to that file that must then be closed — though this is not true for URLConnections to jar resources 2) calling getLastModified on JarURLConnections returns the last modified time of the jar file, rather than the file within
        Parameters:
        resourceURL - the URL to return the last modified time for
        Returns:
        the last modified time of the resource, expressed as the number of milliseconds since the epoch, or 0 if there was a problem