org.yajul.util
Class ResourceUtil

java.lang.Object
  extended by org.yajul.util.ResourceUtil

public class ResourceUtil
extends java.lang.Object

Provides utility methods for finding and loading resources. User: josh Date: Sep 20, 2003 Time: 7:06:23 PM


Constructor Summary
ResourceUtil()
           
 
Method Summary
static boolean exists(java.lang.String name)
          Returns true if the specified resource exists.
static java.io.InputStream getResourceAsStream(java.lang.String resourceName)
          Returns an input stream for the named resource, or null if it was not found.
static java.util.Properties loadProperties(java.lang.String resourceName)
          Loads a properties resource.
static java.util.Properties loadProperties(java.lang.String resourceName, java.util.Properties defaults, java.lang.Class aClass)
          Loads a properties resource.
static byte[] resourceAsBytes(java.lang.String name)
          Returns the resource as a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceUtil

public ResourceUtil()
Method Detail

loadProperties

public static java.util.Properties loadProperties(java.lang.String resourceName)
                                           throws java.io.IOException
Loads a properties resource. Returns null if the resource was not found.

Parameters:
resourceName - The name of the resource.
Returns:
Properties - The loaded properties, or null if the resource was not found.
Throws:
java.io.IOException - if the resource could not be parsed

loadProperties

public static java.util.Properties loadProperties(java.lang.String resourceName,
                                                  java.util.Properties defaults,
                                                  java.lang.Class aClass)
                                           throws java.io.IOException
Loads a properties resource. Returns null if the resource was not found.

Parameters:
resourceName - The name of the resource.
defaults - A set of default properties, for 'layering' of properties files. See http://www.javaworld.com/javaworld/javatips/jw-javatip135.html?page=1
aClass - optional class for loading properties inside a package. If this is specified (not null) the resource name will be loaded from the same class loader and package as this class. The package path will automatically be added to the resource name in this case.
Returns:
Properties - The loaded properties, or null if the resource was not found.
Throws:
java.io.IOException - if the resource could not be parsed

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resourceName)
Returns an input stream for the named resource, or null if it was not found. Uses the current class loader.

Parameters:
resourceName - The name of the resource
Returns:
InputStream - The input stream, or null if the resource was not found.

resourceAsBytes

public static byte[] resourceAsBytes(java.lang.String name)
                              throws java.io.IOException
Returns the resource as a byte array.

Parameters:
name - The resource name.
Returns:
byte[] The contents of the resource.
Throws:
java.io.IOException - if anything goes wrong.

exists

public static boolean exists(java.lang.String name)
Returns true if the specified resource exists.

Parameters:
name - The resource name
Returns:
true if the specified resource exists.


Copyright © 2008. All Rights Reserved.