public class URI extends Object
1) For socket related URIs, the toString() methods use semicolon (;) as the query marker instead of the normal question mark (?), and the parameters are separated with a semicolon instead of the normal ampersand (&). With this, the URIs are compatible with those used by J2ME socket connectors. (The Java 6 API treats socket URIs as URNs). 2) This implementation does not yet "rigorously parse IPv4" addresses like the Java 6 version does, the host address is simply stored as provided by the caller. This will be enhanced using the InetAddress class when available. 3) The characters defined as legal "other characters" are not all interpreted correctly, which just means some unicode characters will get encoded that aren't required to be. The method URIHelper.isLegalUnicode() needs to be inspected further. 4) Because of 3) toASCIIString() and toString() return the same value. TODO: finish this list
http://docs.oracle.com/javase/6/docs/api/java/net/URI.html
,
http://en.wikipedia.org/wiki/Uniform_resource_identifier
,
http://en.wikipedia.org/wiki/Uniform_resource_name
,
http://www.ietf.org/rfc/rfc2396.txt
,
http://www.ietf.org/rfc/rfc2732.txt
,
http://tools.ietf.org/html/rfc2141
Constructor and Description |
---|
URI(String uriString)
Constructor that parses its values from a URI string.
|
URI(String scheme,
String ssp,
String fragment)
Constructor for building URNs.
|
URI(String scheme,
String userInfo,
String host,
int port,
String path,
String query,
String fragment)
Constructor to create a new URI object.
|
URI(String scheme,
String authority,
String path,
String query,
String fragment)
Constructor to create a new URI object.
|
Modifier and Type | Method and Description |
---|---|
static URI |
create(String uriString)
A convenience factory method, intended to be used when the URI string is
known to be valid (ie.
|
boolean |
equals(Object that)
Indicates whether some other object is "equal to" this one.
|
String |
getAuthority() |
String |
getFragment()
Get the decoded fragment (otherwise known as the "reference" or
"anchor") part of the uri.
|
String |
getHost()
Get the host name part of the URI.
|
String |
getPath()
Get the decoded path part of the uri.
|
int |
getPort()
Get the port number for this URI.
|
String |
getQuery()
Get the decoded query part of the uri.
|
String |
getRawAuthority() |
String |
getRawFragment()
Get the encoded fragment (otherwise known as the "reference" or
"anchor") part of the uri.
|
String |
getRawPath()
Get the encoded path part of the uri.
|
String |
getRawQuery()
Get the encoded query part of the uri.
|
String |
getRawSchemeSpecificPart() |
String |
getRawUserInfo() |
String |
getScheme()
Get the scheme part of the URI.
|
String |
getSchemeSpecificPart() |
String |
getUserInfo() |
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isAbsolute() |
boolean |
isOpaque() |
URI |
normalize()
Normalize a URI by removing any "./" segments, and "path/../" segments.
|
protected void |
parseSchemeSpecificPart(String ssp,
boolean encode)
Utility method used to parse a given scheme specific part.
|
protected void |
parseURI(String uriString)
Rather than attempting to process the uri string in a linear fashion,
this implementation works its way from outside-in
|
protected String |
rebuildSchemeSpecificPart()
Utility method to construct the scheme specific part from the uri
segments (less scheme and fragment)
|
URI |
relativize(URI uri)
Create a relative URI object against this URI, given the uri parameter.
|
URI |
resolve(URI uri)
Resolve a relative URI by merging it with this URI.
|
protected void |
setAuthority(String newAuthority,
boolean encode)
Utility method - set the part, ensuring valid format.
|
protected void |
setAuthority(String host,
int port,
String userInfo,
boolean encode)
Utility method to construct the authority segment from given host, port,
and userinfo segments.
|
protected void |
setFragment(String fragment,
boolean encode)
Utility method to set the fragment.
|
protected void |
setPath(String path,
boolean encode)
Utility method to set the path.
|
protected void |
setQuery(String query,
boolean encode)
Utility method to set the query.
|
protected void |
setScheme(String scheme)
Utility method - set the scheme, ensuring valid format, and determining
the query separator to use.
|
protected void |
setSchemeSpecificPart(String ssp,
boolean encode)
Utility method - set the scheme specific part, ensuring valid format.
|
String |
toASCIIString() |
String |
toString()
Returns a string representation of the object.
|
public URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException
scheme
- the scheme of the URI (for URLs, this would be the
protocol), or null for relative URIs.userInfo
- the unencoded userinfo segment (ie. username:password) or
null.host
- the hostname or address, or null.port
- the host port, or -1.path
- the unencoded path segment.query
- the unencoded query segment.fragment
- the unencoded fragment (often referred to as the
'reference' or 'anchor'), or null.URISyntaxException
- if any of the fragments are invalid.public URI(String scheme, String authority, String path, String query, String fragment) throws URISyntaxException
scheme
- the scheme of the URI (for URLs, this would be the
protocol), or null for relative URIs.authority
- the unencoded authority segment (ie.
username:password@host:port, or simply: host) or null.path
- the unencoded path segment.query
- the unencoded query segment.fragment
- the unencoded fragment (often referred to as the
'reference' or 'anchor'), or null.URISyntaxException
- if any of the fragments are invalid.public URI(String scheme, String ssp, String fragment) throws URISyntaxException
scheme
- ssp
- the unencoded scheme specific part (everything except the
scheme and fragment)fragment
- the unencoded fragment, or nullURISyntaxException
- if any of the segments are invalid.public URI(String uriString) throws URISyntaxException
uriString
- a full encoded URI in string form to be parsed.URISyntaxException
- if any of the parsed segments are invalid.protected void setScheme(String scheme) throws URISyntaxException
URISyntaxException
http://en.wikipedia.org/wiki/Uniform_resource_name
protected void setSchemeSpecificPart(String ssp, boolean encode) throws URISyntaxException
URISyntaxException
protected void setAuthority(String newAuthority, boolean encode) throws URISyntaxException
URISyntaxException
protected void setQuery(String query, boolean encode) throws URISyntaxException
query
- encode
- URISyntaxException
protected void setPath(String path, boolean encode) throws URISyntaxException
path
- encode
- URISyntaxException
protected void setAuthority(String host, int port, String userInfo, boolean encode) throws URISyntaxException
host
- port
- userInfo
- encode
- URISyntaxException
protected void setFragment(String fragment, boolean encode)
fragment
- encode
- protected String rebuildSchemeSpecificPart()
public static URI create(String uriString)
uriString
- URI address as a stringprotected void parseURI(String uriString) throws URISyntaxException
uriString
- URISyntaxException
protected void parseSchemeSpecificPart(String ssp, boolean encode) throws URISyntaxException
ssp
- scheme specific part (the URI without the scheme or fragment
included).encode
- true if ssp needs to be encoded, false if ssp needs to be
verified.URISyntaxException
- if the ssp is invalid.public String getScheme()
public String getHost()
public int getPort()
public String getPath()
public String getRawPath()
public String getQuery()
public String getRawQuery()
public String getFragment()
public String getRawFragment()
public String getSchemeSpecificPart()
public String getRawSchemeSpecificPart()
public String getAuthority()
public String getRawAuthority()
public String getUserInfo()
public String getRawUserInfo()
public boolean isOpaque()
public boolean isAbsolute()
public String toString()
Object
public String toASCIIString()
public URI relativize(URI uri)
uri
- ://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize
%28java.net.URI%29
public URI resolve(URI uri)
uri
- a URI to resolve against this URI.://docs.oracle.com/javase/6/docs/api/java/net/URI.html#resolve%28
java.net.URI%29
public URI normalize()
://docs.oracle.com/javase/6/docs/api/java/net/URI.html#normalize%
28%29
public int hashCode()
Object
public boolean equals(Object that)
Object