    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
implements Serializable

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.

##

URL(String)
  Creates a URL from the unparsed absolute URL.
URL(String, String, int, String)
  Creates an absolute URL from the specified protocol, host, port and file.
URL(String, String, String)
  Creates an absolute URL from the specified protocol, host, and file.
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.

##

equals(Object)
  Compares two URLs.
getContent()
  Gets the contents from this opened connection.
getFile()
  Gets the file name.
getHost()
  Gets the host name, if applicable.
getPort()
  Gets the port number.
getProtocol()
  Gets the protocol name.
getRef()
  Gets the ref.
hashCode()
  Creates an integer suitable for hash table indexing.
openConnection()
  Creates (if not already in existance) a URLConnection object that contains a connection to the remote object referred to by the URL.
openStream()
  Opens an input stream.
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.
set(String, String, int, String, String)
  Sets the fields of the URL.
setURLStreamHandlerFactory(URLStreamHandlerFactory)
  Sets the URLStreamHandler factory.
toExternalForm()
  Reverses the parsing of the URL.
toString()
  Converts to a human-readable form.

##

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.

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.

URL

      public URL(String spec) throws MalformedURLException

  Creates a URL from the unparsed absolute URL.

  Parameters:
    spec - the URL String to parse

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 is parsed 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.

##

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

getPort

      public int getPort()

  Gets the port number. Returns -1 if the port is not set.

getProtocol

      public String getProtocol()

  Gets the protocol name.

getHost

      public String getHost()

  Gets the host name, if applicable. For "file" protocol, this is an empty string.

getFile

      public String getFile()

  Gets the file name.

getRef

      public String getRef()

  Gets the ref.

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

hashCode

      public int hashCode()

  Creates an integer suitable for hash table indexing.

  Overrides:
    hashCode in class Object

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.

toString

      public String toString()

  Converts to a human-readable form.

  Returns:
    the textual representation.
  Overrides:
    toString in class Object

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).

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

openStream

      public final InputStream openStream() throws IOException

  Opens an input stream.

  Throws: IOException
    If an I/O exception has occurred.

getContent

      public final Object getContent() throws IOException

  Gets the contents from this opened connection.

  Throws: IOException
    If an I/O exception has occurred.

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