Constructs a hierarchical URI from the given components.
If a scheme is given then the path, if also given, must either be
empty or begin with a slash character ( '/'). Otherwise a
component of the new URI may be left undefined by passing null
for the corresponding parameter or, in the case of the port
parameter, by passing -1.
This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section 5.2, step 7:
Initially, the result string is empty.
If a scheme is given then it is appended to the result,
followed by a colon character ( ':').
If user information, a host, or a port are given then the
string "//" is appended.
If user information is given then it is appended, followed by
a commercial-at character ( '@'). Any character not in the
unreserved, punct, escaped, or other
categories is quoted.
If a host is given then it is appended. If the host is a
literal IPv6 address but is not enclosed in square brackets
( '[' and ']') then the square brackets are added.
If a port number is given then a colon character
( ':') is appended, followed by the port number in decimal.
If a path is given then it is appended. Any character not in
the unreserved, punct, escaped, or other
categories, and not equal to the slash character ( '/') or the
commercial-at character ( '@'), is quoted.
If a query is given then a question-mark character
( '?') is appended, followed by the query. Any character that
is not a legal URI character is quoted.
Finally, if a fragment is given then a hash character
( '#') is appended, followed by the fragment. Any character
that is not a legal URI character is quoted.
The resulting URI string is then parsed as if by invoking the URI(String) constructor and then invoking the parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.
scheme | Scheme name | |
userInfo | User name and authorization information | |
host | Host name | |
port | Port number | |
path | Path | |
query | Query | |
fragment | Fragment |
URISyntaxException
| If both a scheme and a path are given but the path is relative, if the URI string constructed from the given components violates RFC 2396, or if the authority component of the string is present but cannot be parsed as a server-based authority |
Diagram: URL