kiwi.util
Class ResourceLoader

java.lang.Object
  extended bykiwi.util.ResourceLoader

public class ResourceLoader
extends java.lang.Object

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.

Author:
Mark Lindner, PING Software Group
See Also:
ResourceManager

Field Summary
protected  java.lang.Class clazz
          The class object associated with this resource loader.
private  ResourceDecoder decoder
           
 
Constructor Summary
ResourceLoader(java.lang.Class clazz)
          Construct a new ResourceLoader.
 
Method Summary
 AudioClip getResourceAsAudioClip(java.lang.String path)
          Retrieve a resource as an AudioClip.
 java.awt.Image getResourceAsImage(java.lang.String path)
          Retrieve a resource as an Image.
 java.util.Properties getResourceAsProperties(java.lang.String path)
          Retrieve a resource as a Properties object.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Retrieve a resource as a stream.
 java.lang.String getResourceAsString(java.lang.String path)
          Retrieve a resource as a String.
 java.net.URL getResourceAsURL(java.lang.String path)
          Retrieve a resource as a URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decoder

private ResourceDecoder decoder

clazz

protected java.lang.Class clazz
The class object associated with this resource loader.

Constructor Detail

ResourceLoader

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

Method Detail

getResourceAsURL

public java.net.URL getResourceAsURL(java.lang.String path)
Retrieve a resource as a URL.

Parameters:
path - The location of the resource.
Returns:
A URL reference to the resource.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
                                        throws java.io.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:
java.io.IOException - If the resource was not found.

getResourceAsString

public final java.lang.String getResourceAsString(java.lang.String path)
                                           throws java.io.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:
java.io.IOException - If an error occurred while reading the resource's data.

getResourceAsAudioClip

public final AudioClip getResourceAsAudioClip(java.lang.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 java.awt.Image getResourceAsImage(java.lang.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 java.util.Properties getResourceAsProperties(java.lang.String path)
                                                   throws java.io.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:
java.io.IOException - If an error occurred while reading the resource's data.