Package org.apache.ibatis.io
Class Resources
java.lang.Object
org.apache.ibatis.io.Resources
A class to simplify access to resources through the classloader.
- Author:
- Clinton Begin
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> classForName(String className) Loads a classstatic Charsetstatic ClassLoaderReturns the default classloader (may be null).static FilegetResourceAsFile(ClassLoader loader, String resource) Returns a resource on the classpath as a File objectstatic FilegetResourceAsFile(String resource) Returns a resource on the classpath as a File objectstatic PropertiesgetResourceAsProperties(ClassLoader loader, String resource) Returns a resource on the classpath as a Properties objectstatic PropertiesgetResourceAsProperties(String resource) Returns a resource on the classpath as a Properties objectstatic ReadergetResourceAsReader(ClassLoader loader, String resource) Returns a resource on the classpath as a Reader objectstatic ReadergetResourceAsReader(String resource) Returns a resource on the classpath as a Reader objectstatic InputStreamgetResourceAsStream(ClassLoader loader, String resource) Returns a resource on the classpath as a Stream objectstatic InputStreamgetResourceAsStream(String resource) Returns a resource on the classpath as a Stream objectstatic URLgetResourceURL(ClassLoader loader, String resource) Returns the URL of the resource on the classpathstatic URLgetResourceURL(String resource) Returns the URL of the resource on the classpathstatic PropertiesgetUrlAsProperties(String urlString) Gets a URL as a Properties objectstatic ReadergetUrlAsReader(String urlString) Gets a URL as a Readerstatic InputStreamgetUrlAsStream(String urlString) Gets a URL as an input streamstatic voidsetCharset(Charset charset) static voidsetDefaultClassLoader(ClassLoader defaultClassLoader) Sets the default classloader
-
Method Details
-
getDefaultClassLoader
Returns the default classloader (may be null).- Returns:
- The default classloader
-
setDefaultClassLoader
Sets the default classloader- Parameters:
defaultClassLoader- - the new default ClassLoader
-
getResourceURL
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
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
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
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
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
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
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
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
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
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
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
Loads a class- Parameters:
className- - the class to fetch- Returns:
- The loaded class
- Throws:
ClassNotFoundException- If the class cannot be found (duh!)
-
getCharset
-
setCharset
-