Java Resource Load getResourceAsStream(String name, Class clazz)

Here you can find the source of getResourceAsStream(String name, Class clazz)

Description

get Resource As Stream

License

LGPL

Declaration

public static InputStream getResourceAsStream(String name, Class clazz) 

Method Source Code

//package com.java2s;

import java.io.InputStream;

public class Main {
    public static InputStream getResourceAsStream(String name, Class clazz) {
        ClassLoader loader;//from  w  w w  .  ja va2  s  .  c om

        // TODO - is this needed?  ClassPathLoader is a GemFire service and
        // is not available in JGroups
        //        try {
        //          return ClassPathLoader.getLatest().getResourceAsStream(name);
        //        }
        //        catch (VirtualMachineError err) { // GemStoneAddition
        //          // If this ever returns, rethrow the error.  We're poisoned
        //          // now, so don't let this thread continue.
        //          throw err;
        //        }
        //        catch(Throwable t) {
        //        }

        if (clazz != null) {
            try {
                loader = clazz.getClassLoader();
                if (loader != null) {
                    return loader.getResourceAsStream(name);
                }
            } catch (VirtualMachineError err) { // GemStoneAddition
                // If this ever returns, rethrow the error.  We're poisoned
                // now, so don't let this thread continue.
                throw err;
            } catch (Throwable t) {
            }
        }
        try {
            loader = ClassLoader.getSystemClassLoader();
            if (loader != null) {
                return loader.getResourceAsStream(name);
            }
        } catch (VirtualMachineError err) { // GemStoneAddition
            // If this ever returns, rethrow the error.  We're poisoned
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
        }

        return null;
    }
}

Related

  1. getResourceAsStream(String name)
  2. getResourceAsStream(String name)
  3. getResourceAsStream(String name)
  4. getResourceAsStream(String name)
  5. getResourceAsStream(String name, Class aClass)
  6. getResourceAsStream(String name, Class clazz)
  7. getResourceAsStream(String name, Class clzz)
  8. getResourceAsStream(String path)
  9. getResourceAsStream(String path, Class caller)