Package org.apache.ibatis.io
Class Resources
- java.lang.Object
-
- org.apache.ibatis.io.Resources
-
public class Resources extends java.lang.ObjectA class to simplify access to resources through the classloader.- Author:
- Clinton Begin
-
-
Method Summary
Modifier and Type Method Description static java.lang.Class<?>classForName(java.lang.String className)Loads a classstatic java.nio.charset.CharsetgetCharset()static java.lang.ClassLoadergetDefaultClassLoader()Returns the default classloader (may be null).static java.io.FilegetResourceAsFile(java.lang.ClassLoader loader, java.lang.String resource)Returns a resource on the classpath as a File objectstatic java.io.FilegetResourceAsFile(java.lang.String resource)Returns a resource on the classpath as a File objectstatic java.util.PropertiesgetResourceAsProperties(java.lang.ClassLoader loader, java.lang.String resource)Returns a resource on the classpath as a Properties objectstatic java.util.PropertiesgetResourceAsProperties(java.lang.String resource)Returns a resource on the classpath as a Properties objectstatic java.io.ReadergetResourceAsReader(java.lang.ClassLoader loader, java.lang.String resource)Returns a resource on the classpath as a Reader objectstatic java.io.ReadergetResourceAsReader(java.lang.String resource)Returns a resource on the classpath as a Reader objectstatic java.io.InputStreamgetResourceAsStream(java.lang.ClassLoader loader, java.lang.String resource)Returns a resource on the classpath as a Stream objectstatic java.io.InputStreamgetResourceAsStream(java.lang.String resource)Returns a resource on the classpath as a Stream objectstatic java.net.URLgetResourceURL(java.lang.ClassLoader loader, java.lang.String resource)Returns the URL of the resource on the classpathstatic java.net.URLgetResourceURL(java.lang.String resource)Returns the URL of the resource on the classpathstatic java.util.PropertiesgetUrlAsProperties(java.lang.String urlString)Gets a URL as a Properties objectstatic java.io.ReadergetUrlAsReader(java.lang.String urlString)Gets a URL as a Readerstatic java.io.InputStreamgetUrlAsStream(java.lang.String urlString)Gets a URL as an input streamstatic voidsetCharset(java.nio.charset.Charset charset)static voidsetDefaultClassLoader(java.lang.ClassLoader defaultClassLoader)Sets the default classloader
-
-
-
Method Detail
-
getDefaultClassLoader
public static java.lang.ClassLoader getDefaultClassLoader()
Returns the default classloader (may be null).- Returns:
- The default classloader
-
setDefaultClassLoader
public static void setDefaultClassLoader(java.lang.ClassLoader defaultClassLoader)
Sets the default classloader- Parameters:
defaultClassLoader- - the new default ClassLoader
-
getResourceURL
public static java.net.URL getResourceURL(java.lang.String resource) throws java.io.IOExceptionReturns the URL of the resource on the classpath- Parameters:
resource- The resource to find- Returns:
- The resource
- Throws:
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.IOExceptionReturns 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:
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.IOExceptionReturns a resource on the classpath as a Stream object- Parameters:
resource- The resource to find- Returns:
- The resource
- Throws:
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.IOExceptionReturns 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:
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.IOExceptionReturns a resource on the classpath as a Properties object- Parameters:
resource- The resource to find- Returns:
- The resource
- Throws:
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.IOExceptionReturns 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:
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.IOExceptionReturns a resource on the classpath as a Reader object- Parameters:
resource- The resource to find- Returns:
- The resource
- Throws:
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.IOExceptionReturns 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:
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.IOExceptionReturns a resource on the classpath as a File object- Parameters:
resource- The resource to find- Returns:
- The resource
- Throws:
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.IOExceptionReturns 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:
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.IOExceptionGets a URL as an input stream- Parameters:
urlString- - the URL to get- Returns:
- An input stream with the data from the URL
- Throws:
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.IOExceptionGets a URL as a Reader- Parameters:
urlString- - the URL to get- Returns:
- A Reader with the data from the URL
- Throws:
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.IOExceptionGets a URL as a Properties object- Parameters:
urlString- - the URL to get- Returns:
- A Properties object with the data from the URL
- Throws:
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.ClassNotFoundExceptionLoads a class- Parameters:
className- - the class to fetch- Returns:
- The loaded class
- Throws:
java.lang.ClassNotFoundException- If the class cannot be found (duh!)
-
getCharset
public static java.nio.charset.Charset getCharset()
-
setCharset
public static void setCharset(java.nio.charset.Charset charset)
-
-