/** * Locates the resource with the specified name. For Java 2 callers, the * current thread's context class loader is preferred, falling back on the * class loader of the caller when the current thread's context is not set, * or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>URL</code> object */ public static URL getResource( String name, ClassLoader callerClassLoader) { _checkResourceName(name); URL url = null; ClassLoader loader = getContextClassLoader(); if (loader != null) url = loader.getResource(name); if (url == null) { if (callerClassLoader != null) url = callerClassLoader.getResource(name); else url = ClassLoader.getSystemResource(name); } return url; }
/** * Locates the resource stream with the specified name. For Java 2 callers, * the current thread's context class loader is preferred, falling back on * the class loader of the caller when the current thread's context is not * set, or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>InputStream</code> object */ public static InputStream getResourceAsStream( String name, ClassLoader callerClassLoader) { _checkResourceName(name); InputStream stream = null; ClassLoader loader = getContextClassLoader(); if (loader != null) stream = loader.getResourceAsStream(name); if (stream == null) { if (callerClassLoader != null) stream = callerClassLoader.getResourceAsStream(name); else stream = ClassLoader.getSystemResourceAsStream(name); } return stream; }
/** * Locates the resource with the specified name. For Java 2 callers, the * current thread's context class loader is preferred, falling back on the * class loader of the caller when the current thread's context is not set, * or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>URL</code> object */ public static URL getResource( String name, ClassLoader callerClassLoader) { _checkResourceName(name); URL url = null; ClassLoader loader = getContextClassLoader(); if (loader != null) url = loader.getResource(name); if (url == null) { if (callerClassLoader != null) url = callerClassLoader.getResource(name); else url = ClassLoader.getSystemResource(name); } return url; }
/** * Locates the resource stream with the specified name. For Java 2 callers, * the current thread's context class loader is preferred, falling back on * the class loader of the caller when the current thread's context is not * set, or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>InputStream</code> object */ public static InputStream getResourceAsStream( String name, ClassLoader callerClassLoader) { _checkResourceName(name); InputStream stream = null; ClassLoader loader = getContextClassLoader(); if (loader != null) stream = loader.getResourceAsStream(name); if (stream == null) { if (callerClassLoader != null) stream = callerClassLoader.getResourceAsStream(name); else stream = ClassLoader.getSystemResourceAsStream(name); } return stream; }