ahc.io
Class ResourceLoader

java.lang.Object
  |
  +--ahc.io.ResourceLoader

public class ResourceLoader
extends java.lang.Object

This class serves to retrieve resources from the class path, i.e. it allows clients to access the contents of files (e.g. images) that are in the classpath. This is often better than reading from the file system because it reduces installation hassle, works in application servers etc.

Author:
Arno Haase

Constructor Summary
ResourceLoader()
           
 
Method Summary
static byte[] getAsBytes(java.lang.String name)
          This is a convenience method that reads an entire resource and returns it as a byte array.
static javax.swing.ImageIcon getAsImageIcon(java.lang.String name)
          This is a convenience method that reads an entire resource and returns it as an ImageIcon.
static java.io.InputStream getAsStream(java.lang.String name)
          This is the underlying method of this class; it provides access to a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLoader

public ResourceLoader()
Method Detail

getAsStream

public static java.io.InputStream getAsStream(java.lang.String name)
This is the underlying method of this class; it provides access to a resource. The resource name must be provided relative to the class path root and with '/' as separators, e.g. "images/MyImage.jpg" for an image in the subdirectory "images", or "ahc/util/ResourceLoader.class for the class file of this class.

If the resource is not found null is returned.


getAsBytes

public static byte[] getAsBytes(java.lang.String name)
This is a convenience method that reads an entire resource and returns it as a byte array.

If the resource is not found, an IllegalArgumentException is thrown.


getAsImageIcon

public static javax.swing.ImageIcon getAsImageIcon(java.lang.String name)
This is a convenience method that reads an entire resource and returns it as an ImageIcon.

If the resource is not found, an IllegalArgumentException is thrown.