Top Description Fields Constructors Methods
org.mortbay.resource

public abstract Class Resource

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.mortbay.resource.ResourceCollection, org.mortbay.resource.URLResource
Imports
java.io.File, .IOException, .InputStream, .OutputStream, .Serializable, java.net.MalformedURLException, .URL, .URLConnection, java.text.DateFormat, java.util.Arrays, .Date, org.mortbay.log.Log, org.mortbay.util.IO, .Loader, .StringUtil, .URIUtil

Abstract resource class.
Authors
Nuno Pregui�a, Greg Wilkins (gregw)

Field Summary

Modifier and TypeField and Description
public static boolean
pack-priv Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract Resource
addPath(String
The path segment to add, which should be encoded by the encode method.
path
)

Returns the resource contained inside the current resource with the given name.

public abstract boolean
delete()

Deletes the given resource

public String

Returns:

String encoded for this resource type.
encode
(String uri)

Encode according to this resource type.

public abstract boolean
exists()

Returns true if the respresened resource exists.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
public URL

Returns:

The canonical Alias of this resource or null if none.
getAlias
()

public Object
public static boolean
public abstract File
getFile()

Returns an File representing the given resource or NULL if this is not possible.

public abstract InputStream
getInputStream()

Returns an input stream to the resource

public String

Returns:

String of HTML
getListHTML
(String
The base URL
base
,
boolean
True if the parent directory should be included
parent
)

Get the resource list as a HTML directory listing.

public abstract String
getName()

Returns the name of the resource

public abstract OutputStream
getOutputStream()

Returns an output stream to the resource

public abstract URL
getURL()

Returns an URL representing the given resource

public abstract boolean
isDirectory()

Returns true if the respresenetd resource is a container/directory.

public abstract long
lastModified()

Returns the last modified time

public abstract long
length()

Return the length of the resource

public abstract String[]
list()

Returns a list of resource names contained in the given resource The resource names are not URL encoded.

public static Resource
newClassPathResource(String resource)

Find a classpath resource.

public static Resource

Returns:

Resource or null
newClassPathResource
(String
The relative name of the resouce
name
,
boolean
True if URL caches are to be used.
useCaches
,
boolean
True if forced searching of parent classloaders is performed to work around loaders with inverted priorities
checkParents
)

Find a classpath resource.

public static Resource

Returns:

A Resource object.
newResource
(URL
A URL.
url
)

Construct a resource from a url.

pack-priv static Resource
newResource(URL
the url for which to make the resource
url
,
boolean
true enables URLConnection caching if applicable to the type of resource
useCaches
)

Construct a resource from a url.

public static Resource

Returns:

A Resource object.
newResource
(String
A URL or filename.
resource
)

Construct a resource from a string.

public static Resource

Returns:

A Resource object.
newResource
(String
A URL or filename.
resource
,
boolean
controls URLConnection caching
useCaches
)

Construct a resource from a string.

public static Resource
newSystemResource(String resource)

Construct a system resource from a string.

public abstract void
release()

Release any resources held by the resource.

public abstract boolean
renameTo(Resource dest)

Rename the given resource

public void
public static void
setDefaultUseCaches(boolean useCaches)

Change the default setting for url connection caches.

public void
writeTo(OutputStream out, long
First byte to write
start
,
long
Bytes to write or -1 for all of them.
count
)

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__defaultUseCachesback to summary
public static boolean __defaultUseCaches
_associateback to summary
pack-priv Object _associate

Constructor Detail

Resourceback to summary
public Resource()

Method Detail

addPathback to summary
public abstract Resource addPath(String path) throws IOException, MalformedURLException

Returns the resource contained inside the current resource with the given name.

Parameters
path:String

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

deleteback to summary
public abstract boolean delete() throws SecurityException

Deletes the given resource

encodeback to summary
public String encode(String uri)

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

Returns:String

String encoded for this resource type.

existsback to summary
public abstract boolean exists()

Returns true if the respresened resource exists.

finalizeback to summary
protected void finalize()

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

getAliasback to summary
public URL getAlias()
Returns:URL

The canonical Alias of this resource or null if none.

getAssociateback to summary
public Object getAssociate()
getDefaultUseCachesback to summary
public static boolean getDefaultUseCaches()
getFileback to summary
public abstract File getFile() throws IOException

Returns an File representing the given resource or NULL if this is not possible.

getInputStreamback to summary
public abstract InputStream getInputStream() throws IOException

Returns an input stream to the resource

getListHTMLback to summary
public String getListHTML(String base, boolean parent) throws IOException

Get the resource list as a HTML directory listing.

Parameters
base:String

The base URL

parent:boolean

True if the parent directory should be included

Returns:String

String of HTML

getNameback to summary
public abstract String getName()

Returns the name of the resource

getOutputStreamback to summary
public abstract OutputStream getOutputStream() throws IOException, SecurityException

Returns an output stream to the resource

getURLback to summary
public abstract URL getURL()

Returns an URL representing the given resource

isDirectoryback to summary
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.

lastModifiedback to summary
public abstract long lastModified()

Returns the last modified time

lengthback to summary
public abstract long length()

Return the length of the resource

listback to summary
public abstract String[] list()

Returns a list of resource names contained in the given resource The resource names are not URL encoded.

newClassPathResourceback to summary
public static Resource newClassPathResource(String resource)

Find a classpath resource.

newClassPathResourceback to summary
public static Resource newClassPathResource(String name, boolean useCaches, boolean checkParents)

Find a classpath resource. The {@java .lang.Class#getResource} method is used to lookup the resource. If it is not found, then the Loader#getResource(Class, String, boolean) method is used. If it is still not found, then ClassLoader#getSystemResource(String) is used. Unlike getSystemResource this method does not check for normal resources.

Parameters
name:String

The relative name of the resouce

useCaches:boolean

True if URL caches are to be used.

checkParents:boolean

True if forced searching of parent classloaders is performed to work around loaders with inverted priorities

Returns:Resource

Resource or null

newResourceback to summary
public static Resource newResource(URL url) throws IOException

Construct a resource from a url.

Parameters
url:URL

A URL.

Returns:Resource

A Resource object.

newResourceback to summary
pack-priv static Resource newResource(URL url, boolean useCaches)

Construct a resource from a url.

Parameters
url:URL

the url for which to make the resource

useCaches:boolean

true enables URLConnection caching if applicable to the type of resource

newResourceback to summary
public static Resource newResource(String resource) throws MalformedURLException, IOException

Construct a resource from a string.

Parameters
resource:String

A URL or filename.

Returns:Resource

A Resource object.

newResourceback to summary
public static Resource newResource(String resource, boolean useCaches) throws MalformedURLException, IOException

Construct a resource from a string.

Parameters
resource:String

A URL or filename.

useCaches:boolean

controls URLConnection caching

Returns:Resource

A Resource object.

newSystemResourceback to summary
public static Resource newSystemResource(String resource) throws IOException

Construct a system resource from a string. The resource is tried as classloader resource before being treated as a normal resource.

releaseback to summary
public abstract void release()

Release any resources held by the resource.

renameToback to summary
public abstract boolean renameTo(Resource dest) throws SecurityException

Rename the given resource

setAssociateback to summary
public void setAssociate(Object o)
setDefaultUseCachesback to summary
public static void setDefaultUseCaches(boolean useCaches)

Change the default setting for url connection caches. Subsequent URLConnections will use this default.

writeToback to summary
public void writeTo(OutputStream out, long start, long count) throws IOException
Parameters
start:long

First byte to write

count:long

Bytes to write or -1 for all of them.