org.mortbay.util
Class Resource

java.lang.Object
  |
  +--org.mortbay.util.Resource
Direct Known Subclasses:
JarResource

public class Resource
extends java.lang.Object

Class that represents a resource accessible through the file or URL

Version:
$Id: Resource.java,v 1.5 2001/10/19 00:24:01 gregwilkins Exp $
Author:
Nuno Preguiça, Greg Wilkins (gregw)

Method Summary
 Resource addPath(java.lang.String path)
          Returns the resource contained inside the current resource with the given name
static java.lang.String canonicalPath(java.lang.String path)
          Convert a path to a cananonical form.
 boolean delete()
          Deletes the given resource
 boolean equals(java.lang.Object o)
           
 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()
           
 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
static Resource newResource(java.lang.String resource)
          Construct a resource from a string.
static Resource newResource(java.net.URL url)
           
static Resource newSystemResource(java.lang.String resource)
          Construct a system resource from a string.
 void release()
          Release any resources held by the resource.
 boolean renameTo(Resource dest)
          Rename the given resource
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

newResource

public static Resource newResource(java.net.URL url)
                            throws java.io.IOException
Parameters:
url -  
Returns:
 

newResource

public static Resource newResource(java.lang.String resource)
                            throws java.net.MalformedURLException,
                                   java.io.IOException
Construct a resource from a string. If the string is not a URL, it is treated as an absolute or relative file path.
Parameters:
resource. -  
Returns:
 

newSystemResource

public static Resource newSystemResource(java.lang.String resource)
                                  throws java.io.IOException
Construct a system resource from a string. The resource is tried as classloader resource before being treated as a normal resource.
Parameters:
resource. -  
Returns:
 

release

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

exists

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

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.

lastModified

public long lastModified()
Returns the last modified time

length

public long length()
Return the length of the resource

getURL

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

getFile

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

getName

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

getInputStream

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

getOutputStream

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

delete

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

renameTo

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

list

public java.lang.String[] list()
Returns a list of resource names contained in the given 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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

canonicalPath

public static java.lang.String canonicalPath(java.lang.String path)
Convert a path to a cananonical form. All instances of "//", "." and ".." are factored out. Null is returned if the path tries to .. above it's root.
Parameters:
path -  
Returns:
path or null.


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.