com.xmlmind.util
Class URLUtil

java.lang.Object
  extended by com.xmlmind.util.URLUtil

public final class URLUtil
extends java.lang.Object

A collection of utility functions (static methods) operating on URLs.

Work with any hierarchical URLs. Does not work with opaque URLs, except for a few functions which work with "jar:" URLs.

Note that, for these few functions, the path of "jar:" URL (e.g. jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class) is everything after "!/", including the leading "/".


Nested Class Summary
static class URLUtil.URLComparator
          Compares two URLs by their external forms.
 
Field Summary
static URLUtil.URLComparator COMPARATOR
          A ready-to-use URLComparator.
static java.net.URL[] EMPTY_LIST
          A ready-to-use empty list of URLs.
 
Method Summary
static void checkHTTPConnection(java.net.URLConnection connection)
          Checks that specified HTTP connection returned "200 OK".
static java.lang.String contentTypeToCharset(java.lang.String contentType)
          Returns the value of the charset parameter possibly found in specified content type.
static java.lang.String contentTypeToMedia(java.lang.String contentType)
          Parses a content type such as "text/html; charset=ISO-8859-1" and returns the media type (for the above example "text/html").
static int copyFile(java.lang.String srcLocation, java.lang.String dstLocation)
          Copies the contents of specified URL to specified "file:" URL.
static java.net.URL createURL(java.lang.String spec)
          Same as new URL(spec), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.
static java.net.URL createURL(java.net.URL context, java.lang.String spec)
          Same as new URL(context, spec), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.
static java.net.URL createURL(java.net.URL context, java.lang.String spec, java.net.URLStreamHandler handler)
          Same as new URL(context, spec, handler), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.
static boolean exists(java.net.URL url)
          Returns true if specified URL corresponds to an existing resource; returns false otherwise.
static java.lang.String getBaseName(java.net.URL url)
          Same as getRawBaseName(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).
static java.lang.String getExtension(java.net.URL url)
          Same as getRawExtension(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).
static java.lang.String getFragment(java.net.URL url)
          Same as URL.getRef except that the returned value is decoded using URIComponent.decode(java.lang.String).
static java.net.URL getParent(java.net.URL url)
          Returns the parent of specified URL, if any.
static java.lang.String getPath(java.net.URL url)
          Same as getRawPath(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).
static java.lang.String getRawBaseName(java.net.URL url)
          Returns the raw (that is, possibly containing %HH escapes) basename part of the path, if specified URL has a path.
static java.lang.String getRawExtension(java.net.URL url)
          Returns the raw (that is, possibly containing %HH escapes) extension of the path, if specified URL has a path.
static java.lang.String getRawPath(java.net.URL url)
          Returns the raw (that is, possibly containing %HH escapes) path, if specified URL has a path.
static java.lang.String getRawRelativePath(java.net.URL url, java.net.URL base)
          Returns the path of specified URL relative to specified base URL.
static java.lang.String getRawUserName(java.net.URL url)
          Returns the raw (that is, possibly containing %HH escapes) user name, if a user info is found in specified URL.
static java.lang.String getRawUserPassword(java.net.URL url)
          Returns the raw (that is, possibly containing %HH escapes) user password, if a user info is found in specified URL.
static java.net.URL getRoot(java.net.URL url)
          Returns the root of specified URL.
static java.lang.String getUserName(java.net.URL url)
          Same as getRawUserName(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).
static java.lang.String getUserPassword(java.net.URL url)
          Same as getRawUserPassword(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).
static boolean isAncestorOf(java.net.URL ancestorURL, java.net.URL url)
          Tests whether first specified URL is an ancestor of second specified URL.
static boolean isFileURL(java.net.URL url)
          Returns true if specified URL is a file: URL, otherwise returns false
static boolean isJarURL(java.net.URL url)
          Returns true if specified URL is a jar: URL, otherwise returns false
static long lastModified(java.net.URL url)
          Returns the date specified URL has been last modified.
static byte[] loadBytes(java.net.URL url)
          Equivalent to loadBytes(url, -1).
static byte[] loadBytes(java.net.URL url, int timeout)
          Loads the content of an URL containing binary data.
static java.lang.String loadString(java.net.URL url)
          Equivalent to loadString(url, null, -1).
static java.lang.String loadString(java.net.URL url, java.lang.String charset)
          Equivalent to loadString(url, charset, -1).
static java.lang.String loadString(java.net.URL url, java.lang.String charset, int timeout)
          Loads the content of an URL containing text.
