Package org.geotools.util
Class URLs
Object
URLs
Utilities for manipulating and converting to and from
URLs.
urlToFile(URL) and fileToUrl(File) and getParentUrl(URL) are used to work with files
across platforms
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URLchangeUrlExt(URL url, String postfix) Changes the ending (e.g. ".sld") of aURLstatic URLExtends aURL.static URLA replacement forFile.toURL()andFile.toURI().toURL().static URLgetParentUrl(URL url) The function is supposed to be equivalent toFile.getParent().static FileTakes a URL and converts it to a File.
-
Constructor Details
-
URLs
public URLs()
-
-
Method Details
-
changeUrlExt
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
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
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
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- if the parentURLcan not be created.
-
urlToFile
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
-