com.uwyn.rife.resources
Class ResourceFinderClasspath

java.lang.Object
  extended by com.uwyn.rife.resources.AbstractResourceFinder
      extended by com.uwyn.rife.resources.ResourceFinderClasspath
All Implemented Interfaces:
ResourceFinder

public class ResourceFinderClasspath
extends AbstractResourceFinder

This class offers ResourceFinder capabilities for resources that are available through the classloader. This is done for directories as well as for jar files. Basically, this corresponds to the resources that are available through the classpath.

Since the application's classloader isn't supposed to change in a global way, the ResourceFinderClasspath class can only be instantiated through the static getInstance() method that always returns the same instance as a singleton.

Since:
1.0
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)
See Also:
ResourceFinder

Constructor Summary
protected ResourceFinderClasspath()
           
 
Method Summary
 String getContent(URL resource, String encoding)
          Retrieves the complete content of the provided resource.
static ResourceFinderClasspath getInstance()
          Returns the shared singleton instance of the ResourceFinderClasspath class.
 long getModificationTime(URL resource)
          Retrieves the modification time of the provided resource.
 URL getResource(String name)
          Retrieves the resource that corresponds to the provided name.
<ResultType>
ResultType
useStream(URL resource, InputStreamUser user)
          Returns a stream that can be used to read the contents of the provided resource.
 
Methods inherited from class com.uwyn.rife.resources.AbstractResourceFinder
getContent, getContent, getContent, getModificationTime, useStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceFinderClasspath

protected ResourceFinderClasspath()
Method Detail

getInstance

public static ResourceFinderClasspath getInstance()
Returns the shared singleton instance of the ResourceFinderClasspath class.

Returns:
the singleton ResourceFinderClasspath instance
Since:
1.0

getResource

public URL getResource(String name)
Description copied from interface: ResourceFinder
Retrieves the resource that corresponds to the provided name.

This method never throws an exception, but returns null in case of an exception.

Parameters:
name - the name of the resource to retrieve
Returns:
the URL object that corresponds to the provided name; or

null if the resource couldn't be found or if an error occurred.


useStream

public <ResultType> ResultType useStream(URL resource,
                                         InputStreamUser user)
                     throws ResourceFinderErrorException,
                            InnerClassException
Description copied from interface: ResourceFinder
Returns a stream that can be used to read the contents of the provided resource.

Parameters:
resource - the resource to retrieve
user - an instance of InputStreamUser that contains the logic that will be executed with this stream
Returns:
the return value from the useInputStream method of the provided InputStreamUser instance
Throws:
ResourceFinderErrorException - when an error occurred during the creation or opening of the stream.
InnerClassException - when errors occurs inside the InputStreamUser
See Also:
InputStreamUser, ResourceFinder.useStream(String, InputStreamUser)

getContent

public String getContent(URL resource,
                         String encoding)
                  throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the complete content of the provided resource.

Parameters:
resource - the resource to retrieve the content from
encoding - the encoding that should be used to read the content
Returns:
a String object that contains the complete content of the resource with the provided name; or

null if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
See Also:
ResourceFinder.getContent(String), ResourceFinder.getContent(String, String), ResourceFinder.getContent(URL)

getModificationTime

public long getModificationTime(URL resource)
                         throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the modification time of the provided resource.

Parameters:
resource - the resource to retrieve the modification time from
Returns:
a positive long with the modification time in milliseconds; or

-1 if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the modification time.
See Also:
ResourceFinder.getModificationTime(String)


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.