com.ibatis.common.resources
Class Resources

java.lang.Object
  extended by com.ibatis.common.resources.Resources

public class Resources
extends java.lang.Object

A class to simplify access to resources through the classloader.


方法摘要
static java.lang.Class classForName(java.lang.String className)
          Loads a class
static java.nio.charset.Charset getCharset()
           
static java.lang.ClassLoader getDefaultClassLoader()
          Returns the default classloader (may be null).
static java.io.File getResourceAsFile(java.lang.ClassLoader loader, java.lang.String resource)
          Returns a resource on the classpath as a File object
static java.io.File getResourceAsFile(java.lang.String resource)
          Returns a resource on the classpath as a File object
static java.util.Properties getResourceAsProperties(java.lang.ClassLoader loader, java.lang.String resource)
          Returns a resource on the classpath as a Properties object
static java.util.Properties getResourceAsProperties(java.lang.String resource)
          Returns a resource on the classpath as a Properties object
static java.io.Reader getResourceAsReader(java.lang.ClassLoader loader, java.lang.String resource)
          Returns a resource on the classpath as a Reader object
static java.io.Reader getResourceAsReader(java.lang.String resource)
          Returns a resource on the classpath as a Reader object
static java.io.InputStream getResourceAsStream(java.lang.ClassLoader loader, java.lang.String resource)
          Returns a resource on the classpath as a Stream object
static java.io.InputStream getResourceAsStream(java.lang.String resource)
          Returns a resource on the classpath as a Stream object
static java.net.URL getResourceURL(java.lang.ClassLoader loader, java.lang.String resource)
          Returns the URL of the resource on the classpath
static java.net.URL getResourceURL(java.lang.String resource)
          Returns the URL of the resource on the classpath
static java.util.Properties getUrlAsProperties(java.lang.String urlString)
          Gets a URL as a Properties object
static java.io.Reader getUrlAsReader(java.lang.String urlString)
          Gets a URL as a Reader
static java.io.InputStream getUrlAsStream(java.lang.String urlString)
          Gets a URL as an input stream
static java.lang.Object instantiate(java.lang.Class clazz)
          Creates an instance of a class
static java.lang.Object instantiate(java.lang.String className)
          Creates an instance of a class
static void setCharset(java.nio.charset.Charset charset)
          Use this method to set the Charset to be used when calling the getResourceAsReader methods.
static void setDefaultClassLoader(java.lang.ClassLoader defaultClassLoader)
          Sets the default classloader
 
类方法继承: java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

方法详细信息

getDefaultClassLoader

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

返回:
The default classloader

setDefaultClassLoader

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

参数:
defaultClassLoader - - the new default ClassLoader

getResourceURL

public static java.net.URL getResourceURL(java.lang.String resource)
                                   throws java.io.IOException
Returns the URL of the resource on the classpath

参数:
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceURL

public static java.net.URL getResourceURL(java.lang.ClassLoader loader,
                                          java.lang.String resource)
                                   throws java.io.IOException
Returns the URL of the resource on the classpath

参数:
loader - The classloader used to load the resource
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resource)
                                               throws java.io.IOException
Returns a resource on the classpath as a Stream object

参数:
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.ClassLoader loader,
                                                      java.lang.String resource)
                                               throws java.io.IOException
Returns a resource on the classpath as a Stream object

参数:
loader - The classloader used to load the resource
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsProperties

public static java.util.Properties getResourceAsProperties(java.lang.String resource)
                                                    throws java.io.IOException
Returns a resource on the classpath as a Properties object

参数:
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsProperties

public static java.util.Properties getResourceAsProperties(java.lang.ClassLoader loader,
                                                           java.lang.String resource)
                                                    throws java.io.IOException
Returns a resource on the classpath as a Properties object

参数:
loader - The classloader used to load the resource
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsReader

public static java.io.Reader getResourceAsReader(java.lang.String resource)
                                          throws java.io.IOException
Returns a resource on the classpath as a Reader object

参数:
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsReader

public static java.io.Reader getResourceAsReader(java.lang.ClassLoader loader,
                                                 java.lang.String resource)
                                          throws java.io.IOException
Returns a resource on the classpath as a Reader object

参数:
loader - The classloader used to load the resource
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsFile

public static java.io.File getResourceAsFile(java.lang.String resource)
                                      throws java.io.IOException
Returns a resource on the classpath as a File object

参数:
resource - The resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getResourceAsFile

public static java.io.File getResourceAsFile(java.lang.ClassLoader loader,
                                             java.lang.String resource)
                                      throws java.io.IOException
Returns a resource on the classpath as a File object

参数:
loader - - the classloader used to load the resource
resource - - the resource to find
返回:
The resource
抛出异常:
java.io.IOException - If the resource cannot be found or read

getUrlAsStream

public static java.io.InputStream getUrlAsStream(java.lang.String urlString)
                                          throws java.io.IOException
Gets a URL as an input stream

参数:
urlString - - the URL to get
返回:
An input stream with the data from the URL
抛出异常:
java.io.IOException - If the resource cannot be found or read

getUrlAsReader

public static java.io.Reader getUrlAsReader(java.lang.String urlString)
                                     throws java.io.IOException
Gets a URL as a Reader

参数:
urlString - - the URL to get
返回:
A Reader with the data from the URL
抛出异常:
java.io.IOException - If the resource cannot be found or read

getUrlAsProperties

public static java.util.Properties getUrlAsProperties(java.lang.String urlString)
                                               throws java.io.IOException
Gets a URL as a Properties object

参数:
urlString - - the URL to get
返回:
A Properties object with the data from the URL
抛出异常:
java.io.IOException - If the resource cannot be found or read

classForName

public static java.lang.Class classForName(java.lang.String className)
                                    throws java.lang.ClassNotFoundException
Loads a class

参数:
className - - the class to load
返回:
The loaded class
抛出异常:
java.lang.ClassNotFoundException - If the class cannot be found (duh!)

instantiate

public static java.lang.Object instantiate(java.lang.String className)
                                    throws java.lang.ClassNotFoundException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException
Creates an instance of a class

参数:
className - - the class to create
返回:
An instance of the class
抛出异常:
java.lang.ClassNotFoundException - If the class cannot be found (duh!)
java.lang.InstantiationException - If the class cannot be instantiaed
java.lang.IllegalAccessException - If the class is not public, or other access problems arise

instantiate

public static java.lang.Object instantiate(java.lang.Class clazz)
                                    throws java.lang.InstantiationException,
                                           java.lang.IllegalAccessException
Creates an instance of a class

参数:
clazz - - the class to create
返回:
An instance of the class
抛出异常:
java.lang.InstantiationException - If the class cannot be instantiaed
java.lang.IllegalAccessException - If the class is not public, or other access problems arise

getCharset

public static java.nio.charset.Charset getCharset()

setCharset

public static void setCharset(java.nio.charset.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)

参数:
charset -