Class URLs

    • Constructor Detail

      • URLs

        public URLs()
    • Method Detail

      • extendUrl

        public static URL extendUrl​(URL base,
                                    String extension)
                             throws MalformedURLException
        Extends a URL.
        base - Has to be a URL pointing to a directory. If it doesn't end with a / it will be added automatically.
        extension - The part that will be added to the URL
        MalformedURLException - if the new URL can not be created.
      • fileToUrl

        public static URL fileToUrl​(File file)
        A replacement for File.toURL() and File.toURI().toURL().

        File.toURL() does not percent-encode characters and File.toURI().toURL() does not percent-encode non-ASCII characters. This method ensures that URL characters are correctly percent-encoded, and works around the reported misbehaviour of some Java implementations on Mac.

      • urlToFile

        public static File urlToFile​(URL url)
        Takes a URL and converts it to a File. The attempts to deal with Windows UNC format specific problems, specifically files located on network shares and different drives.

        If the URL.getAuthority() returns null or is empty, then only the url's path property is used to construct the file. Otherwise, the authority is prefixed before the path.

        It is assumed that url.getProtocol returns "file".

        Authority is the drive or network share the file is located on. Such as "C:", "E:", "\\fooServer"

        url - a URL object that uses protocol "file"
        a File that corresponds to the URL's location