org.jicengine.io
Class ClasspathResource

java.lang.Object
  extended byorg.jicengine.io.AbstractResource
      extended byorg.jicengine.io.ClasspathResource
All Implemented Interfaces:
Resource, UrlReadable

public class ClasspathResource
extends AbstractResource
implements UrlReadable

A resource found in the classpath. The classloader of this ClassPathResource is used for reading the resource.

Version:
1.0
Author:
.timo
See Also:
Class, ClassLoader, Class.getResourceAsStream(java.lang.String), Class.getResource(java.lang.String)

Constructor Summary
ClasspathResource(java.lang.String resourceName)
          The name of the resource, for method ClassLoader.getResourceAsStream().
 
Method Summary
 java.lang.ClassLoader getClassLoader()
           
 java.io.InputStream getInputStream()
          A primary way reading the resource.
 Resource getResource(java.lang.String relativePath)
           Locates another Resource whose path is defined relative to this Resource.
 java.lang.String getResourceName()
           
 java.net.URL getUrl()
           
 boolean isAvailable()
           Determines the availability of the Resource by calling getInputStream(): resource is available if the method doesn't throw an exception.
 
Methods inherited from class org.jicengine.io.AbstractResource
getIdentifier, getMimeType, getReader, setMimeType, toString, writeTo, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClasspathResource

public ClasspathResource(java.lang.String resourceName)
The name of the resource, for method ClassLoader.getResourceAsStream().

See Also:
Class.getResourceAsStream(java.lang.String), Class.getResource(java.lang.String)
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()

getResourceName

public java.lang.String getResourceName()

getUrl

public java.net.URL getUrl()
                    throws java.io.IOException
Specified by:
getUrl in interface UrlReadable
Throws:
java.io.IOException

isAvailable

public boolean isAvailable()
Description copied from class: AbstractResource

Determines the availability of the Resource by calling getInputStream(): resource is available if the method doesn't throw an exception.

Override this if a more efficient way for determining the availability is possible.

Specified by:
isAvailable in interface Resource
Overrides:
isAvailable in class AbstractResource

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: Resource
A primary way reading the resource.

Specified by:
getInputStream in interface Resource
Specified by:
getInputStream in class AbstractResource
Throws:
java.io.IOException

getResource

public Resource getResource(java.lang.String relativePath)
                     throws java.io.IOException
Description copied from interface: Resource

Locates another Resource whose path is defined relative to this Resource.

the path scheme used with files and urls is used for specifying relative paths.

the method generally returns instances of the same Resource-subclass than the current instance, but this is not obligatory.

NOTE:

NOTE: there is no support for absolute paths. yet.

Specified by:
getResource in interface Resource
Specified by:
getResource in class AbstractResource
Throws:
java.io.IOException