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(String name, Class clzz)
get Resource As Stream
InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
if (inStream != null) {
    return inStream;
ClassLoader c = clzz.getClassLoader();
if (c != null) {
    inStream = c.getResourceAsStream(name);
    if (inStream != null) {
...
InputStreamgetResourceAsStream(String path)
Return the InputStream of the resource provided, following the #findResource(String) rules.
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return cl.getResourceAsStream(path);
InputStreamgetResourceAsStream(String path, Class caller)
get Resource As Stream
String resource = path;
if (resource.startsWith(SLASH)) {
    resource = resource.substring(1);
InputStream is = null;
File file = new File(path);
if (file.exists() && file.isFile()) {
    try {
...
InputStreamgetResourceAsStream(String path, ClassLoader cl)
get Resource As Stream
return cl.getResourceAsStream(path);
InputStreamgetResourceAsStream(String path, ClassLoader loader)
get Resource As Stream
if (loader == null) {
    return null;
InputStream in = loader.getResourceAsStream(path);
if (in != null) {
    return in;
return loader.getResourceAsStream(togglePath(path));
...
InputStreamgetResourceAsStream(String relativeName, Class clazz)
Returns the input stream for the resource with the specified relative name.
String newName = getAbsoluteResourceName(relativeName, clazz);
return getResourceAsStream(newName);
InputStreamgetResourceAsStream(String res)
get Resource As Stream
return Object.class.getResourceAsStream(res);
InputStreamgetResourceAsStream(String resName, Object obj)
get Resource As Stream
InputStream str = obj.getClass().getResourceAsStream(resName.startsWith("/") ? resName : "/" + resName);
File file = new File(resName);
if (file.exists())
    return new FileInputStream(file);
else if (str != null)
    return str;
else
    throw new FileNotFoundException("No such resource: " + resName);
...
InputStreamgetResourceAsStream(String resource, ClassLoader classLoader)
get Resource As Stream
InputStream returnValue = classLoader.getResourceAsStream(resource);
if (null == returnValue) {
    returnValue = classLoader.getResourceAsStream("/" + resource);
if (null != returnValue) {
    return returnValue;
return null;
...
InputStreamgetResourceAsStream(String resource, ClassLoader classLoader)
Returns a resource on the classpath as a Stream object.
InputStream in = null;
if (classLoader != null)
    in = classLoader.getResourceAsStream(resource);
if (in == null)
    in = ClassLoader.getSystemResourceAsStream(resource);
if (in == null)
    throw new IOException("Could not find resource " + resource);
return in;
...