kiwi.util
Class ResourceLoader

java.lang.Object
  |
  +--kiwi.util.ResourceLoader
Direct Known Subclasses:
CompressedResourceLoader

public class ResourceLoader
extends Object
implements ImageObserver

A utility class containing methods for retrieving application resources; these resources typically reside within a JAR file among the classes that make up an application. The location of a resource is specified as a path relative to the location of a class within the application's class hierarchy. This "anchor class" is specified in the constructor.

Resources may be retrieved as byte arrays, as Strings, as InputStreams, as AudioClips, as Images,, or as Properties objects.

See ResourceManager for a higher-level interface.

Version:
1.1 (09/98)
Author:
Mark Lindner, PING Software Group
See Also:
CompressedResourceLoader, ResourceManager

Field Summary
protected  Class clazz
          The class object associated with this resource loader.
 
Constructor Summary
ResourceLoader(Class clazz)
          Construct a new ResourceLoader.
 
Method Summary
 AudioClip getResourceAsAudioClip(String path)
          Retrieve a resource as an AudioClip.
 Image getResourceAsImage(String path)
          Retrieve a resource as an Image.
 Properties getResourceAsProperties(String path)
          Retrieve a resource as a Properties object.
 InputStream getResourceAsStream(String path)
          Retrieve a resource as a stream.
 String getResourceAsString(String path)
          Retrieve a resource as a String.
 URL getResourceAsURL(String path)
          Retrieve a resource as a URL.
 boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
          Image tracker method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clazz

protected Class clazz
The class object associated with this resource loader.
Constructor Detail

ResourceLoader

public ResourceLoader(Class clazz)
Construct a new ResourceLoader. A new resource loader is created with a default input buffer size.
Method Detail

getResourceAsURL

public URL getResourceAsURL(String path)
Retrieve a resource as a URL.
Parameters:
path - The location of the resource.
Returns:
A URL reference to the resource.

getResourceAsStream

public InputStream getResourceAsStream(String path)
                                throws IOException
Retrieve a resource as a stream.
Parameters:
path - The location of the resource.
Returns:
An InputStream from which the resource data may be read.
Throws:
IOException - If the resource was not found.

getResourceAsString

public final String getResourceAsString(String path)
                                 throws IOException
Retrieve a resource as a String. Retrieves the specified resource, returning its data as a String. It is assumed that the resource contains printable text.
Parameters:
path - The location of the resource.
Throws:
IOException - If an error occurred while reading the resource's data.

getResourceAsAudioClip

public final AudioClip getResourceAsAudioClip(String path)
Retrieve a resource as an AudioClip. Retrieves the specified resource, returning its data as an AudioClip. It is assumed that the resource contains valid audio data.
Parameters:
path - The location of the resource.

getResourceAsImage

public final Image getResourceAsImage(String path)
Retrieve a resource as an Image. Retrieves the specified resource, returning its data as an Image. It is assumed that the resource contains valid image data.
Parameters:
path - The location of the resource.

getResourceAsProperties

public final Properties getResourceAsProperties(String path)
                                         throws IOException
Retrieve a resource as a Properties object. Retrieves the specified resource, returning its data as a Properties object. It is assumed that the resource is a properly-formatted property list.
Parameters:
path - The location of the resource.
Throws:
IOException - If an error occurred while reading the resource's data.

imageUpdate

public boolean imageUpdate(Image img,
                           int infoflags,
                           int x,
                           int y,
                           int w,
                           int h)
Image tracker method. This is an internal method and should not be called directly.
Specified by:
imageUpdate in interface ImageObserver