public class URI
- Object
- URI
An implementation of a Univeral Resource Identifier (URI). While the output is mostly compatible with the Java 6 API, there are a few somewhat subtle differences:
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
Constructors
Methods
Inherited methods
Constructor details
URI
public URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
throws URISyntaxExceptionParameters
schemeString- the scheme of the URI (for URLs, this would be the protocol), or null for relative URIs.
userInfoString- the unencoded userinfo segment (ie. username:password) or null.
hostString- the hostname or address, or null.
portint- the host port, or -1.
pathString- the unencoded path segment.
queryString- the unencoded query segment.
fragmentString- the unencoded fragment (often referred to as the ‘reference’ or ‘anchor’), or null.
Throws
URISyntaxException- if any of the fragments are invalid.
URI
public URI(String scheme, String authority, String path, String query, String fragment)
throws URISyntaxExceptionParameters
schemeString- the scheme of the URI (for URLs, this would be the protocol), or null for relative URIs.
authorityString- the unencoded authority segment (ie. username:password@host:port, or simply: host) or null.
pathString- the unencoded path segment.
queryString- the unencoded query segment.
fragmentString- the unencoded fragment (often referred to as the ‘reference’ or ‘anchor’), or null.
Throws
URISyntaxException- if any of the fragments are invalid.
URI
public URI(String scheme, String ssp, String fragment)
throws URISyntaxExceptionConstructor for building URNs. The ssp and fragment should be unencoded values - they will be encoded as required.
Examples: mailto:user@codenameone.com sms:+5555551212 tel:+5555551212 isbn:9781935182962
Parameters
schemeString- Not documented.
sspString- the unencoded scheme specific part (everything except the scheme and fragment)
fragmentString- the unencoded fragment, or null
Throws
URISyntaxException- if any of the segments are invalid.
URI
public URI(String uriString)
throws URISyntaxExceptionParameters
uriStringString- a full encoded URI in string form to be parsed.
Throws
URISyntaxException- if any of the parsed segments are invalid.
Method details
setScheme
protected void setScheme(String scheme)
throws URISyntaxExceptionThrows
setSchemeSpecificPart
protected void setSchemeSpecificPart(String ssp, boolean encode)
throws URISyntaxExceptionThrows
setAuthority
protected void setAuthority(String newAuthority, boolean encode)
throws URISyntaxExceptionThrows
setQuery
protected void setQuery(String query, boolean encode)
throws URISyntaxExceptionThrows
setPath
protected void setPath(String path, boolean encode)
throws URISyntaxExceptionThrows
setAuthority
protected void setAuthority(String host, int port, String userInfo, boolean encode)
throws URISyntaxExceptionThrows
setFragment
protected void setFragment(String fragment, boolean encode)rebuildSchemeSpecificPart
protected String rebuildSchemeSpecificPart()create
public static URI create(String uriString)A convenience factory method, intended to be used when the URI string is known to be valid (ie. a static application URI), so it is not needed for the caller to handle invalid syntax. NOTE: this is not away to avoid handling errors altogether - passing an invalid URI string will result in an IllegalArgumentException being thrown. The benefit here is that the compiler will not complain if you don’t explicitly handle the error at compile time.
When handling a user-editable URI, use the URI constructors instead.
Parameters
uriStringString- URI address as a string
Returns
parseURI
protected void parseURI(String uriString)
throws URISyntaxExceptionThrows
parseSchemeSpecificPart
protected void parseSchemeSpecificPart(String ssp, boolean encode)
throws URISyntaxExceptionParameters
sspString- scheme specific part (the URI without the scheme or fragment included).
encodeboolean- true if ssp needs to be encoded, false if ssp needs to be verified.
Throws
URISyntaxException- if the ssp is invalid.
getScheme
public String getScheme()Returns
getHost
public String getHost()Returns
getPort
public int getPort()Returns
getPath
public String getPath()Returns
getRawPath
public String getRawPath()Returns
getQuery
public String getQuery()Returns
getRawQuery
public String getRawQuery()Returns
getFragment
public String getFragment()Returns
getRawFragment
public String getRawFragment()Returns
getSchemeSpecificPart
public String getSchemeSpecificPart()Returns
getRawSchemeSpecificPart
public String getRawSchemeSpecificPart()Returns
getAuthority
public String getAuthority()Returns
getRawAuthority
public String getRawAuthority()Returns
getUserInfo
public String getUserInfo()Returns
getRawUserInfo
public String getRawUserInfo()Returns
isOpaque
public boolean isOpaque()Returns
isAbsolute
public boolean isAbsolute()Returns
toString
public String toString()Returns
toASCIIString
public String toASCIIString()Returns
relativize
public URI relativize(URI uri)resolve
public URI resolve(URI uri)Parameters
uriURI- a URI to resolve against this URI.
Returns
normalize
public URI normalize()Returns
hashCode
public int hashCode()equals
public boolean equals(Object that)