URL(String spec)
public URL(String spec)
throws MalformedURLException
- Creates a
URL object from the String
representation.
This constructor is equivalent to a call to the two-argument
constructor with a null first argument.
- Parameters:
spec - the String to parse as a URL.
- Throws:
MalformedURLException - If the string specifies an
unknown protocol.- See Also:
URL(java.net.URL, java.lang.String)
URL(String protocol,
String host,
int port,
String file)
public URL(String protocol,
String host,
int port,
String file)
throws MalformedURLException
- Creates a
URL object from the specified
protocol, host, port
number, and file.
host can be expressed as a host name or a literal
IP address. If IPv6 literal address is used, it should be
enclosed in square brackets ('[' and ']'), as
specified by RFC 2732;
However, the literal IPv6 address format defined in RFC 2373: IP
Version 6 Addressing Architecture is also accepted.
Specifying a port number of -1
indicates that the URL should use the default port for the
protocol.
If this is the first URL object being created with the specified
protocol, a stream protocol handler object, an instance of
class URLStreamHandler, is created for that protocol:
- If the application has previously set up an instance of
URLStreamHandlerFactory as the stream handler factory,
then the createURLStreamHandler method of that instance
is called with the protocol string as an argument to create the
stream protocol handler.
- If no
URLStreamHandlerFactory has yet been set up,
or if the factory's createURLStreamHandler method
returns null, then the constructor finds the
value of the system property:
java.protocol.handler.pkgs
If the value of that system property is not null,
it is interpreted as a list of packages separated by a vertical
slash character '|'. The constructor tries to load
the class named:
<package>.<protocol>.Handler
where <package> is replaced by the name of the package
and <protocol> is replaced by the name of the protocol.
If this class does not exist, or if the class exists but it is not
a subclass of URLStreamHandler, then the next package
in the list is tried.
- If the previous step fails to find a protocol handler, then the
constructor tries to load from a system default package.
<system default package>.<protocol>.Handler
If this class does not exist, or if the class exists but it is not a
subclass of URLStreamHandler, then a
MalformedURLException is thrown.
No validation of the inputs is performed by this constructor.
- Parameters:
protocol - the name of the protocol to use.host - the name of the host.port - the port number on the host.file - the file on the host
- Throws:
MalformedURLException - if an unknown protocol is specified.- See Also:
System.getProperty(java.lang.String),
setURLStreamHandlerFactory(
java.net.URLStreamHandlerFactory),
URLStreamHandler,
URLStreamHandlerFactory.createURLStreamHandler(
java.lang.String)
URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler)
public URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler)
throws MalformedURLException
- Creates a
URL object from the specified
protocol, host, port
number, file, and handler. Specifying
a port number of -1 indicates that
the URL should use the default port for the protocol. Specifying
a handler of null indicates that the URL
should use a default stream handler for the protocol, as outlined
for:
java.net.URL#URL(java.lang.String, java.lang.String, int,
java.lang.String)
If the handler is not null and there is a security manager,
the security manager's checkPermission
method is called with a
NetPermission("specifyStreamHandler") permission.
This may result in a SecurityException.
No validation of the inputs is performed by this constructor.
- Parameters:
protocol - the name of the protocol to use.host - the name of the host.port - the port number on the host.file - the file on the hosthandler - the stream handler for the URL.
- Throws:
MalformedURLException - if an unknown protocol is specified.
SecurityException - if a security manager exists and its
checkPermission method doesn't allow
specifying a stream handler explicitly.- See Also:
System.getProperty(java.lang.String),
setURLStreamHandlerFactory(
java.net.URLStreamHandlerFactory),
URLStreamHandler,
URLStreamHandlerFactory.createURLStreamHandler(
java.lang.String),
SecurityManager.checkPermission(java.security.Permission),
NetPermission
URL(String protocol,
String host,
String file)
public URL(String protocol,
String host,
String file)
throws MalformedURLException
- Creates a URL from the specified
protocol
name, host name, and file name. The
default port for the specified protocol is used.
This method is equivalent to calling the four-argument
constructor with the arguments being protocol,
host, -1, and file.
No validation of the inputs is performed by this constructor.
- Parameters:
protocol - the name of the protocol to use.host - the name of the host.file - the file on the host.
- Throws:
MalformedURLException - if an unknown protocol is specified.- See Also:
URL(java.lang.String, java.lang.String,
int, java.lang.String)
URL(URL context,
String spec)
public URL(URL context,
String spec)
throws MalformedURLException
- Creates a URL by parsing the given spec within a specified context.
The new URL is created from the given context URL and the spec
argument as described in
RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
<scheme>://<authority><path>?<query>#<fragment>
The reference is parsed into the scheme, authority, path, query and
fragment parts. If the path component is empty and the scheme,
authority, and query components are undefined, then the new URL is a
reference to the current document. Otherwise, the fragment and query
parts present in the spec are used in the new URL.
If the scheme component is defined in the given spec and does not match
the scheme of the context, then the new URL is created as an absolute
URL based on the spec alone. Otherwise the scheme component is inherited
from the context URL.
If the authority component is present in the spec then the spec is
treated as absolute and the spec authority and path will replace the
context authority and path. If the authority component is absent in the
spec then the authority of the new URL will be inherited from the
context.
If the spec's path component begins with a slash character
"/" then the
path is treated as absolute and the spec path replaces the context path.
Otherwise, the path is treated as a relative path and is appended to the
context path, as described in RFC2396. Also, in this case,
the path is canonicalized through the removal of directory
changes made by occurences of ".." and ".".
For a more detailed description of URL parsing, refer to RFC2396.
- Parameters:
context - the context in which to parse the specification.spec - the String to parse as a URL.
- Throws:
MalformedURLException - if no protocol is specified, or an
unknown protocol is found.- See Also:
URL(java.lang.String, java.lang.String,
int, java.lang.String),
URLStreamHandler,
URLStreamHandler.parseURL(java.net.URL,
java.lang.String, int, int)
URL(URL context,
String spec,
URLStreamHandler handler)
public URL(URL context,
String spec,
URLStreamHandler handler)
throws MalformedURLException
- Creates a URL by parsing the given spec with the specified handler
within a specified context. If the handler is null, the parsing
occurs as with the two argument constructor.
- Parameters:
context - the context in which to parse the specification.spec - the String to parse as a URL.handler - the stream handler for the URL.
- Throws:
MalformedURLException - if no protocol is specified, or an
unknown protocol is found.
SecurityException - if a security manager exists and its
checkPermission method doesn't allow
specifying a stream handler.- See Also:
URL(java.lang.String, java.lang.String,
int, java.lang.String),
URLStreamHandler,
URLStreamHandler.parseURL(java.net.URL,
java.lang.String, int, int)
| | | | | |