Package org.geotools.util
Class URLs
Object
URLs
Utilities for manipulating and converting to and from
URL
s.
urlToFile(URL)
and fileToUrl(File)
and getParentUrl(URL)
are used to work with files
across platforms
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URL
changeUrlExt
(URL url, String postfix) Changes the ending (e.g. ".sld") of aURL
static URL
Extends aURL
.static URL
A replacement forFile.toURL()
andFile.toURI().toURL()
.static URL
getParentUrl
(URL url) The function is supposed to be equivalent toFile.getParent()
.static File
Takes 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
-URL
likefile:/sds/a.bmp
orhttp://www.some.org/foo/bar.shp
postfix
- New file extension for theURL
without.
- Returns:
- A new
URL
with new extension. - Throws:
IllegalArgumentException
-
extendUrl
Extends aURL
.- Parameters:
base
- Has to be aURL
pointing 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 newURL
can 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()
. TheURL
is converted to a String, truncated to the last / and then recreated as a new URL.- Throws:
MalformedURLException
- if the parentURL
can 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
-