Class java.net.URL
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.net.URL

java.lang.Object
   |
   +----java.net.URL

public final class URL
extends Object
Class URL represents a Uniform Reference Locator -- a reference to an object on the World Wide Web. This is a constant object, once it is created, its fields cannot be changed.

Constructor Index

 o URL(String)
Creates a URL from the unparsed absolute URL.
 o URL(String, String, int, String)
Creates an absolute URL from the specified protocol, host, port and file.
 o URL(String, String, String)
Creates an absolute URL from the specified protocol, host, and file.
 o URL(URL, String)
Creates a URL from the unparsed URL in the specified context.If spec is an absolute URL it is used as is.

Method Index

 o equals(Object)
Compares two URLs.
 o getContent()
Gets the contents from this opened connection.
 o getFile()
Gets the file name.
 o getHost()
Gets the host name.
 o getPort()
Gets the port number.
 o getProtocol()
Gets the protocol name.
 o getRef()
Gets the ref.
 o hashCode()
Creates an integer suitable for hash table indexing.
 o openConnection()
Creates (if not already in existance) a URLConnection object that contains a connection to the remote object referred to by the URL.
 o openStream()
Opens an input stream.
 o sameFile(URL)
Compares two URLs, excluding the "ref" fields: sameFile is true if the true references the same remote object, but not necessarily the same subpiece of that object.
 o set(String, String, int, String, String)
Sets the fields of the URL.
 o setURLStreamHandlerFactory(URLStreamHandlerFactory)
Sets the URLStreamHandler factory.
 o toExternalForm()
Reverses the parsing of the URL.
 o toString()
Converts to a human-readable form.

Constructors

 o URL
  public URL(String protocol,
             String host,
             int port,
             String file) throws MalformedURLException
Creates an absolute URL from the specified protocol, host, port and file.
Parameters:
protocol - the protocol to use
host - the host to connect to
port - the port at that host to connect to
file - the file on that host
Throws: MalformedURLException
If an unknown protocol is found.
 o URL
  public URL(String protocol,
             String host,
             String file) throws MalformedURLException
Creates an absolute URL from the specified protocol, host, and file. The port number used will be the default for the protocol.
Parameters:
protocol - the protocol to use
host - the host to connect to
file - the file on that host
Throws: MalformedURLException
If an unknown protocol is found.
 o URL
  public URL(String spec) throws MalformedURLException
Creates a URL from the unparsed absolute URL.
Parameters:
spec - the URL String to parse
 o URL
  public URL(URL context,
             String spec) throws MalformedURLException
Creates a URL from the unparsed URL in the specified context.If spec is an absolute URL it is used as is. Otherwise it isparsed in terms of the context. Context may be null (indicating no context).
Parameters:
context - the context to parse the URL to
spec - the URL String to parse
Throws: MalformedURLException
If the protocol is equal to null.

Methods

 o set
  protected void set(String protocol,
                     String host,
                     int port,
                     String file,
                     String ref)
Sets the fields of the URL. This is not a public method so that only URLStreamHandlers can modify URL fields. URLs are otherwise constant. REMIND: this method will be moved to URLStreamHandler
Parameters:
protocol - the protocol to use
host - the host name to connecto to
port - the protocol port to connect to
file - the specified file name on that host
ref - the reference
 o getPort
  public int getPort()
Gets the port number. Returns -1 if the port is not set.
 o getProtocol
  public String getProtocol()
Gets the protocol name.
 o getHost
  public String getHost()
Gets the host name.
 o getFile
  public String getFile()
Gets the file name.
 o getRef
  public String getRef()
Gets the ref.
 o equals
  public boolean equals(Object obj)
Compares two URLs.
Parameters:
obj - the URL to compare against.
Returns:
true if and only if they are equal, false otherwise.
Overrides:
equals in class Object
 o hashCode
  public int hashCode()
Creates an integer suitable for hash table indexing.
Overrides:
hashCode in class Object
 o sameFile
  public boolean sameFile(URL other)
Compares two URLs, excluding the "ref" fields: sameFile is true if the true references the same remote object, but not necessarily the same subpiece of that object.
Parameters:
other - the URL to compare against.
Returns:
true if and only if they are equal, false otherwise.
 o toString
  public String toString()
Converts to a human-readable form.
Returns:
the textual representation.
Overrides:
toString in class Object
 o toExternalForm
  public String toExternalForm()
Reverses the parsing of the URL.
Returns:
the textual representation of the fully qualified URL (i.e. after the context and canonicalization have been applied).
 o openConnection
  public URLConnection openConnection() throws IOException
Creates (if not already in existance) a URLConnection object that contains a connection to the remote object referred to by the URL. Invokes the appropriate protocol handler. Failure is indicated by throwing an exception.
Throws: IOException
If an I/O exception has occurred.
See Also:
URLConnection
 o openStream
  public final InputStream openStream() throws IOException
Opens an input stream.
Throws: IOException
If an I/O exception has occurred.
 o getContent
  public final Object getContent() throws IOException
Gets the contents from this opened connection.
Throws: IOException
If an I/O exception has occurred.
 o setURLStreamHandlerFactory
  public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
Sets the URLStreamHandler factory.
Parameters:
fac - the desired factory
Throws: Error
If the factory has already been defined.

All Packages  Class Hierarchy  This Package  Previous  Next  Index