static java.lang.String normalizeContentType(java.lang.String contentType, java.lang.String defaultCharset)
          Returns a normalized string form for specified content type.
static java.net.URLConnection openConnectionNoCache(java.net.URL url)
          Similar to url.openConnection except that the accessed resource may not be a cached copy.
static java.net.URLConnection openConnectionUseCache(java.net.URL url)
          Similar to url.openConnection except that the accessed resource may be a cached copy.
static java.io.InputStream openStreamNoCache(java.net.URL url)
          Similar to url.openStream except that the accessed resource may not be a cached copy.
static java.io.InputStream openStreamUseCache(java.net.URL url)
          Similar to url.openStream except that the accessed resource may be a cached copy.
static boolean sameContentType(java.lang.String ct1, java.lang.String ct2, java.lang.String defaultCharset)
          Tests whether specified content types are identical.
static boolean sameRoot(java.net.URL url1, java.net.URL url2)
          Returns true if specified URLs have the same root.
static java.net.URL setExtension(java.net.URL url, java.lang.String extension)
          Same as setRawExtension(java.net.URL, java.lang.String) except that specified extension is quoted using URIComponent.quotePath(java.lang.String).
static java.net.URL setFragment(java.net.URL url, java.lang.String fragment)
          Same as setRawFragment(java.net.URL, java.lang.String) except that specified fragment is quoted using URIComponent.quoteFragment(java.lang.String).
static java.net.URL setRawExtension(java.net.URL url, java.lang.String extension)
          Changes the extension of specified URL to specified extension.
static java.net.URL setRawFragment(java.net.URL url, java.lang.String fragment)
          Changes the fragment of specified URL to specified fragment.
static java.net.URL setRawUserInfo(java.net.URL url, java.lang.String userName, java.lang.String password)
          Changes the user info of specified URL to specified user info.
static java.net.URL setUserInfo(java.net.URL url, java.lang.String userName, java.lang.String password)
          Same as setRawUserInfo(java.net.URL, java.lang.String, java.lang.String) except that specified user info is quoted using URIComponent.quoteUserInfo(java.lang.String).
static java.lang.String toDisplayForm(java.net.URL url)
          Same as java.net.URL.toExternalForm except that returned string may contain non-ASCII characters and that, if specified URL contains a password, the characters of this password are replaced by '*'.
static java.lang.String toLabel(java.net.URL url)
          Same as toDisplayForm(java.net.URL) but file: URLs not having a fragment are displayed as plain file names.
static java.lang.String toShortDisplayForm(java.net.URL url, int maxLength)
          Same as toDisplayForm(java.net.URL) except that the returned string is made shorter than specified length (when possible).
static java.lang.String toShortLabel(java.net.URL url, int maxLength)
          Same as toLabel(java.net.URL) except that the returned string is made shorter than specified length (when possible).
static java.net.URL urlOrFile(java.lang.String path)
          Equivalent to urlOrFile(path, false, false, null).
static java.net.URL urlOrFile(java.lang.String path, boolean checkAbsolute)
          Equivalent to urlOrFile(path, checkAbsolute, false, null).
static java.net.URL urlOrFile(java.lang.String path, boolean checkAbsolute, boolean allowDir)
          Equivalent to urlOrFile(path, checkAbsolute, allowDir, null).
static java.net.URL urlOrFile(java.lang.String path, boolean checkAbsolute, boolean allowDir, java.net.URL baseURL)
          Returns an URL created from specified path.
static java.io.File urlToFile(java.net.URL url)
          Converts a file: URL to a File.
static java.net.URI urlToURI(java.net.URL url)
          Similar to java.net.URL.toURI() except that this utility will not throw a java.net.URISyntaxException if the URL spec contains illegal characters such as spaces.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_LIST

public static final java.net.URL[] EMPTY_LIST
A ready-to-use empty list of URLs.


COMPARATOR

public static final URLUtil.URLComparator COMPARATOR
A ready-to-use URLComparator.

Method Detail

createURL

public static java.net.URL createURL(java.lang.String spec)
                              throws java.net.MalformedURLException
Same as new URL(spec), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.

Throws:
java.net.MalformedURLException
See Also:
URIComponent.encode(java.lang.String)

createURL

public static java.net.URL createURL(java.net.URL context,
                                     java.lang.String spec)
                              throws java.net.MalformedURLException
Same as new URL(context, spec), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.

Throws:
java.net.MalformedURLException
See Also:
URIComponent.encode(java.lang.String)

