Java Utililty Methods Resource Load

List of utility methods to do Resource Load

Description

The list of methods to do Resource Load are organized into topic(s).

Method

InputStreamgetResourceAsStream(Class clazz, String fileName)
get Resource As Stream
InputStream is = clazz.getResourceAsStream(fileName);
if (is == null) {
    is = clazz.getClassLoader().getResourceAsStream(fileName);
if (is == null) {
    is = ClassLoader.getSystemResourceAsStream(fileName);
if (is == null) {
...
InputStreamgetResourceAsStream(Class clazz, String resource)
get Resource As Stream
return clazz == null ? ClassLoader.getSystemResourceAsStream(resource)
        : clazz.getResourceAsStream(resource);
InputStreamgetResourceAsStream(Class clazz, String resourceName)
get Resource As Stream
return clazz.getResourceAsStream(resourceName);
InputStreamgetResourceAsStream(Class testClass, String resource)
get Resource As Stream
return testClass.getResourceAsStream(getResourcePath(testClass, resource));
InputStreamgetResourceAsStream(final String fileName, ClassLoader classLoader)
Gets a resource as InputStream.
InputStream fileIn;
fileIn = classLoader.getResourceAsStream(resolveFileName(fileName));
if (fileIn == null) {
    fileIn = classLoader.getResourceAsStream(resolveFileName("WEB-INF/classes/" + fileName));
if (fileIn == null) {
    fileIn = new FileInputStream(resolveFileName(fileName));
return fileIn;
InputStreamgetResourceAsStream(final String name)
Get resource as stream in privileged mode.
return Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
InputStreamgetResourceAsStream(final String resourceName, final Class caller)
Get the specified resource as a stream.
final String resource;
if (!resourceName.startsWith("/")) {
    final Package callerPackage = caller.getPackage();
    if (callerPackage != null) {
        resource = callerPackage.getName().replace('.', '/') + '/' + resourceName;
    } else {
        resource = resourceName;
    return getResourceAsStream(resource, caller.getClassLoader());
} else {
    return getResourceAsStream(resourceName, caller.getClassLoader());
InputStreamgetResourceAsStream(final String resourceName, final Class caller)
get Resource As Stream
final String resource;
if (resourceName.startsWith("/")) {
    resource = resourceName.substring(1);
} else {
    final Package callerPackage = caller.getPackage();
    if (callerPackage != null) {
        resource = callerPackage.getName().replace('.', '/') + '/' + resourceName;
    } else {
...
InputStreamgetResourceAsStream(Object context, String resourceName)
get Resource As Stream
Class<?> contextClass;
if (context instanceof Class<?>) {
    contextClass = (Class<?>) context;
} else {
    contextClass = context.getClass();
String fullResourceName = getFullyQualifiedResourceName(contextClass, resourceName);
InputStream is = contextClass.getClassLoader().getResourceAsStream(fullResourceName);
...
InputStreamgetResourceAsStream(Object o, String resource)
get Resource As Stream
String newPath = "";
if (resource.startsWith("/")) {
    newPath = "/net/ages/alwb/utils/app/resources" + resource;
} else {
    newPath = "/net/ages/alwb/utils/app/resources/" + resource;
try {
    return o.getClass().getResourceAsStream(newPath);
...