org.mortbay.util
Class URLResource

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

public class URLResource
extends Resource

Abstract resource class.

Version:
$Id: URLResource.java,v 1.10 2009/05/16 01:53:36 gregwilkins Exp $
Author:
Nuno Preguica, Greg Wilkins (gregw)
See Also:
Serialized Form

Field Summary
protected  java.net.URLConnection _connection
           
protected  java.io.InputStream _in
           
protected  java.net.URL _url
           
protected  java.lang.String _urlString
           
 
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)
           
 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
 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 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

_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
Throws:
java.io.IOException

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
Throws:
java.io.IOException

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
Throws:
java.io.IOException
java.lang.SecurityException

delete

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

Specified by:
delete in class Resource
Throws:
java.lang.SecurityException

renameTo

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

Specified by:
renameTo in class Resource
Throws:
java.lang.SecurityException

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
Parameters:
path - The path segment to add, which should be encoded by the encode method.
Throws:
java.io.IOException
java.net.MalformedURLException

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


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