Package org.geotools.util
Class URLs
- Object
-
- URLs
-
public class URLs extends Object
Utilities for manipulating and converting to and fromURLs.urlToFile(URL)andfileToUrl(File)andgetParentUrl(URL)are used to work with files across platforms
-
-
Constructor Summary
Constructors Constructor Description URLs()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URLchangeUrlExt(URL url, String postfix)Changes the ending (e.g. ".sld") of aURLstatic URLextendUrl(URL base, String extension)Extends aURL.static URLfileToUrl(File file)A replacement forFile.toURL()andFile.toURI().toURL().static URLgetParentUrl(URL url)The function is supposed to be equivalent toFile.getParent().static FileurlToFile(URL url)Takes a URL and converts it to a File.
-
-
-
Method Detail
-
changeUrlExt
public static URL changeUrlExt(URL url, String postfix) throws IllegalArgumentException
Changes the ending (e.g. ".sld") of aURL- Parameters:
url-URLlikefile:/sds/a.bmporhttp://www.some.org/foo/bar.shppostfix- New file extension for theURLwithout.- Returns:
- A new
URLwith new extension. - Throws:
IllegalArgumentException
-
extendUrl
public static URL extendUrl(URL base, String extension) throws MalformedURLException
Extends aURL.- Parameters:
base- Has to be aURLpointing to a directory. If it doesn't end with a/it will be added automatically.extension- The part that will be added to theURL- Throws:
MalformedURLException- if the newURLcan not be created.
-
fileToUrl
public static URL fileToUrl(File file)
A replacement forFile.toURL()andFile.toURI().toURL().File.toURL()does not percent-encode characters andFile.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.- Returns:
- URL
-
getParentUrl
public static URL getParentUrl(URL url) throws MalformedURLException
The function is supposed to be equivalent toFile.getParent(). TheURLis converted to a String, truncated to the last / and then recreated as a new URL.- Throws:
MalformedURLException
-
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"
- Parameters:
url- a URL object that uses protocol "file"- Returns:
- a File that corresponds to the URL's location
-
-