Package org.apache.ibatis.io
Class Resources
- java.lang.Object
-
- org.apache.ibatis.io.Resources
-
public class Resources extends Object
A class to simplify access to resources through the classloader.- Author:
- Clinton Begin
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>
classForName(String className)
Loads a classstatic Charset
getCharset()
static ClassLoader
getDefaultClassLoader()
Returns the default classloader (may be null).static File
getResourceAsFile(ClassLoader loader, String resource)
Returns a resource on the classpath as a File objectstatic File
getResourceAsFile(String resource)
Returns a resource on the classpath as a File objectstatic Properties
getResourceAsProperties(ClassLoader loader, String resource)
Returns a resource on the classpath as a Properties objectstatic Properties
getResourceAsProperties(String resource)
Returns a resource on the classpath as a Properties objectstatic Reader
getResourceAsReader(ClassLoader loader, String resource)
Returns a resource on the classpath as a Reader objectstatic Reader
getResourceAsReader(String resource)
Returns a resource on the classpath as a Reader objectstatic InputStream
getResourceAsStream(ClassLoader loader, String resource)
Returns a resource on the classpath as a Stream objectstatic InputStream
getResourceAsStream(String resource)
Returns a resource on the classpath as a Stream objectstatic URL
getResourceURL(ClassLoader loader, String resource)
Returns the URL of the resource on the classpathstatic URL
getResourceURL(String resource)
Returns the URL of the resource on the classpathstatic Properties
getUrlAsProperties(String urlString)
Gets a URL as a Properties objectstatic Reader
getUrlAsReader(String urlString)
Gets a URL as a Readerstatic InputStream
getUrlAsStream(String urlString)
Gets a URL as an input streamstatic void
setCharset(Charset charset)
static void
setDefaultClassLoader(ClassLoader defaultClassLoader)
Sets the default classloader
-
-
-
Method Detail
-
getDefaultClassLoader
public static ClassLoader getDefaultClassLoader()
Returns the default classloader (may be null).- Returns:
- The default classloader
-
setDefaultClassLoader
public static void setDefaultClassLoader(ClassLoader defaultClassLoader)
Sets the default classloader- Parameters:
defaultClassLoader
- - the new default ClassLoader
-
getResourceURL
public static URL getResourceURL(String resource) throws IOException
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) throws IOException
Returns the URL of the resource on the classpath- Parameters:
loader
- The classloader used to fetch the resourceresource
- The resource to find- Returns:
- The resource
- Throws:
IOException
- If the resource cannot be found or read
-
getResourceAsStream
public static InputStream getResourceAsStream(String resource) throws IOException
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) throws IOException
Returns a resource on the classpath as a Stream object- Parameters:
loader
- The classloader used to fetch the resourceresource
- The resource to find- Returns:
- The resource
- Throws:
IOException
- If the resource cannot be found or read
-
getResourceAsProperties
public static Properties getResourceAsProperties(String resource) throws IOException
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) throws IOException
Returns a resource on the classpath as a Properties object- Parameters:
loader
- The classloader used to fetch the resourceresource
- The resource to find- Returns:
- The resource
- Throws:
IOException
- If the resource cannot be found or read
-
getResourceAsReader
public static Reader getResourceAsReader(String resource) throws IOException
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) throws IOException
Returns a resource on the classpath as a Reader object- Parameters:
loader
- The classloader used to fetch the resourceresource
- The resource to find- Returns:
- The resource
- Throws:
IOException
- If the resource cannot be found or read
-
getResourceAsFile
public static File getResourceAsFile(String resource) throws IOException
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) throws IOException
Returns a resource on the classpath as a File object- Parameters:
loader
- - the classloader used to fetch the resourceresource
- - the resource to find- Returns:
- The resource
- Throws:
IOException
- If the resource cannot be found or read
-
getUrlAsStream
public static InputStream getUrlAsStream(String urlString) throws IOException
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
-
getUrlAsReader
public static Reader getUrlAsReader(String urlString) throws IOException
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
-
getUrlAsProperties
public static Properties getUrlAsProperties(String urlString) throws IOException
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
-
classForName
public static Class<?> classForName(String className) throws ClassNotFoundException
Loads a class- Parameters:
className
- - the class to fetch- Returns:
- The loaded class
- Throws:
ClassNotFoundException
- If the class cannot be found (duh!)
-
getCharset
public static Charset getCharset()
-
setCharset
public static void setCharset(Charset charset)
-
-