Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.util
Class URLResource  view URLResource download URLResource.java

java.lang.Object
  extended byorg.mortbay.util.Resource
      extended byorg.mortbay.util.URLResource
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BadResource, FileResource, JarResource

public class URLResource
extends Resource

Abstract resource class.

Version:
$Id: URLResource.java,v 1.6 2003/10/05 23:46:29 gregwilkins Exp $

Field Summary
protected  java.net.URLConnection _connection
           
protected  java.io.InputStream _in
           
protected  java.net.URL _url
           
protected  java.lang.String _urlString
           
private static org.apache.commons.logging.Log log
           
 
Fields inherited from class org.mortbay.util.Resource
_associate
 
Constructor Summary
protected URLResource(java.net.URL url, java.net.URLConnection connection)
           
 
Method Summary
 Resource addPath(java.lang.String path)
          Returns the resource contained inside the current resource with the given name
protected  boolean checkConnection()
           
 boolean delete()
          Deletes the given resource
 boolean equals(java.lang.Object o)
          Determine whether this Object is semantically equal to another Object.
 boolean exists()
          Returns true if the respresened resource exists.
 java.io.File getFile()
          Returns an File representing the given resource or NULL if this is not possible.
 java.io.InputStream getInputStream()
          Returns an input stream to the resource
 java.lang.String getName()
          Returns the name of the resource
 java.io.OutputStream getOutputStream()
          Returns an output stream to the resource
 java.net.URL getURL()
          Returns an URL representing the given resource
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 boolean isDirectory()
          Returns true if the respresenetd resource is a container/directory.
 long lastModified()
          Returns the last modified time
 long length()
          Return the length of the resource
 java.lang.String[] list()
          Returns a list of resource names contained in the given resource
 void release()
          Release any resources held by the resource.
 boolean renameTo(Resource dest)
          Rename the given resource
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class org.mortbay.util.Resource
cache, encode, finalize, getAlias, getAssociate, getListHTML, newResource, newResource, newSystemResource, setAssociate, writeTo
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

_url

protected java.net.URL _url

_urlString

protected java.lang.String _urlString

_connection

protected transient java.net.URLConnection _connection

_in

protected transient java.io.InputStream _in
Constructor Detail

URLResource

protected URLResource(java.net.URL url,
                      java.net.URLConnection connection)
Method Detail

checkConnection

protected boolean checkConnection()

release

public void release()
Release any resources held by the resource.

Specified by:
release in class Resource

exists

public boolean exists()
Returns true if the respresened resource exists.

Specified by:
exists in class Resource

isDirectory

public boolean isDirectory()
Returns true if the respresenetd resource is a container/directory. If the resource is not a file, resources ending with "/" are considered directories.

Specified by:
isDirectory in class Resource

lastModified

public long lastModified()
Returns the last modified time

Specified by:
lastModified in class Resource

length

public long length()
Return the length of the resource

Specified by:
length in class Resource

getURL

public java.net.URL getURL()
Returns an URL representing the given resource

Specified by:
getURL in class Resource

getFile

public java.io.File getFile()
                     throws java.io.IOException
Returns an File representing the given resource or NULL if this is not possible.

Specified by:
getFile in class Resource

getName

public java.lang.String getName()
Returns the name of the resource

Specified by:
getName in class Resource

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an input stream to the resource

Specified by:
getInputStream in class Resource

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException,
                                            java.lang.SecurityException
Returns an output stream to the resource

Specified by:
getOutputStream in class Resource

delete

public boolean delete()
               throws java.lang.SecurityException
Deletes the given resource

Specified by:
delete in class Resource

renameTo

public boolean renameTo(Resource dest)
                 throws java.lang.SecurityException
Rename the given resource

Specified by:
renameTo in class Resource

list

public java.lang.String[] list()
Returns a list of resource names contained in the given resource

Specified by:
list in class Resource

addPath

public Resource addPath(java.lang.String path)
                 throws java.io.IOException,
                        java.net.MalformedURLException
Returns the resource contained inside the current resource with the given name

Specified by:
addPath in class Resource

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equals

public boolean equals(java.lang.Object o)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.