public abstract class ResourceHelper extends Object
| Constructor and Description |
|---|
ResourceHelper() |
| Modifier and Type | Method and Description |
|---|---|
static Class<?>[] |
findClasses(String pkg,
boolean recurse)
Searches for classes in the specified package.
|
static Class<?>[] |
findClasses(String pkg,
ClassLoader cl,
boolean recurse)
Searches for classes in the specified package using the specified class
loader.
|
static ClassLoader |
getClassLoader()
Returns class loader.
|
static ClassLoader |
getClassLoader(ClassLoader cl)
Returns
getClassLoader() if the specified class loader is
null; returns the specified class loader otherwise. |
static String |
getPackageName(Class<?> c)
Returns package name for the specified class.
|
static String |
getResourcePath(Class<?> c)
Returns resource path for package of the specified class.
|
static URL |
getResourceURL(String name)
Returns resource URL for the specified resource name.
|
static URL |
getResourceURL(String name,
ClassLoader cl)
Returns resource URL for the specified resource name using the specified
class loader.
|
static byte[] |
readBinaryResource(String name)
Reads content of resource with the specified name as binary data.
|
static byte[] |
readBinaryResource(String name,
ClassLoader cl)
Reads content of resource with the specified name as binary data using
the specified class loader.
|
static String |
readTextResource(String name)
Reads content of resource with the specified name as character data.
|
static String |
readTextResource(String name,
ClassLoader cl)
Reads content of resource with the specified name as character data
using the specified class loader.
|
static String |
readTextResource(String name,
String encoding)
Reads content of resource with the specified name as character data
using the specified character encoding.
|
static String |
readTextResource(String name,
String encoding,
ClassLoader cl)
Reads content of resource with the specified name as character data
using the specified character encoding and class loader.
|
public static ClassLoader getClassLoader()
This method tries to resolve class loader in the following sequence:
null then this method returns
null.public static ClassLoader getClassLoader(ClassLoader cl)
getClassLoader() if the specified class loader is
null; returns the specified class loader otherwise.cl - Class loader.getClassLoader() if the specified class loader is
null; returns the specified class loader otherwise.public static String getPackageName(Class<?> c)
c - Class which package name should be returned.public static String getResourcePath(Class<?> c)
c - Class contained in the package.public static URL getResourceURL(String name)
name - Resource name.ResourceError - if resource with the specified name is not found.getResourceURL(String, ClassLoader)public static URL getResourceURL(String name, ClassLoader cl)
name - Resource name.cl - Class loader to be used for resource loading.ResourceError - if resource with the specified name is not found.public static byte[] readBinaryResource(String name)
name - Resource name.ResourceError - if an error occurred when reading resource.readBinaryResource(String, ClassLoader)public static byte[] readBinaryResource(String name, ClassLoader cl)
name - Resource name.cl - Class loader to be used for resource loading.ResourceError - if an error occurred when reading resource.#readBinaryResource(InputStream)public static String readTextResource(String name)
name - Resource name.ResourceError - if an error occurred when reading resource.readTextResource(String, String, ClassLoader)public static String readTextResource(String name, ClassLoader cl)
name - Resource name.cl - Class loader to be used for resource loading.ResourceError - if an error occurred when reading resource.readTextResource(String, String, ClassLoader)public static String readTextResource(String name, String encoding)
name - Resource name.encoding - Character encoding.ResourceError - if an error occurred when reading resource.readTextResource(String, String, ClassLoader)public static String readTextResource(String name, String encoding, ClassLoader cl)
name - Resource name.encoding - Character encoding.cl - Class loader to be used for resource loading.ResourceError - if an error occurred when reading resource.#readTextResource(InputStream, String)public static Class<?>[] findClasses(String pkg, boolean recurse)
pkg - Package name where to search classes.recurse - Determines if search should be performed recursively.public static Class<?>[] findClasses(String pkg, ClassLoader cl, boolean recurse)
pkg - Package name where to search classes.cl - Class loader to be used for class loading.recurse - Determines if search should be performed recursively.Copyright © 2010-2012 FoxLabs. All Rights Reserved.