com.tenduke.io
Class UriUtils

java.lang.Object
  extended by com.tenduke.io.UriUtils

public final class UriUtils
extends java.lang.Object

Utility methods for working with URI objects.


Method Summary
static java.net.URI changeFileExtension(java.net.URI uri, java.lang.String fileExtension)
          Changes the "file extension" part of the URI.
static java.net.URI constructFileUri(java.io.File file)
          Constructs URI using file scheme and absolute path of the given file.
static java.net.URI constructFileUri(java.lang.String filePath)
          Constructs URI using file scheme and the given file path.
static java.net.URL constructFileUrl(java.io.File file)
          Constructs URL using file scheme and absolute path of the given file.
static java.net.URL constructFileUrl(java.lang.String filePath)
          Constructs URL using file scheme and the given file path.
static java.lang.String getUriPath(java.net.URI uri)
          Gets path component of the given uri.
static java.lang.String getUriPath(java.net.URI uri, java.lang.String characterEncoding)
          Gets path component of the given uri.
static java.lang.String getUriPathSafe(java.net.URI uri)
          Gets path component of the given uri.
static java.lang.String getUriPathSafe(java.net.URI uri, java.lang.String characterEncoding)
          Gets path component of the given uri.
static java.lang.String getUriQuery(java.net.URI uri)
          Gets query component of the given uri.
static java.lang.String getUriQuery(java.net.URI uri, java.lang.String characterEncoding)
          Gets query component of the given uri.
static java.lang.String getUriQuerySafe(java.net.URI uri)
          Gets query component of the given uri.
static java.lang.String getUriQuerySafe(java.net.URI uri, java.lang.String characterEncoding)
          Gets query component of the given uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

changeFileExtension

public static java.net.URI changeFileExtension(java.net.URI uri,
                                               java.lang.String fileExtension)
                                        throws java.net.URISyntaxException
Changes the "file extension" part of the URI. File extension is part of URI path after first dot after last slash.

Parameters:
uri - Source URI.
fileExtension - The new file extension.
Returns:
URI with the changed file extension, or original URI if no file extension part found.
Throws:
java.net.URISyntaxException - Thrown if the changed URI is not valid URI.

constructFileUri

public static java.net.URI constructFileUri(java.io.File file)
                                     throws java.net.URISyntaxException
Constructs URI using file scheme and absolute path of the given file.

Parameters:
file - File for which URI is constructed.
Returns:
URI that can be used to identify and locate the file.
Throws:
java.net.URISyntaxException - Thrown if constructing the URI fails.

constructFileUri

public static java.net.URI constructFileUri(java.lang.String filePath)
                                     throws java.net.URISyntaxException
Constructs URI using file scheme and the given file path.

Parameters:
filePath - Path to file for which URI is constructed.
Returns:
URI that can be used to identify and locate the file.
Throws:
java.net.URISyntaxException - Thrown if constructing the URI fails.

constructFileUrl

public static java.net.URL constructFileUrl(java.io.File file)
                                     throws java.net.MalformedURLException
Constructs URL using file scheme and absolute path of the given file.

Parameters:
file - File for which URL is constructed.
Returns:
URL that can be used to locate the file.
Throws:
java.net.MalformedURLException - Thrown if constructing the URL fails.

constructFileUrl

public static java.net.URL constructFileUrl(java.lang.String filePath)
                                     throws java.net.MalformedURLException
Constructs URL using file scheme and the given file path.

Parameters:
filePath - Path to file for which URL is constructed.
Returns:
URL that can be used to locate the file.
Throws:
java.net.MalformedURLException - Thrown if constructing the URL fails.

getUriPath

public static java.lang.String getUriPath(java.net.URI uri)
                                   throws java.io.UnsupportedEncodingException
Gets path component of the given uri. The string returned by this method is equal to that returned by the URI.getRawPath() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload uses UTF-8 character encoding.

Parameters:
uri - The URI object.
Returns:
The decoded path component of this URI, or null if the path is undefined.
Throws:
java.io.UnsupportedEncodingException - Thrown if given character encoding is not supported.

getUriPath

public static java.lang.String getUriPath(java.net.URI uri,
                                          java.lang.String characterEncoding)
                                   throws java.io.UnsupportedEncodingException
Gets path component of the given uri. The string returned by this method is equal to that returned by the URI.getRawPath() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc).

Parameters:
uri - The URI object.
characterEncoding - Character encoding to be used by URLDecoder.decode.
Returns:
The decoded path component of this URI, or null if the path is undefined.
Throws:
java.io.UnsupportedEncodingException - Thrown if given character encoding is not supported.

getUriPathSafe

public static java.lang.String getUriPathSafe(java.net.URI uri)
Gets path component of the given uri. The string returned by this method is equal to that returned by the URI.getRawPath() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload uses UTF-8 character encoding and catches exceptions, returning null if exceptions occurred.

Parameters:
uri - The URI object.
Returns:
The decoded path component of this URI, or null if the path is undefined.

getUriPathSafe

public static java.lang.String getUriPathSafe(java.net.URI uri,
                                              java.lang.String characterEncoding)
Gets path component of the given uri. The string returned by this method is equal to that returned by the URI.getRawPath() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload catches exceptions, returning null if exceptions occurred.

Parameters:
uri - The URI object.
characterEncoding - Character encoding to be used by URLDecoder.decode.
Returns:
The decoded path component of this URI, or null if the path is undefined.

getUriQuery

public static java.lang.String getUriQuery(java.net.URI uri)
                                    throws java.io.UnsupportedEncodingException
Gets query component of the given uri. The string returned by this method is equal to that returned by the URI.getRawQuery() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload uses UTF-8 character encoding.

Parameters:
uri - The URI object.
Returns:
The decoded query component of this URI, or null if the query is undefined.
Throws:
java.io.UnsupportedEncodingException - Thrown if given character encoding is not supported.

getUriQuery

public static java.lang.String getUriQuery(java.net.URI uri,
                                           java.lang.String characterEncoding)
                                    throws java.io.UnsupportedEncodingException
Gets query component of the given uri. The string returned by this method is equal to that returned by the URI.getRawQuery() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc).

Parameters:
uri - The URI object.
characterEncoding - Character encoding to be used by URLDecoder.decode.
Returns:
The decoded query component of this URI, or null if the query is undefined.
Throws:
java.io.UnsupportedEncodingException - Thrown if given character encoding is not supported.

getUriQuerySafe

public static java.lang.String getUriQuerySafe(java.net.URI uri)
Gets query component of the given uri. The string returned by this method is equal to that returned by the URI.getRawQuery() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload uses UTF-8 character encoding and catches exceptions, returning null if exceptions occurred.

Parameters:
uri - The URI object.
Returns:
The decoded query component of this URI, or null if the query is undefined.

getUriQuerySafe

public static java.lang.String getUriQuerySafe(java.net.URI uri,
                                               java.lang.String characterEncoding)
Gets query component of the given uri. The string returned by this method is equal to that returned by the URI.getRawQuery() method except that it is URL decoded using java.net.URLDecoder.decode(String s, String enc). This overload catches exceptions, returning null if exceptions occurred.

Parameters:
uri - The URI object.
characterEncoding - Character encoding to be used by URLDecoder.decode.
Returns:
The decoded query component of this URI, or null if the query is undefined.