|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.net.URL
public final class URL
An instance of class URL specifies the location of a resource on the world wide web as specified by RFC 1738.
| Field Summary | |
|---|---|
(package private) URLStreamHandler |
strmHandler
The URL Stream (protocol) Handler |
| Constructor Summary | |
|---|---|
URL(String spec)
Constructs a new URL instance by parsing the specification. |
|
URL(String protocol,
String host,
int port,
String file)
Constructs a new URL instance using the arguments provided. |
|
URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler)
Constructs a new URL instance using the arguments provided. |
|
URL(String protocol,
String host,
String file)
Constructs a new URL instance using the arguments provided. |
|
URL(URL context,
String spec)
Constructs a new URL by parsing the specification given by spec and using the context provided by
context. |
|
URL(URL context,
String spec,
URLStreamHandler handler)
Constructs a new URL by parsing the specification given by spec and using the context provided by
context. |
|
| Method Summary | |
|---|---|
boolean |
equals(Object o)
Compares the argument to the receiver, and returns true if they represent the same URL. |
(package private) void |
fixURL(boolean fixHost)
|
String |
getAuthority()
Returns the authority component of this URL. |
Object |
getContent()
Returns an Object representing the resource referenced by this URL. |
Object |
getContent(Class[] types)
Returns an Object representing the resource referenced by this URL. |
int |
getDefaultPort()
Returns the default port for this URL as defined by the URLStreamHandler. |
String |
getFile()
Returns the file component of this URL. |
String |
getHost()
Returns the host component of this URL. |
String |
getPath()
Returns the path component of this URL. |
int |
getPort()
Returns the port component of this URL. |
String |
getProtocol()
Returns the protocol component of this URL. |
String |
getQuery()
Returns the query component of this URL. |
String |
getRef()
Returns the reference component of this URL. |
(package private) URLStreamHandler |
getStreamHandler()
|
String |
getUserInfo()
Returns the user info component of this URL. |
int |
hashCode()
Returns a hash code for this URL object. |
URLConnection |
openConnection()
Creates a connection to this URL using the appropriate ProtocolHandler. |
URLConnection |
openConnection(Proxy proxy)
The method is the same as openConnection() except that it
uses the proxy to establish a connection to this URL using
appropriate ProtocolHandler. |
InputStream |
openStream()
Returns a stream for reading from this URL. |
boolean |
sameFile(URL otherURL)
Returns true if the receiver and the argument refer to the same file. |
protected void |
set(String protocol,
String host,
int port,
String file,
String ref)
Sets the properties of this URL using the provided arguments. |
protected void |
set(String protocol,
String host,
int port,
String authority,
String userInfo,
String path,
String query,
String ref)
Sets the properties of this URL using the provided arguments. |
(package private) void |
setupStreamHandler()
Sets the receiver's stream handler to one which is appropriate for its protocol. |
static void |
setURLStreamHandlerFactory(URLStreamHandlerFactory streamFactory)
Sets the URL Stream (protocol) handler factory. |
String |
toExternalForm()
Create and return the String representation of this URL. |
String |
toString()
Returns a string containing a concise, human-readable description of the receiver. |
URI |
toURI()
Creates a URI related with this URL |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
transient URLStreamHandler strmHandler
| Constructor Detail |
|---|
public URL(String spec)
throws MalformedURLException
spec - java.lang.String a URL specification.
MalformedURLException - if the spec could not be parsed as an URL.
public URL(URL context,
String spec)
throws MalformedURLException
spec and using the context provided by
context.
The protocol of the specification is obtained by parsing the
spec string.
If the spec does not specify a protocol:
null, then a
MalformedURLException.null, then the protocol is
obtained from the context.spec does specify a protocol:
null, or specifies a different
protocol than the spec, the context is ignored.null and specifies the same
protocol as the specification, the properties of the new URL
are obtained from the context.
context - java.net.URL URL to use as context.spec - java.lang.String a URL specification.
MalformedURLException - if the spec could not be parsed as an URL.
public URL(URL context,
String spec,
URLStreamHandler handler)
throws MalformedURLException
spec and using the context provided by
context.
If the handler argument is non-null, a security check is made to verify that user-defined protocol handlers can be specified.
The protocol of the specification is obtained by parsing the
spec string.
If the spec does not specify a protocol:
null, then a
MalformedURLException.null, then the protocol is
obtained from the context.spec does specify a protocol:
null, or specifies a different
protocol than the spec, the context is ignored.null and specifies the same
protocol as the specification, the properties of the new URL
are obtained from the context.
context - java.net.URL URL to use as context.spec - java.lang.String a URL specification.handler - java.net.URLStreamHandler a URLStreamHandler.
MalformedURLException - if the spec could not be parsed as an URL
public URL(String protocol,
String host,
String file)
throws MalformedURLException
protocol - String the protocol for the URL.host - String the name of the host.file - the name of the resource.
MalformedURLException - if the parameters do not represent a valid URL.
public URL(String protocol,
String host,
int port,
String file)
throws MalformedURLException
protocol - String the protocol for the URL.host - String the name of the host.port - int the port number.file - String the name of the resource.
MalformedURLException - if the parameters do not represent a valid URL.
public URL(String protocol,
String host,
int port,
String file,
URLStreamHandler handler)
throws MalformedURLException
If the handler argument is non-null, a security check is made to verify that user-defined protocol handlers can be specified.
protocol - the protocol for the URL.host - the name of the host.port - the port number.file - the name of the resource.handler - the stream handler that this URL uses.
MalformedURLException - if the parameters do not represent an URL.| Method Detail |
|---|
public static void setURLStreamHandlerFactory(URLStreamHandlerFactory streamFactory)
A security check is performed to verify that the current Policy allows the stream handler factory to be set.
streamFactory - URLStreamHandlerFactory The factory to use for finding stream
handlers.void fixURL(boolean fixHost)
protected void set(String protocol,
String host,
int port,
String file,
String ref)
URLStreamHandler
code.
protocol - the new protocol.host - the new host name.port - the new port number.file - the new file component.ref - the new reference.URL,
URLStreamHandlerpublic boolean equals(Object o)
equals in class Objecto - the object to compare with this URL.
true if the object is the same as this URL,
false otherwise.hashCodepublic boolean sameFile(URL otherURL)
otherURL - URL to compare against.
public int hashCode()
hashCode in class ObjectObject.equals(java.lang.Object)void setupStreamHandler()
Note that this will overwrite any existing stream handler with the new one. Senders must check if the strmHandler is null before calling the method if they do not want this behavior (a speed optimization).
public final Object getContent()
throws IOException
IOException - If an error occurred obtaining the content.
public final Object getContent(Class[] types)
throws IOException
types - The list of acceptable content types
IOException - If an error occurred obtaining the content.
public final InputStream openStream()
throws IOException
IOException - if a stream could not be created.
public URLConnection openConnection()
throws IOException
IOException - if the connection to the URL is not possible.
public URI toURI()
throws URISyntaxException
URISyntaxException - if this URL cannot format into URI
public URLConnection openConnection(Proxy proxy)
throws IOException
openConnection() except that it
uses the proxy to establish a connection to this URL using
appropriate ProtocolHandler.
proxy - the proxy which is used to make the connection
IOException - thrown if an IO error occurs during connection
establishment
SecurityException - thrown if a security manager is installed and it denies
the permission to connect to the proxy.
IllegalArgumentException - thrown if the proxy is null or of an invalid type.
UnsupportedOperationException - thrown if the protocol handler doesn't support this
method.public String toString()
toString in class Objectpublic String toExternalForm()
toString(),
URL,
URLStreamHandler.toExternalForm(URL)public String getFile()
public String getHost()
public int getPort()
public String getProtocol()
public String getRef()
public String getQuery()
public String getPath()
public String getUserInfo()
public String getAuthority()
protected void set(String protocol,
String host,
int port,
String authority,
String userInfo,
String path,
String query,
String ref)
URLStreamHandler
code.
protocol - the new protocol.host - the new host name.port - the new port number.authority - the new authority.userInfo - the new user info.path - the new path component.query - the new query.ref - the new reference.URL,
URLStreamHandlerURLStreamHandler getStreamHandler()
public int getDefaultPort()
URLStreamHandler.getDefaultPort()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||