createURL

public static java.net.URL createURL(java.net.URL context,
                                     java.lang.String spec,
                                     java.net.URLStreamHandler handler)
                              throws java.net.MalformedURLException
Same as new URL(context, spec, handler), except that non-ASCII characters and other illegal characters such as spaces possibly found in spec are %HH-encoded.

Throws:
java.net.MalformedURLException
See Also:
URIComponent.encode(java.lang.String)

isFileURL

public static boolean isFileURL(java.net.URL url)
Returns true if specified URL is a file: URL, otherwise returns false


isJarURL

public static boolean isJarURL(java.net.URL url)
Returns true if specified URL is a jar: URL, otherwise returns false


urlToFile

public static java.io.File urlToFile(java.net.URL url)
Converts a file: URL to a File.

On Windows, this function converts a "file:" URL having a host (other than "localhost") to an UNC filename. For example, it converts "file://foo/bar/gee.txt" to "\\foo\bar\gee.txt".

Parameters:
url - the URL to be converted
Returns:
an absolute File or null if url cannot be converted to a File (for example, because url is not a file: URL)
See Also:
isFileURL(java.net.URL), FileUtil.fileToURL(java.io.File), urlOrFile(java.lang.String)

urlToURI

public static java.net.URI urlToURI(java.net.URL url)
Similar to java.net.URL.toURI() except that this utility will not throw a java.net.URISyntaxException if the URL spec contains illegal characters such as spaces. In such case, special efforts are made to nevertheless return a URI equivalent to specified URL.

Parameters:
url - URL to be converted
Returns:
converted URI or null if this really cannot be done

urlOrFile

public static java.net.URL urlOrFile(java.lang.String path)
Equivalent to urlOrFile(path, false, false, null).


urlOrFile

public static java.net.URL urlOrFile(java.lang.String path,
                                     boolean checkAbsolute)
Equivalent to urlOrFile(path, checkAbsolute, false, null).


urlOrFile

public static java.net.URL urlOrFile(java.lang.String path,
                                     boolean checkAbsolute,
                                     boolean allowDir)
Equivalent to urlOrFile(path, checkAbsolute, allowDir, null).


urlOrFile

public static java.net.URL urlOrFile(java.lang.String path,
                                     boolean checkAbsolute,
                                     boolean allowDir,
                                     java.net.URL baseURL)
Returns an URL created from specified path. First, this convenience function attempts to convert specified path to an URL. If this fails, specified path is considered to be the name of an existing file or directory. If this filename conforms to specified requirements (checkAbsolute, allowDir), it is converted to an URL using FileUtil.fileToURL(java.io.File).

Parameters:
path - external form of an URL or the filename of an existing file or directory.

If the path contains newline characters, everything after the first newline character, including this character, is ignored.

The reason for this is that Web browsers such as Firefox seems to append the title of the Web page after its URL.

checkAbsolute - if true, when path is a filename, path must be absolute or this function will return null
allowDir - if true, when path is a filename, path is allowed to be not only the path of a file but also the path of a directory
baseURL - which base URL to use to resolve path when its a relative URL. May be null.
Returns:
an URL or null if specified path cannot be converted to an URL given specified requirements

sameRoot

public static boolean sameRoot(java.net.URL url1,
                               java.net.URL url2)
Returns true if specified URLs have the same root.

See Also:
getRoot(java.net.URL)

getRoot

public static java.net.URL getRoot(java.net.URL url)
Returns the root of specified URL.

Example: returns "http://java.sun.com/" for "http://java.sun.com/docs/index.html".

Example: returns "jar:http://www.foo.com/bar/baz.jar!/" for "jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class".

Parameters:
url - a hierachical or "jar:" URL
Returns:
root of specified URL

isAncestorOf

public static boolean isAncestorOf(java.net.URL ancestorURL,
                                   java.net.URL url)
Tests whether first specified URL is an ancestor of second specified URL.

Parameters:
ancestorURL - a hierachical or "jar:" URL
url - a hierachical or "jar:" URL
Returns:
true if ancestorURL is equal to or is an ancestor directory of url; false otherwise.

getParent

public static java.net.URL getParent(java.net.URL url)
Returns the parent of specified URL, if any. Returned URL has a path which ends with '/'.

Examples:

Parameters:
url - a hierachical or "jar:" URL
Returns:
parent of specified URL or null for root URLs.
See Also:
URIComponent.getRawParentPath(String, boolean)

getPath

