All Packages Class Hierarchy This Package Previous Next Index
Class HTTPClient.URI
java.lang.Object
|
+----HTTPClient.URI
- public class URI
- extends Object
This class represents a generic URI, as defined in RFC-2396.
This is similar to java.net.URL, with the following enhancements:
- it doesn't require a URLStreamhandler to exist for the scheme; this
allows this class to be used to hold any URI, construct absolute
URIs from relative ones, etc.
- it handles escapes correctly
- equals() works correctly
- relative URIs are correctly constructed
- it has methods for accessing various fields such as userinfo,
fragment, params, etc.
- it handles less common forms of resources such as the "*" used in
http URLs.
Ideally, java.net.URL should subclass URI.
- Version:
- 0.3-2 18/06/1999
- Author:
- Ronald Tschalär
- See Also:
- rfc-2396
-
URI(String)
- Constructs a URI from the given string representation.
-
URI(String, String)
- Constructs an opaque URI from the given parts.
-
URI(String, String, int, String)
- Constructs a URI from the given parts.
-
URI(String, String, String)
- Constructs a URI from the given parts, using the default port for
this scheme (if known).
-
URI(String, String, String, int, String, String, String)
- Constructs a URI from the given parts.
-
URI(URI, String)
- Constructs a URI from the given string representation, relative to
the given base URI.
-
URI(URL)
- Construct a URI from the given URL.
-
defaultPort(String)
- Return the default port used by a given protocol.
-
equals(Object)
-
-
getFragment()
-
-
getHost()
-
-
getOpaque()
-
-
getPath()
-
-
getPort()
-
-
getQueryString()
-
-
getScheme()
-
-
getUserinfo()
-
-
isGenericURI()
- Does the scheme specific part of this URI use the generic-URI syntax?
In general URI are split into two categories: opaque-URI and
generic-URI.
-
main(String[])
- Run test set.
-
toExternalForm()
-
-
toString()
-
-
toURL()
- Will try to create a java.net.URL object from this URI.
-
usesGenericSyntax(String)
-
URI
public URI(String uri) throws ParseException
- Constructs a URI from the given string representation. The string
must be an absolute URI.
- Parameters:
- uri - a String containing an absolute URI
- Throws: ParseException
- if no scheme can be found or a specified
port cannot be parsed as a number
URI
public URI(URI base,
String rel_uri) throws ParseException
- Constructs a URI from the given string representation, relative to
the given base URI.
- Parameters:
- base - the base URI, relative to which rel_uri
is to be parsed
- rel_uri - a String containing a relative or absolute URI
- Throws: ParseException
- if base is null and
rel_uri is not an absolute URI, or
if base is not null and the scheme
is not known to use the generic syntax, or
if a given port cannot be parsed as a number
URI
public URI(URL url) throws ParseException
- Construct a URI from the given URL.
- Parameters:
- url - the URL
- Throws: ParseException
- if
url.toExternalForm()
generates
an invalid string representation
URI
public URI(String scheme,
String host,
String path) throws ParseException
- Constructs a URI from the given parts, using the default port for
this scheme (if known).
- Parameters:
- scheme - the scheme (sometimes known as protocol)
- host - the host
- path - the path part
- Throws: ParseException
- if scheme is null
URI
public URI(String scheme,
String host,
int port,
String path) throws ParseException
- Constructs a URI from the given parts.
- Parameters:
- scheme - the scheme (sometimes known as protocol)
- host - the host
- port - the port
- path - the path part
- Throws: ParseException
- if scheme is null
URI
public URI(String scheme,
String userinfo,
String host,
int port,
String path,
String query,
String fragment) throws ParseException
- Constructs a URI from the given parts. Any part except for the
the scheme may be null.
- Parameters:
- scheme - the scheme (sometimes known as protocol)
- userinfo - the userinfo
- host - the host
- port - the port
- path - the path part
- query - the query string
- fragment - the fragment identifier
- Throws: ParseException
- if scheme is null
URI
public URI(String scheme,
String opaque) throws ParseException
- Constructs an opaque URI from the given parts.
- Parameters:
- scheme - the scheme (sometimes known as protocol)
- opaque - the opaque part
- Throws: ParseException
- if scheme is null
usesGenericSyntax
public static boolean usesGenericSyntax(String scheme)
- Returns:
- true if the scheme should be parsed according to the
generic-URI syntax
defaultPort
public static final int defaultPort(String protocol)
- Return the default port used by a given protocol.
- Parameters:
- protocol - the protocol
- Returns:
- the port number, or 0 if unknown
getScheme
public String getScheme()
- Returns:
- the scheme (often also referred to as protocol)
getOpaque
public String getOpaque()
- Returns:
- the opaque part, or null if this URI is generic
getHost
public String getHost()
- Returns:
- the host
getPort
public int getPort()
- Returns:
- the port, or -1 if it's the default port
getUserinfo
public String getUserinfo()
- Returns:
- the user info
getPath
public String getPath()
- Returns:
- the path; this includes the query string
getQueryString
public String getQueryString()
- Returns:
- the query string
getFragment
public String getFragment()
- Returns:
- the fragment
isGenericURI
public boolean isGenericURI()
- Does the scheme specific part of this URI use the generic-URI syntax?
In general URI are split into two categories: opaque-URI and
generic-URI. The generic-URI syntax is the syntax most are familiar
with from URLs such as ftp- and http-URLs, which is roughly:
generic-URI = scheme ":" [ "//" server ] [ "/" ] [ path_segments ] [ "?" query ]
(see draft-fielding-uri-syntax-03 for exact syntax). Only URLs
using the generic-URI syntax can be used to create and resolve
relative URIs.
Whether a given scheme is parsed according to the generic-URI
syntax or wether it is treated as opaque is determined by an internal
table of URI schemes.
- See Also:
- rfc-2396
toURL
public URL toURL() throws MalformedURLException
- Will try to create a java.net.URL object from this URI.
- Returns:
- the URL
- Throws: MalformedURLException
- if no handler is available for the
scheme
toExternalForm
public String toExternalForm()
- Returns:
- a string representation of this URI suitable for use in
links, headers, etc.
toString
public String toString()
- Overrides:
- toString in class Object
- See Also:
- toExternalForm
equals
public boolean equals(Object other)
- Returns:
- true if other is either a URI or URL and it
matches the current URI
- Overrides:
- equals in class Object
main
public static void main(String args[]) throws Exception
- Run test set.
- Throws: Exception
- if any test fails
All Packages Class Hierarchy This Package Previous Next Index