Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mortbay.resource
Class Resource

    java.lang.Object
      org.mortbay.resource.Resource

All Implemented Interfaces:
  java.io.Serializable

Direct Known Subclasses:
  ResourceCollection, URLResource

    public abstract class Resource

extends java.lang.Object
implements java.io.Serializable

Abstract resource class.

Author:
  Nuno Pregui�a, Greg Wilkins (gregw)
See Also:
  Serialized Form

Field Summary
`static boolean` | `__defaultUseCaches`

Constructor Summary
`Resource()`

Method Summary
`abstract Resource` | `addPath(java.lang.String path)` Returns the resource contained inside the current resource with the given name.
`abstract boolean` | `delete()` Deletes the given resource
`java.lang.String` | `encode(java.lang.String uri)` Encode according to this resource type.
`abstract boolean` | `exists()` Returns true if the respresened resource exists.
`protected void` | `finalize()`
`java.net.URL` | `getAlias()`
`java.lang.Object` | `getAssociate()`
`static boolean` | `getDefaultUseCaches()`
`abstract java.io.File` | `getFile()` Returns an File representing the given resource or NULL if this is not possible.
`abstract java.io.InputStream` | `getInputStream()` Returns an input stream to the resource
`java.lang.String` | `getListHTML(java.lang.String base, boolean parent)` Get the resource list as a HTML directory listing.
`abstract java.lang.String` | `getName()` Returns the name of the resource
`abstract java.io.OutputStream` | `getOutputStream()` Returns an output stream to the resource
`abstract java.net.URL` | `getURL()` Returns an URL representing the given resource
`abstract boolean` | `isDirectory()` Returns true if the respresenetd resource is a container/directory.
`abstract long` | `lastModified()` Returns the last modified time
`abstract long` | `length()` Return the length of the resource
`abstract java.lang.String[]` | `list()` Returns a list of resource names contained in the given resource The resource names are not URL encoded.
`static Resource` | `newClassPathResource(java.lang.String resource)` Find a classpath resource.
`static Resource` | `newClassPathResource(java.lang.String name, boolean useCaches, boolean checkParents)` Find a classpath resource.
`static Resource` | `newResource(java.lang.String resource)` Construct a resource from a string.
`static Resource` | `newResource(java.lang.String resource, boolean useCaches)` Construct a resource from a string.
`static Resource` | `newResource(java.net.URL url)` Construct a resource from a url.
`static Resource` | `newResource(java.net.URL url, boolean useCaches)` Construct a resource from a url.
`static Resource` | `newSystemResource(java.lang.String resource)` Construct a system resource from a string.
`abstract void` | `release()` Release any resources held by the resource.
`abstract boolean` | `renameTo(Resource dest)` Rename the given resource
`void` | `setAssociate(java.lang.Object o)`
`static void` | `setDefaultUseCaches(boolean useCaches)` Change the default setting for url connection caches.
`void` | `writeTo(java.io.OutputStream out, long start, long count)`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### __defaultUseCaches

    public static boolean __defaultUseCaches

Constructor Detail

### Resource

    public Resource()

Method Detail

### setDefaultUseCaches

    public static void setDefaultUseCaches(boolean useCaches)

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

  Parameters:
    `useCaches` -

### getDefaultUseCaches

    public static boolean getDefaultUseCaches()

### newResource

    public static Resource newResource(java.net.URL url)
                                throws java.io.IOException

  Construct a resource from a url.

  Parameters:
    `url` - A URL.
  Returns:
    A Resource object.
  Throws:
    `java.io.IOException`

### newResource

    public static Resource newResource(java.net.URL url,
                                       boolean useCaches)

  Construct a resource from a url.

  Parameters:
    `url` - the url for which to make the resource
    `useCaches` - true enables URLConnection caching if applicable to the type of resource
  Returns:

### newResource

    public static Resource newResource(java.lang.String resource)
                                throws java.net.MalformedURLException,
                                       java.io.IOException

  Construct a resource from a string.

  Parameters:
    `resource` - A URL or filename.
  Returns:
    A Resource object.
  Throws:
    `java.net.MalformedURLException`
    `java.io.IOException`

### newResource

    public static Resource newResource(java.lang.String resource,
                                       boolean useCaches)
                                throws java.net.MalformedURLException,
                                       java.io.IOException

  Construct a resource from a string.

  Parameters:
    `resource` - A URL or filename.
    `useCaches` - controls URLConnection caching
  Returns:
    A Resource object.
  Throws:
    `java.net.MalformedURLException`
    `java.io.IOException`

### 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.

  Throws:
    `java.io.IOException`

### newClassPathResource

    public static Resource newClassPathResource(java.lang.String resource)

  Find a classpath resource.

### newClassPathResource

    public static Resource newClassPathResource(java.lang.String name,
                                                boolean useCaches,
                                                boolean checkParents)

  Find a classpath resource. The 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` - The relative name of the resouce
    `useCaches` - True if URL caches are to be used.
    `checkParents` - True if forced searching of parent classloaders is performed to work around loaders with inverted priorities
  Returns:
    Resource or null

### finalize

    protected void finalize()

  Overrides:
    `finalize` in class `java.lang.Object`

### release

    public abstract void release()

  Release any resources held by the resource.

### exists

    public abstract boolean exists()

  Returns true if the respresened resource exists.

### 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

### getURL

    public abstract java.net.URL getURL()

  Returns an URL representing the given resource

### getFile

    public abstract java.io.File getFile()
                                  throws java.io.IOException

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

  Throws:
    `java.io.IOException`

### getName

    public abstract java.lang.String getName()

  Returns the name of the resource

### getInputStream

    public abstract java.io.InputStream getInputStream()
                                                throws java.io.IOException

  Returns an input stream to the resource

  Throws:
    `java.io.IOException`

### getOutputStream

    public abstract java.io.OutputStream getOutputStream()
                                                  throws java.io.IOException,
                                                         java.lang.SecurityException

  Returns an output stream to the resource

  Throws:
    `java.io.IOException`
    `java.lang.SecurityException`

### delete

    public abstract boolean delete()
                            throws java.lang.SecurityException

  Deletes the given resource

  Throws:
    `java.lang.SecurityException`

### renameTo

    public abstract boolean renameTo(Resource dest)
                              throws java.lang.SecurityException

  Rename the given resource

  Throws:
    `java.lang.SecurityException`

### list

    public abstract java.lang.String[] list()

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

### addPath

    public abstract 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.

  Parameters:
    `path` - The path segment to add, which should be encoded by the encode method.
  Throws:
    `java.io.IOException`
    `java.net.MalformedURLException`

### encode

    public java.lang.String encode(java.lang.String uri)

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

  Parameters:
    `uri` -
  Returns:
    String encoded for this resource type.

### getAssociate

    public java.lang.Object getAssociate()

### setAssociate

    public void setAssociate(java.lang.Object o)

### getAlias

    public java.net.URL getAlias()

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

### getListHTML

    public java.lang.String getListHTML(java.lang.String base,
                                        boolean parent)
                                 throws java.io.IOException

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

### writeTo

    public void writeTo(java.io.OutputStream out,
                        long start,
                        long count)
                 throws java.io.IOException

  Parameters:
    `out` -
    `start` - First byte to write
    `count` - Bytes to write or -1 for all of them.
  Throws:
    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.