org.mortbay.util

Class Resource

public abstract class Resource extends Object implements Serializable

Abstract resource class.

Version: $Id: Resource.java,v 1.31 2005/10/21 11:36:56 gregwilkins Exp $

Author: Nuno Preguiga Greg Wilkins (gregw)

Method Summary
abstract ResourceaddPath(String path)
Returns the resource contained inside the current resource with the given name.
CachedResourcecache()
abstract booleandelete()
Deletes the given resource
Stringencode(String uri)
Encode according to this resource type.
abstract booleanexists()
Returns true if the respresened resource exists.
protected voidfinalize()
URLgetAlias()
ObjectgetAssociate()
abstract FilegetFile()
Returns an File representing the given resource or NULL if this is not possible.
abstract InputStreamgetInputStream()
Returns an input stream to the resource
StringgetListHTML(String base, boolean parent)
Get the resource list as a HTML directory listing.
abstract StringgetName()
Returns the name of the resource
abstract OutputStreamgetOutputStream()
Returns an output stream to the resource
abstract URLgetURL()
Returns an URL representing the given resource
abstract booleanisDirectory()
Returns true if the respresenetd resource is a container/directory.
abstract longlastModified()
Returns the last modified time
abstract longlength()
Return the length of the resource
abstract String[]list()
Returns a list of resource names contained in the given resource The resource names are not URL encoded.
static ResourcenewResource(URL url)
Construct a resource from a url.
static ResourcenewResource(String resource)
Construct a resource from a string.
static ResourcenewSystemResource(String resource)
Construct a system resource from a string.
abstract voidrelease()
Release any resources held by the resource.
abstract booleanrenameTo(Resource dest)
Rename the given resource
voidsetAssociate(Object o)
voidwriteTo(OutputStream out, long start, long count)

Method Detail

addPath

public abstract Resource addPath(String path)
Returns the resource contained inside the current resource with the given name.

Parameters: path The path segment to add, which should be encoded by the encode method.

cache

public CachedResource cache()

delete

public abstract boolean delete()
Deletes the given resource

encode

public String encode(String uri)
Encode according to this resource type. The default implementation calls URI.encodePath(uri)

Parameters: uri

Returns: String encoded for this resource type.

exists

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

finalize

protected void finalize()

getAlias

public URL getAlias()

Returns: The canonical Alias of this resource or null if none.

getAssociate

public Object getAssociate()

getFile

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

getInputStream

public abstract InputStream getInputStream()
Returns an input stream to the resource

getListHTML

public String getListHTML(String base, boolean parent)
Get the resource list as a HTML directory listing.

Parameters: base The base URL parent True if the parent directory should be included

Returns: String of HTML

getName

public abstract String getName()
Returns the name of the resource

getOutputStream

public abstract OutputStream getOutputStream()
Returns an output stream to the resource

getURL

public abstract URL getURL()
Returns an URL representing the given resource

isDirectory

public abstract 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 abstract long lastModified()
Returns the last modified time

length

public abstract long length()
Return the length of the resource

list

public abstract String[] list()
Returns a list of resource names contained in the given resource The resource names are not URL encoded.

newResource

public static Resource newResource(URL url)
Construct a resource from a url.

Parameters: url A URL.

Returns: A Resource object.

newResource

public static Resource newResource(String resource)
Construct a resource from a string.

Parameters: resource A URL or filename.

Returns: A Resource object.

newSystemResource

public static Resource newSystemResource(String resource)
Construct a system resource from a string. The resource is tried as classloader resource before being treated as a normal resource.

release

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

renameTo

public abstract boolean renameTo(Resource dest)
Rename the given resource

setAssociate

public void setAssociate(Object o)

writeTo

public void writeTo(OutputStream out, long start, long count)

Parameters: out start First byte to write count Bytes to write or -1 for all of them.

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