Package ca.cgjennings.io.protocols
Class MappedURLHandler
- java.lang.Object
-
- java.net.URLStreamHandler
-
- ca.cgjennings.io.protocols.MappedURLHandler
-
public abstract class MappedURLHandler extends java.net.URLStreamHandler
A base class for creating protocol handlers that substitutes the source URL with a stand-in. Implementations should overridemapURL(java.net.URL)
and/ormapConnection(java.net.URL, java.net.URL)
.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description MappedURLHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getComposedPath(java.net.URL url)
Composes the host and path of a URL together into a single stream; this is useful when processing file system-like URLs that do not use a host.static void
install()
Installs all custom protocol handlers.protected java.net.URLConnection
mapConnection(java.net.URL sourceURL, java.net.URL mappedURL)
Returns aURLConnection
for the mapped URL.protected java.net.URL
mapURL(java.net.URL sourceURL)
Maps a URL in the handled protocol to one of the underlying URLs.protected java.net.URLConnection
openConnection(java.net.URL sourceURL)
static java.lang.String
removeRelativePathComponents(java.lang.String path)
Removes .
-
-
-
Method Detail
-
openConnection
protected final java.net.URLConnection openConnection(java.net.URL sourceURL) throws java.io.IOException
- Specified by:
openConnection
in classjava.net.URLStreamHandler
- Throws:
java.io.IOException
-
mapURL
protected java.net.URL mapURL(java.net.URL sourceURL) throws java.io.IOException
Maps a URL in the handled protocol to one of the underlying URLs. The base class returns the original URL.- Parameters:
sourceURL
- a URL in the protocol handled by this handler- Returns:
- a URL using another protocol that maps to the same resource as
this handler, or
null
- Throws:
java.io.IOException
- if an I/O error occurs while composing the new URL
-
mapConnection
protected java.net.URLConnection mapConnection(java.net.URL sourceURL, java.net.URL mappedURL) throws java.io.IOException
Returns aURLConnection
for the mapped URL. The base class returnsmappedURL.openConnection()
.- Parameters:
sourceURL
- the original URLmappedURL
- the mapped URL returned frommapURL(java.net.URL)
- Returns:
- a connection for the URL
- Throws:
java.io.IOException
- if an I/O error occurs or the mapped URL isnull
-
install
public static void install()
Installs all custom protocol handlers. There is normally no need to call this as Strange Eons will install the handler during initialization.
-
getComposedPath
public static java.lang.String getComposedPath(java.net.URL url)
Composes the host and path of a URL together into a single stream; this is useful when processing file system-like URLs that do not use a host.- Parameters:
url
- the URL to compose- Returns:
- the host and path, concatenated and separated by a slash, or
null
ifnull
was passed in
-
removeRelativePathComponents
public static java.lang.String removeRelativePathComponents(java.lang.String path)
Removes . and .. segments from a URL path. This can be used on the concatenation of an absolute path with a path with one or more relative segments to produce an equivalent absolute path.- Parameters:
path
- the concatenated path- Returns:
- an absolute path
-
-