public static java.lang.String getPath(java.net.URL url)
Same as getRawPath(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).


getRawPath

public static java.lang.String getRawPath(java.net.URL url)
Returns the raw (that is, possibly containing %HH escapes) path, if specified URL has a path.

Example: returns "/index.html" for "http://www.acme.com/index.html".

Example: returns "/COM/foo/Quux.class" for "jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class".

Parameters:
url - a hierachical or "jar:" URL
Returns:
the raw path or null if specified URL has no path (this is not consistent with URL.getPath which returns the empty string in such case)

getBaseName

public static java.lang.String getBaseName(java.net.URL url)
Same as getRawBaseName(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).


getRawBaseName

public static java.lang.String getRawBaseName(java.net.URL url)
Returns the raw (that is, possibly containing %HH escapes) basename part of the path, if specified URL has a path.

Example: returns "index.html" for "http://www.acme.com/index.html".

Example: returns "png" for "http://www.acme.com/icons/png/".

Example: returns "Quux.class" for "jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class".

Parameters:
url - a hierachical or "jar:" URL
Returns:
basename or null if specified URL has no path (this is not consistent with URL.getPath which returns the empty string in such case)
See Also:
URIComponent.getRawBaseName(java.lang.String)

getExtension

public static java.lang.String getExtension(java.net.URL url)
Same as getRawExtension(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).


getRawExtension

public static java.lang.String getRawExtension(java.net.URL url)
Returns the raw (that is, possibly containing %HH escapes) extension of the path, if specified URL has a path. The extension does not include a leading dot '.'.

Example: returns "html" for "http://www.acme.com/index.html".

Example: returns null for "http://www.acme.com/icons/png/".

Example: returns "class" for "jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class".

Parameters:
url - a hierachical or "jar:" URL
Returns:
extension or null if specified URL has no path (this is not consistent with URL.getPath which returns the empty string in such case)
See Also:
URIComponent.getRawExtension(java.lang.String)

setExtension

public static java.net.URL setExtension(java.net.URL url,
                                        java.lang.String extension)
Same as setRawExtension(java.net.URL, java.lang.String) except that specified extension is quoted using URIComponent.quotePath(java.lang.String).


setRawExtension

public static java.net.URL setRawExtension(java.net.URL url,
                                           java.lang.String extension)
Changes the extension of specified URL to specified extension.

Parameters:
url - a hierachical or "jar:" URL
extension - new extension. Assumed to have been quoted using URIComponent.quotePath(java.lang.String). May be null which means: remove the extension.
Returns:
an URL identical to url except that its extension has been changed or removed.

Returns same URL if specified URL has no path or its path ends with '/'.

See Also:
URIComponent.setRawExtension(java.lang.String, java.lang.String)

getFragment

public static java.lang.String getFragment(java.net.URL url)
Same as URL.getRef except that the returned value is decoded using URIComponent.decode(java.lang.String).


setFragment

public static java.net.URL setFragment(java.net.URL url,
                                       java.lang.String fragment)
Same as setRawFragment(java.net.URL, java.lang.String) except that specified fragment is quoted using URIComponent.quoteFragment(java.lang.String).


setRawFragment

public static java.net.URL setRawFragment(java.net.URL url,
                                          java.lang.String fragment)
Changes the fragment of specified URL to specified fragment.

Parameters:
url - a hierachical or "jar:" URL
fragment - new fragment. Assumed to have been quoted using URIComponent.quoteFragment(java.lang.String). May be null which means: remove the fragment.
Returns:
an URL identical to url except that its fragment has been changed or removed. Returns url as is if specified URL has no path.
See Also:
URIComponent.setRawFragment(java.lang.String, java.lang.String)

getUserName

public static java.lang.String getUserName(java.net.URL url)
Same as getRawUserName(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).


getRawUserName

public static java.lang.String getRawUserName(java.net.URL url)
Returns the raw (that is, possibly containing %HH escapes) user name, if a user info is found in specified URL. Returns null otherwise.


getUserPassword

public static java.lang.String getUserPassword(java.net.URL url)
Same as getRawUserPassword(java.net.URL) except that the returned value is decoded using URIComponent.decode(java.lang.String).


getRawUserPassword

public static java.lang.String getRawUserPassword(java.net.URL url)
Returns the raw (that is, possibly containing %HH escapes) user password, if a user info is found in specified URL. Returns null otherwise.


setUserInfo

public static java.net.URL setUserInfo(java.net.URL url,
                                       java.lang.String userName,
                                       java.lang.String password)
