Class URLUtils


  • public final class URLUtils
    extends Object
    Utilities to assist with working with URLs.
    • Method Detail

      • toFile

        public static File toFile​(URL aURL)
        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"
        Parameters:
        aURL - a URL object that uses protocol "file"
        Returns:
        A File that corresponds to the URL's location
      • toString

        public static String toString​(URL aURL)
                               throws IOException
        Returns the contents of the supplied URL as a string.
        Parameters:
        aURL - A URL
        Returns:
        The contents of the supplied URL as a string
        Throws:
        IOException - If there is a problem reading the URL's contents
      • decode

        public static String decode​(String aString)
        Decodes an encoded path. If it has been doubly encoded, it is doubly decoded.
        Parameters:
        aString - An encoded path
        Returns:
        A decoded path
      • decode

        public static String decode​(String aURL,
                                    String aEncoding)
        Decodes an encoded path. If it has been doubly encoded, it is doubly decoded.
        Parameters:
        aURL - An encoded URL String
        aEncoding - A character encoding to use for the string decoding
        Returns:
        A decoded URL String
      • encode

        public static String encode​(String aString,
                                    boolean aIgnoreSlashFlag)
        Percent-encodes supplied string but only after decoding it completely first.
        Parameters:
        aString - The string to encode
        aIgnoreSlashFlag - Whether slashes should be encoded or not
        Returns:
        The percent-encoded string