Package info.freelibrary.util
Class URLUtils
- java.lang.Object
-
- info.freelibrary.util.URLUtils
-
public final class URLUtils extends Object
Utilities to assist with working with URLs.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
decode(String aString)
Decodes an encoded path.static String
decode(String aURL, String aEncoding)
Decodes an encoded path.static String
encode(String aString, boolean aIgnoreSlashFlag)
Percent-encodes supplied string but only after decoding it completely first.static File
toFile(URL aURL)
Takes a URL and converts it to a File.static String
toString(URL aURL)
Returns the contents of the supplied URL as a string.
-
-
-
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 StringaEncoding
- A character encoding to use for the string decoding- Returns:
- A decoded URL String
-
-