Same as setRawUserInfo(java.net.URL, java.lang.String, java.lang.String) except that specified user info is quoted using URIComponent.quoteUserInfo(java.lang.String).


setRawUserInfo

public static java.net.URL setRawUserInfo(java.net.URL url,
                                          java.lang.String userName,
                                          java.lang.String password)
Changes the user info of specified URL to specified user info.

Parameters:
url - a hierachical or "jar:" URL
userName - new username. Assumed to have been quoted using URIComponent.quoteUserInfo(java.lang.String). May be null, which means: remove user info.
password - new password. Assumed to have been quoted using URIComponent.quoteUserInfo(java.lang.String). May be null, which means: password not specified.
Returns:
an URL identical to url except that its user info has been changed or removed.

getRawRelativePath

public static java.lang.String getRawRelativePath(java.net.URL url,
                                                  java.net.URL base)
Returns the path of specified URL relative to specified base URL.

More precisely returns relativePath such that new URL(base, relativePath) equals url.

Parameters:
url - a hierarchical or "jar:" URL
base - another hierarchical or "jar:" URL
Returns:
a relative path possibly followed by the query and fragment components of url or URL.toExternalForm if url or base have no path or if url and base don't have the same root
See Also:
URIComponent.getRawRelativePath(java.lang.String, java.lang.String)

toLabel

public static java.lang.String toLabel(java.net.URL url)
Same as toDisplayForm(java.net.URL) but file: URLs not having a fragment are displayed as plain file names.


toDisplayForm

public static java.lang.String toDisplayForm(java.net.URL url)
Same as java.net.URL.toExternalForm except that returned string may contain non-ASCII characters and that, if specified URL contains a password, the characters of this password are replaced by '*'.

Example: returns ftp://jjc%40acme.com:******@ftp.acme.com/pub/My%20report.doc for ftp://jjc%40acme.com:s%25same@ftp.acme.com/pub/My%20report.doc.

Parameters:
url - a hierarchical URL possibly having a fragment and a query string
Returns:
display form or URL.toExternalForm if specified URL is opaque ("jar:" URLs are opaque).

toShortLabel

public static java.lang.String toShortLabel(java.net.URL url,
                                            int maxLength)
Same as toLabel(java.net.URL) except that the returned string is made shorter than specified length (when possible). This function is useful to display the recently opened URLs in the File menu of an application.


toShortDisplayForm

public static java.lang.String toShortDisplayForm(java.net.URL url,
                                                  int maxLength)
Same as toDisplayForm(java.net.URL) except that the returned string is made shorter than specified length (when possible). This function is useful to display the recently opened URLs in the File menu of an application.

Supports "jar:" URLs, but returns other opaque URLs as is.


exists

public static boolean exists(java.net.URL url)
Returns true if specified URL corresponds to an existing resource; returns false otherwise.

This method treats "file:" URLs as a special, optimized, case.


lastModified

public static long lastModified(java.net.URL url)
Returns the date specified URL has been last modified. The result is the number of milliseconds since January 1, 1970 GMT. If specified URL does not exist or if this date is unknown returns a number which is negative or null.

This method treats "file:" URLs as a special, optimized, case.


checkHTTPConnection

public static void checkHTTPConnection(java.net.URLConnection connection)
                                throws java.io.IOException
