org.jicengine.io
Class StringResource

java.lang.Object
  extended byorg.jicengine.io.AbstractResource
      extended byorg.jicengine.io.StringResource
All Implemented Interfaces:
Resource

public class StringResource
extends AbstractResource

A virtual resource whose content is a String, instead of a file on disc.

StringResource makes it possible to create resource-content dynamically and feed it to applications like any other resource.

Neighbouring resources of a StringResource

StringResource needs a 'locator resource' that specifies the 'location' of this virtual resource. StringResource doesn't implement the getResource() method by itself but forwards the call to its locator resource.

Version:
1.0
Author:
.timo

Constructor Summary
StringResource(java.lang.String identifier, java.lang.String text, Resource locatorResource)
           
 
Method Summary
 java.io.InputStream getInputStream()
          A primary way reading the resource.
 java.io.Reader getReader()
           Simple implementation of getReader() that wraps the InputStream obtained from getInputStream() with a InputStreamReader.
 Resource getResource(java.lang.String relativePath)
           Locates another Resource whose path is defined relative to this Resource.
 java.lang.String getText()
           
 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, setMimeType, toString, writeTo, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringResource

public StringResource(java.lang.String identifier,
                      java.lang.String text,
                      Resource locatorResource)
Parameters:
locatorResource - a resource that gives this virtual resource a location. if the StringResource is created from some source resources through some kind of a transformation, these source resources would be good candidates for a locatorResource.
Method Detail

getText

public java.lang.String getText()

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

getReader

public java.io.Reader getReader()
                         throws java.io.IOException
Description copied from class: AbstractResource

Simple implementation of getReader() that wraps the InputStream obtained from getInputStream() with a InputStreamReader.

Override this method if a better alternative for creating the Reader is available.

Specified by:
getReader in interface Resource
Overrides:
getReader 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