com.ibatis.common.resources

Class Resources

public class Resources extends Object

A class to simplify access to resources through the classloader.
Method Summary
static ClassclassForName(String className)
Loads a class
static CharsetgetCharset()
static ClassLoadergetDefaultClassLoader()
Returns the default classloader (may be null).
static FilegetResourceAsFile(String resource)
Returns a resource on the classpath as a File object
static FilegetResourceAsFile(ClassLoader loader, String resource)
Returns a resource on the classpath as a File object
static PropertiesgetResourceAsProperties(String resource)
Returns a resource on the classpath as a Properties object
static PropertiesgetResourceAsProperties(ClassLoader loader, String resource)
Returns a resource on the classpath as a Properties object
static ReadergetResourceAsReader(String resource)
Returns a resource on the classpath as a Reader object
static ReadergetResourceAsReader(ClassLoader loader, String resource)
Returns a resource on the classpath as a Reader object
static InputStreamgetResourceAsStream(String resource)
Returns a resource on the classpath as a Stream object
static InputStreamgetResourceAsStream(ClassLoader loader, String resource)
Returns a resource on the classpath as a Stream object
static URLgetResourceURL(String resource)
Returns the URL of the resource on the classpath
static URLgetResourceURL(ClassLoader loader, String resource)
Returns the URL of the resource on the classpath
static PropertiesgetUrlAsProperties(String urlString)
Gets a URL as a Properties object
static ReadergetUrlAsReader(String urlString)
Gets a URL as a Reader
static InputStreamgetUrlAsStream(String urlString)
Gets a URL as an input stream
static Objectinstantiate(String className)
Creates an instance of a class
static Objectinstantiate(Class clazz)
Creates an instance of a class
static voidsetCharset(Charset charset)
Use this method to set the Charset to be used when calling the getResourceAsReader methods.
static voidsetDefaultClassLoader(ClassLoader defaultClassLoader)
Sets the default classloader

Method Detail

classForName

public static Class classForName(String className)
Loads a class

Parameters: className - the class to load

Returns: The loaded class

Throws: ClassNotFoundException If the class cannot be found (duh!)

getCharset

public static Charset getCharset()

getDefaultClassLoader

public static ClassLoader getDefaultClassLoader()
Returns the default classloader (may be null).

Returns: The default classloader

getResourceAsFile

public static File getResourceAsFile(String resource)
Returns a resource on the classpath as a File object

Parameters: resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsFile

public static File getResourceAsFile(ClassLoader loader, String resource)
Returns a resource on the classpath as a File object

Parameters: loader - the classloader used to load the resource resource - the resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsProperties

public static Properties getResourceAsProperties(String resource)
Returns a resource on the classpath as a Properties object

Parameters: resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsProperties

public static Properties getResourceAsProperties(ClassLoader loader, String resource)
Returns a resource on the classpath as a Properties object

Parameters: loader The classloader used to load the resource resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsReader

public static Reader getResourceAsReader(String resource)
Returns a resource on the classpath as a Reader object

Parameters: resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsReader

public static Reader getResourceAsReader(ClassLoader loader, String resource)
Returns a resource on the classpath as a Reader object

Parameters: loader The classloader used to load the resource resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsStream

public static InputStream getResourceAsStream(String resource)
Returns a resource on the classpath as a Stream object

Parameters: resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceAsStream

public static InputStream getResourceAsStream(ClassLoader loader, String resource)
Returns a resource on the classpath as a Stream object

Parameters: loader The classloader used to load the resource resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceURL

public static URL getResourceURL(String resource)
Returns the URL of the resource on the classpath

Parameters: resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getResourceURL

public static URL getResourceURL(ClassLoader loader, String resource)
Returns the URL of the resource on the classpath

Parameters: loader The classloader used to load the resource resource The resource to find

Returns: The resource

Throws: IOException If the resource cannot be found or read

getUrlAsProperties

public static Properties getUrlAsProperties(String urlString)
Gets a URL as a Properties object

Parameters: urlString - the URL to get

Returns: A Properties object with the data from the URL

Throws: IOException If the resource cannot be found or read

getUrlAsReader

public static Reader getUrlAsReader(String urlString)
Gets a URL as a Reader

Parameters: urlString - the URL to get

Returns: A Reader with the data from the URL

Throws: IOException If the resource cannot be found or read

getUrlAsStream

public static InputStream getUrlAsStream(String urlString)
Gets a URL as an input stream

Parameters: urlString - the URL to get

Returns: An input stream with the data from the URL

Throws: IOException If the resource cannot be found or read

instantiate

public static Object instantiate(String className)
Creates an instance of a class

Parameters: className - the class to create

Returns: An instance of the class

Throws: ClassNotFoundException If the class cannot be found (duh!) InstantiationException If the class cannot be instantiaed IllegalAccessException If the class is not public, or other access problems arise

instantiate

public static Object instantiate(Class clazz)
Creates an instance of a class

Parameters: clazz - the class to create

Returns: An instance of the class

Throws: InstantiationException If the class cannot be instantiaed IllegalAccessException If the class is not public, or other access problems arise

setCharset

public static void setCharset(Charset charset)
Use this method to set the Charset to be used when calling the getResourceAsReader methods. This will allow iBATIS to function properly when the system default encoding doesn't deal well with unicode (IBATIS-340, IBATIS-349)

Parameters: charset

setDefaultClassLoader

public static void setDefaultClassLoader(ClassLoader defaultClassLoader)
Sets the default classloader

Parameters: defaultClassLoader - the new default ClassLoader

Copyright © 2011. All Rights Reserved.