Checks that specified HTTP connection returned "200 OK". No effect when specified connection is not a HttpURLConnection (e.g. it's a JarURLConnection).

Throws:
java.io.IOException - when specified HTTP connection returned a code other than "200 OK". The message of the exception contains information about what happened.

loadBytes

public static byte[] loadBytes(java.net.URL url)
                        throws java.io.IOException
Equivalent to loadBytes(url, -1).

Throws:
java.io.IOException

loadBytes

public static byte[] loadBytes(java.net.URL url,
                               int timeout)
                        throws java.io.IOException
Loads the content of an URL containing binary data.

Parameters:
url - the URL of the binary data
timeout - specifies both connect and read timeout values in milliseconds. 0 means: infinite timeout. A negative value means: default value.
Returns:
the loaded bytes
Throws:
java.io.IOException - if there is an I/O problem

copyFile

public static int copyFile(java.lang.String srcLocation,
                           java.lang.String dstLocation)
                    throws java.lang.IllegalArgumentException,
                           java.io.IOException
Copies the contents of specified URL to specified "file:" URL.

Parameters:
srcLocation - URL of the source file in string form. If relative, this location is relative to the current working directory.
dstLocation - URL of the destination file in string form. If relative, this location is relative to the current working directory.
Throws:
java.lang.IllegalArgumentException - if srcLocation cannot be parsed as an URL or if dstLocation cannot be parsed as a "file:" URL.
java.io.IOException - if an I/O problem occurs

loadString

public static java.lang.String loadString(java.net.URL url)
                                   throws java.io.IOException
Equivalent to loadString(url, null, -1).

Throws:
java.io.IOException

loadString

public static java.lang.String loadString(java.net.URL url,
                                          java.lang.String charset)
                                   throws java.io.IOException
Equivalent to loadString(url, charset, -1).

Throws:
java.io.IOException

loadString

public static java.lang.String loadString(java.net.URL url,
                                          java.lang.String charset,
                                          int timeout)
                                   throws java.io.IOException
Loads the content of an URL containing text.

Parameters:
url - the URL of the text resource
charset - the IANA charset of the text source if known; specifying null means detect it using the content type obtained from the connection
timeout - specifies both connect and read timeout values in milliseconds. 0 means: infinite timeout. A negative value means: default value.
Returns:
the loaded String
Throws:
java.io.IOException - if there is an I/O problem

contentTypeToCharset

public static java.lang.String contentTypeToCharset(java.lang.String contentType)
Returns the value of the charset parameter possibly found in specified content type. For example, returns "utf-8", when passed "text/html; charset=UTF-8"

Parameters:
contentType - a content type (AKA media type) possibly having a charset parameter
Returns:
value of the charset parameter (lower case) if any; null otherwise

contentTypeToMedia

public static java.lang.String contentTypeToMedia(java.lang.String contentType)
Parses a content type such as "text/html; charset=ISO-8859-1" and returns the media type (for the above example "text/html").

Parameters:
contentType - the content type to be parsed
Returns:
the media type (lower case) if parsing was successful; null otherwise.

normalizeContentType

public static java.lang.String normalizeContentType(java.lang.String contentType,
                                                    java.lang.String defaultCharset)
Returns a normalized string form for specified content type.

Example: returns text/html;charset=iso-8859-1 for text/html; charset="ISO-8859-1".

Parameters:
contentType - content type to be normalized
defaultCharset - charset to add as a parameter to the content type when this parameter is absent. May be null.
Returns:
normalized string form for specified content type; null if specified content type is malformed.
See Also:
sameContentType(java.lang.String, java.lang.String, java.lang.String)

sameContentType

public static boolean sameContentType(java.lang.String ct1,
                                      java.lang.String ct2,
                                      java.lang.String defaultCharset)
Tests whether specified content types are identical.

Examples:

Parameters:
ct1 - content type to be tested
ct2 - content type to be tested
defaultCharset - charset to add as a parameter to a content type when this parameter is absent. May be null.
Returns:
true if specified content types are identical; false otherwise
See Also:
normalizeContentType(java.lang.String, java.lang.String)

openConnectionNoCache

public static java.net.URLConnection openConnectionNoCache(java.net.URL url)
                                                    throws java.io.IOException
Similar to url.openConnection except that the accessed resource may not be a cached copy.

Parameters:
url - URL for which an URLConnection must be opened
Throws:
java.io.IOException - if URLConnection cannot be opened
See Also:
openStreamNoCache(URL)

openStreamNoCache

public static java.io.InputStream openStreamNoCache(java.net.URL url)
                                             throws java.io.IOException
Similar to url.openStream except that the accessed resource may not be a cached copy.

Parameters:
url - URL for which an input stream must be opened
Returns:
opened input stream
Throws:
java.io.IOException - if the input stream cannot be opened
See Also:
openConnectionNoCache(URL)

openConnectionUseCache

public static java.net.URLConnection openConnectionUseCache(java.net.URL url)
                                                     throws java.io.IOException
Similar to url.openConnection except that the accessed resource may be a cached copy.

Parameters:
url - URL for which an URLConnection must be opened
Throws:
java.io.IOException - if URLConnection cannot be opened
See Also:
openStreamUseCache(URL)

openStreamUseCache

public static java.io.InputStream openStreamUseCache(java.net.URL url)
                                              throws java.io.IOException
Similar to url.openStream except that the accessed resource may be a cached copy.

Parameters:
url - URL for which an input stream must be opened
Returns:
opened input stream
Throws:
java.io.IOException - if the input stream cannot be opened
See Also:
openConnectionUseCache(URL)