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:

Ideally, java.net.URL should subclass URI.

Version:
0.3-2 18/06/1999
Author:
Ronald Tschalär
See Also:
rfc-2396

Constructor Index

 o URI(String)
Constructs a URI from the given string representation.
 o URI(String, String)
Constructs an opaque URI from the given parts.
 o URI(String, String, int, String)
Constructs a URI from the given parts.
 o URI(String, String, String)
Constructs a URI from the given parts, using the default port for this scheme (if known).
 o URI(String, String, String, int, String, String, String)
Constructs a URI from the given parts.
 o URI(URI, String)
Constructs a URI from the given string representation, relative to the given base URI.
 o URI(URL)
Construct a URI from the given URL.

Method Index

 o defaultPort(String)
Return the default port used by a given protocol.
 o equals(Object)
 o getFragment()
 o getHost()
 o getOpaque()
 o getPath()
 o getPort()
 o getQueryString()
 o getScheme()
 o getUserinfo()
 o 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.

 o main(String[])
Run test set.
 o toExternalForm()
 o toString()
 o toURL()
Will try to create a java.net.URL object from this URI.
 o usesGenericSyntax(String)

Constructors

 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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

Methods

 o usesGenericSyntax
 public static boolean usesGenericSyntax(String scheme)
Returns:
true if the scheme should be parsed according to the generic-URI syntax
 o 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
 o getScheme
 public String getScheme()
Returns:
the scheme (often also referred to as protocol)
 o getOpaque
 public String getOpaque()
Returns:
the opaque part, or null if this URI is generic
 o getHost
 public String getHost()
Returns:
the host
 o getPort
 public int getPort()
Returns:
the port, or -1 if it's the default port
 o getUserinfo
 public String getUserinfo()
Returns:
the user info
 o getPath
 public String getPath()
Returns:
the path; this includes the query string
 o getQueryString
 public String getQueryString()
Returns:
the query string
 o getFragment
 public String getFragment()
Returns:
the fragment
 o 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
 o 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
 o toExternalForm
 public String toExternalForm()
Returns:
a string representation of this URI suitable for use in links, headers, etc.
 o toString
 public String toString()
Overrides:
toString in class Object
See Also:
toExternalForm
 o 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
 o 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