The java.net.URL class cannot be used to parse URIs since it requires the installation of URL stream handlers that may not be available.
The strict parsing mode uses the java.net.URI class to syntactically validate URI strings. The compat mode validate the URI authority and rejects URI fragments, but doesn't perform any additional validation on path and query, other than that which may be implemented in the concrete the Uri subclasses. The legacy mode should not be used unless the application is capable of validating all URI strings before any constructors of this class is invoked.
The format of an absolute URI (see the RFCs mentioned above) is:
absoluteURI = scheme ":" ( hier_part | opaque_part ) scheme = alpha *( alpha | digit | "+" | "-" | "." ) hier_part = ( net_path | abs_path ) [ "?" query ] opaque_part = uric_no_slash *uric net_path = "//" authority [ abs_path ] abs_path = "/" path_segments authority = server | reg_name reg_name = 1*( unreserved | escaped | "$" | "," | ";" | ":" | "@" | "&" | "=" | "+" ) server = [ [ userinfo "@" ] hostport ] userinfo = *( unreserved | escaped | ";" | ":" | "&" | "=" | "+" | "$" | "," ) hostport = host [ ":" port ] host = hostname | IPv4address | IPv6reference port = *digit IPv6reference = "[" IPv6address "]" IPv6address = hexpart [ ":" IPv4address ] IPv4address = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ] hexseq = hex4 *( ":" hex4) hex4 = 1*4hex path = [ abs_path | opaque_part ] path_segments = segment *( "/" segment ) segment = *pchar *( ";" param ) param = *pchar pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | "," query = *uric uric = reserved | unreserved | escaped uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," | "[" | "]" unreserved = alphanum | mark mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" escaped = "%" hex hex unwise = "{" | "}" | "|" | "\" | "^" | "`"
Currently URIs containing userinfo or reg_name
are not supported.
The opaque_part of a non-hierarchical URI is treated as if
if were a path without a leading slash.
| Modifier and Type | Class and Description |
|---|---|
| public static enum |
| Modifier and Type | Field and Description |
|---|---|
| protected String | |
| protected boolean | |
| protected String | |
| protected String | |
| protected int | |
| protected String | |
| protected String | |
| protected String |
| Access | Constructor and Description |
|---|---|
| public | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | |
| protected boolean | Returns: true if the URI should be considered as a scheme-only URI supported by this URI scheme.the URI uri, String the scheme scheme)Checks whether the given uri string should be considered as a scheme-only URI. |
| public String | |
| public String | |
| public int | |
| public String | |
| public String | |
| protected void | |
| protected boolean | Returns: if this is a scheme-only URI supported by the subclassAn URI string uri)A subclass of |
| protected MalformedURLException | Returns: aMalformedURLExceptionthe URI string uri)Creates a |
| private MalformedURLException | |
| private void | |
| private void | |
| private void | |
| protected Uri. | |
| private void | |
| public String |
| fragment | back to summary |
|---|---|
| protected String fragment | |
| hasAuthority | back to summary |
|---|---|
| protected boolean hasAuthority | |
| host | back to summary |
|---|---|
| protected String host | |
| path | back to summary |
|---|---|
| protected String path | |
| port | back to summary |
|---|---|
| protected int port | |
| query | back to summary |
|---|---|
| protected String query | |
| scheme | back to summary |
|---|---|
| protected String scheme | |
| uri | back to summary |
|---|---|
| protected String uri | |
| Uri | back to summary |
|---|---|
| public Uri(String uri) throws MalformedURLException Creates a Uri object given a URI string. | |
| Uri | back to summary |
|---|---|
| protected Uri() Creates an uninitialized Uri object. The init() method must be called before any other Uri methods. | |
| acceptsFragment | back to summary |
|---|---|
| protected boolean acceptsFragment() Whether fragments are supported. Implementation Specification The default implementation of this method retturns false, always.
| |
| checkSchemeOnly | back to summary |
|---|---|
| protected boolean checkSchemeOnly(String uri, String scheme) Checks whether the given uri string should be considered as a scheme-only URI. For some protocols - e.g. DNS, we might accept "dns://" as a valid URL denoting default DNS. For others - we might only accept "scheme:". Implementation Specification The default implementation of this method returns true if
the URI is of the form | |
| getHost | back to summary |
|---|---|
| public String getHost() Returns the host from the URI's authority part, or null
if no host is provided. If the host is an IPv6 literal, the
delimiting brackets are part of the returned value (see
| |
| getPath | back to summary |
|---|---|
| public String getPath() Returns the URI's path. The path is never null. Note that a slash following the authority part (or the scheme if there is no authority part) is part of the path. For example, the path of "http://host/a/b" is "/a/b". | |
| getPort | back to summary |
|---|---|
| public int getPort() Returns the port from the URI's authority part, or -1 if no port is provided. | |
| getQuery | back to summary |
|---|---|
| public String getQuery() Returns the URI's query part, or null if no query is provided. Note that a query always begins with a leading "?". | |
| getScheme | back to summary |
|---|---|
| public String getScheme() Returns the URI's scheme. | |
| init | back to summary |
|---|---|
| protected void init(String uri) throws MalformedURLException Initializes a Uri object given a URI string. This method must be called exactly once, and before any other Uri methods. | |
| isSchemeOnly | back to summary |
|---|---|
| protected boolean isSchemeOnly(String uri) A subclass of Implementation Specification The default implementation of this method returns false, always.
| |
| newInvalidURISchemeException | back to summary |
|---|---|
| protected MalformedURLException newInvalidURISchemeException(String uri) Creates a
| |
| newMalformedURLException | back to summary |
|---|---|
| private MalformedURLException newMalformedURLException(String prefix, String msg) | |
| parse | back to summary |
|---|---|
| private void parse(String uri, Uri. | |
| parseCompat | back to summary |
|---|---|
| private void parseCompat(String uri) throws MalformedURLException | |
| parseLegacy | back to summary |
|---|---|
| private void parseLegacy(String uri) throws MalformedURLException | |
| parseMode | back to summary |
|---|---|
| protected Uri. The parse mode for parsing this URI.
The default is | |
| parseStrict | back to summary |
|---|---|
| private void parseStrict(String uri) throws MalformedURLException | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the URI as a string. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final Uri. | COMPAT
Compatibility mode. |
| public static final Uri. | LEGACY
Legacy mode. |
| public static final Uri. | STRICT
Strict validation mode. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Uri. | |
| public static Uri. |
| COMPAT | back to summary |
|---|---|
| public static final Uri. Compatibility mode. The URI authority is syntactically validated. Rejects URI fragments unless explicitly supported by the subclass. This is the default. | |
| LEGACY | back to summary |
|---|---|
| public static final Uri. Legacy mode. In this mode, no validation is performed. | |
| STRICT | back to summary |
|---|---|
| public static final Uri. Strict validation mode.
Validate the URI syntactically using | |
| ParseMode | back to summary |
|---|---|
| private ParseMode() | |
| valueOf | back to summary |
|---|---|
| public static Uri. | |
| values | back to summary |
|---|---|
| public static Uri. | |