kiwi.util
Class CompressedResourceLoader

java.lang.Object
  |
  +--kiwi.util.ResourceLoader
        |
        +--kiwi.util.CompressedResourceLoader
All Implemented Interfaces:
java.awt.image.ImageObserver

public class CompressedResourceLoader
extends ResourceLoader

A utility class containing methods for retrieving compressed 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 its associated object's class within the application's class hierarchy.

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

Both the GZIP and ZIP compression formats are supported.

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

Field Summary
static int DEFAULT_INFLATER
          The default inflater type.
static int GZIP
          The GZIP inflater type.
protected static int inflater
           
static int ZIP
          The ZIP inflater type.
 
Fields inherited from class kiwi.util.ResourceLoader
clazz, imageLoaded
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CompressedResourceLoader(java.lang.Class clazz)
          Construct a new CompressedResourceLoader with a default input buffer size and inflater type.
CompressedResourceLoader(java.lang.Class clazz, int type)
          Create a new compressed resource loader with the default input buffer size.
CompressedResourceLoader(java.lang.Class clazz, int type, int size)
          Create a new compressed resource loader.
 
Method Summary
private  void _init(int type)
           
 int getInflaterType()
          Get the inflater type.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Retrieve a compressed resource as a stream.
 
Methods inherited from class kiwi.util.ResourceLoader
getResourceAsAudioClip, getResourceAsImage, getResourceAsProperties, getResourceAsString, getResourceAsURL, imageUpdate
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

GZIP

public static final int GZIP
The GZIP inflater type.

ZIP

public static final int ZIP
The ZIP inflater type.

DEFAULT_INFLATER

public static final int DEFAULT_INFLATER
The default inflater type.

inflater

protected static int inflater
Constructor Detail

CompressedResourceLoader

public CompressedResourceLoader(java.lang.Class clazz)
Construct a new CompressedResourceLoader with a default input buffer size and inflater type.
Parameters:
clazz - The class object that serves as the resource anchor for this CompressedResourceLoader.

CompressedResourceLoader

public CompressedResourceLoader(java.lang.Class clazz,
                                int type)
                         throws java.lang.IllegalArgumentException
Create a new compressed resource loader with the default input buffer size.
Parameters:
clazz - The class object that serves as the resource anchor for this CompressedResourceLoader.
type - The inflater type; one of the static constants declared above.
Throws:
java.lang.IllegalArgumentException - If the value of type is invalid.

CompressedResourceLoader

public CompressedResourceLoader(java.lang.Class clazz,
                                int type,
                                int size)
                         throws java.lang.IllegalArgumentException
Create a new compressed resource loader. A new resource loader is created with the specified input buffer size and inflater type.
Parameters:
clazz - The class object that serves as the resource anchor for this CompressedResourceLoader.
type - The inflater type; one of the static constants declared above.
size - The input buffer size.
Throws:
java.lang.IllegalArgumentException - If the value of type or size is invalid.
Method Detail

_init

private void _init(int type)
            throws java.lang.IllegalArgumentException

getInflaterType

public int getInflaterType()
Get the inflater type.
Returns:
The inflater type used by this loader.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
                                        throws java.io.IOException
Retrieve a compressed resource as a stream. Resources are located at a path that is relative to a given class. The data read will be automatically decompressed using the specified appropriate inflater type, or the default inflater type if none was specified.
Overrides:
getResourceAsStream in class ResourceLoader
Parameters:
clazz - The class object associated with this resource.
path - A file path specifying the location of the resource; the path is relative to the location of the class file.
Returns:
An InputStream from which the (decompressed) resource data may be read.
Throws:
java.io.IOException - If the resource was not found.