Class UriUtil
URI
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic URI
Creates a URI by parsing the given components.static URI
Creates a URI by parsing the given components.getQueryMap
(URI uri) Returns the query parameters of the givenuri
or an empty map if the query isnull
.static URI
overrideFragment
(URI uri, String fragment) This method sets the fragment inuri
tofragment
and returns the resulting URI.static URI
overridePort
(URI uri, int port) This method sets the port inuri
toport
and returns the resulting URI.static URI
removeFragment
(URI uri) This method removes the fragment inuri
and returns the resulting URI.
-
Method Details
-
createUri
Creates a URI by parsing the given components.This convenience factory method works as if by invoking the
URI(String, String, String, int, String, String, String)
constructor; anyURISyntaxException
thrown by the constructor is caught and wrapped in a newIllegalArgumentException
object, which is then thrown.This method is provided for use in situations where it is known that the given components results in a legal URI, for example for URI constants declared within a program, and so it would be considered a programming error for the given components not to parse as such. The constructors, which throw
URISyntaxException
directly, should be used in situations where a URI is being constructed from user input or from some other source that may be prone to errors.- Parameters:
scheme
- Scheme name The scheme to be parsed into a URLhost
- Host name The host to be parsed into a URLport
- Port number The port to be parsed into a URL- Returns:
- The new URI
- Throws:
IllegalArgumentException
- If the URI constructed from the given components violates RFC 2396
-
createUri
public static URI createUri(String scheme, String userInfo, String host, int port, String path, String query) Creates a URI by parsing the given components.This convenience factory method works as if by invoking the
URI(String, String, String, int, String, String, String)
constructor; anyURISyntaxException
thrown by the constructor is caught and wrapped in a newIllegalArgumentException
object, which is then thrown.This method is provided for use in situations where it is known that the given components results in a legal URI, for example for URI constants declared within a program, and so it would be considered a programming error for the given components not to parse as such. The constructors, which throw
URISyntaxException
directly, should be used in situations where a URI is being constructed from user input or from some other source that may be prone to errors.- Parameters:
scheme
- Scheme name The scheme to be parsed into a URLuserInfo
- User name and authorization informationhost
- Host name The host to be parsed into a URLport
- Port number The port to be parsed into a URLpath
- Pathquery
- Query- Returns:
- The new URI
- Throws:
IllegalArgumentException
- If the URI constructed from the given components violates RFC 2396
-
overridePort
This method sets the port inuri
toport
and returns the resulting URI.- Parameters:
uri
- the base URIport
- the port- Returns:
- a combined URI and port URI
- Throws:
IllegalArgumentException
- if resulting URI violates RFC 2396
-
overrideFragment
This method sets the fragment inuri
tofragment
and returns the resulting URI.- Parameters:
uri
- the base URIfragment
- the fragment- Returns:
- a combined URI and fragment URI
- Throws:
IllegalArgumentException
- if resulting URI violates RFC 2396
-
removeFragment
This method removes the fragment inuri
and returns the resulting URI.- Parameters:
uri
- the base URI- Returns:
- URI without fragment
- Throws:
IllegalArgumentException
- if resulting URI violates RFC 2396
-
getQueryMap
Returns the query parameters of the givenuri
or an empty map if the query isnull
.- Parameters:
uri
- the URI- Returns:
- query parameters as map
- See Also:
-