@Override public URL getResource(String name) { return this.enclosingClassLoader.getResource(name); }
private static boolean hasResource(String path) { try { return Version.class.getClassLoader().getResource(path) != null; } catch (Throwable t) { return false; } }
private static boolean hasResource(String path) { try { return Version.class.getClassLoader().getResource(path) != null; } catch (Throwable t) { return false; } }
/** * Returns the url identifying the resource. * * <p>See {@link ClassLoader#getResource} * * @throws NoSuchElementException if the resource cannot be loaded through the class loader, * despite physically existing in the class path. */ public final URL url() { URL url = loader.getResource(resourceName); if (url == null) { throw new NoSuchElementException(resourceName); } return url; }
/** * Resolves a URL for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ @Nullable protected URL resolveURL() { if (this.clazz != null) { return this.clazz.getResource(this.path); } else if (this.classLoader != null) { return this.classLoader.getResource(this.path); } else { return ClassLoader.getSystemResource(this.path); } }
private String getViewPage(Class<?> clazz, Collection<String> pageNames, String defaultValue) { while(clazz!=Object.class && clazz!=null) { for (String pageName : pageNames) { String name = clazz.getName().replace('.', '/').replace('$', '/') + "/" + pageName; if(clazz.getClassLoader().getResource(name)!=null) return '/'+name; } clazz = clazz.getSuperclass(); } return defaultValue; }
/** Gets URL for base of path containing Finalizer.class. */ URL getBaseUrl() throws IOException { // Find URL pointing to Finalizer.class file. String finalizerPath = FINALIZER_CLASS_NAME.replace('.', '/') + ".class"; URL finalizerUrl = getClass().getClassLoader().getResource(finalizerPath); if (finalizerUrl == null) { throw new FileNotFoundException(finalizerPath); } // Find URL pointing to base of class path. String urlString = finalizerUrl.toString(); if (!urlString.endsWith(finalizerPath)) { throw new IOException("Unsupported path style: " + urlString); } urlString = urlString.substring(0, urlString.length() - finalizerPath.length()); return new URL(finalizerUrl, urlString); }
protected boolean isAspectJWeavingEnabled(String value, ParserContext parserContext) { if ("on".equals(value)) { return true; } else if ("off".equals(value)) { return false; } else { // Determine default... ClassLoader cl = parserContext.getReaderContext().getBeanClassLoader(); return (cl != null && cl.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) != null); } }
private URL getResource(String fileName) { Class<?> c = getClass(); return c.getClassLoader().getResource(c.getName().replace('.','/').replace('$','/')+ fileName); }
@Override public URL getResource(String name) { if (isMasked(name)) return null; return super.getResource(name); }
/** * It is possible to determine if a resource from a bundle is a directory based on whether or not the ClassLoader * returns null for a path (which does not already contain a trailing '/') *and* that path with an added trailing '/' * * @param url the url * @return if the bundle resource represented by the bundle URL is a directory */ private boolean isBundleUrlDirectory(URL url) { return url.toExternalForm().endsWith("/") || getClassLoader().getResource(url.getPath().substring(1) + "/") != null; }
private static void load(LangLocale locale) { ResourceBundle bundle; ClassLoader classLoader = ClassLoader.getSystemClassLoader(); String resName = String.format("i18n/Messages_%s.properties", locale.get()); URL bundleUrl = classLoader.getResource(resName); if (bundleUrl == null) { throw new JadxRuntimeException("Locale resource not found: " + resName); } try (Reader reader = new InputStreamReader(bundleUrl.openStream(), StandardCharsets.UTF_8)) { bundle = new PropertyResourceBundle(reader); } catch (IOException e) { throw new JadxRuntimeException("Failed to load " + resName, e); } i18nMessagesMap.put(locale, bundle); }
@Override public URL getResource(String name) { if ("foo".equals(name)) { return url; } return super.getResource(name); } });
private String getResourcePath(String resName) { URL resource = getClass().getClassLoader().getResource(CERTIFICATE_TEST_DIR + resName); if (resource == null) { throw new RuntimeException("Resource not found: " + resName); } return resource.getPath(); } }
static File fileFromName(String filename) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL url = classLoader.getResource(filename); return new File(url.getPath()); }
@Override public void setUp() throws Exception { super.setUp(); // This folder is inside the nested-inf/classes directory, inside nestedroot.jar webRoot = "webroot2"; prevCL = Thread.currentThread().getContextClassLoader(); URL jarUrl = prevCL.getResource("nestedroot.jar"); URL rootUrl = new URL("jar:" + jarUrl + "!/nested-inf/classes!/"); URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{rootUrl}, prevCL); Thread.currentThread().setContextClassLoader(urlClassLoader); }
@Setup public void setup() { ClassLoader classLoader = getClass().getClassLoader(); small = loadJsonAsBuffer(classLoader.getResource("small.json")); large = loadJsonAsBuffer(classLoader.getResource("large.json")); }
@Setup public void setup() { ClassLoader classLoader = getClass().getClassLoader(); small = loadJson(classLoader.getResource("small.json")); large = loadJson(classLoader.getResource("large.json")); }
@Test public void testFindsExistingResourceWithGetResourceAndNoOverrides() { assertNotNull(thisClassLoader.getResource(EXISTING_RESOURCE)); assertNotNull(overridingLoader.getResource(EXISTING_RESOURCE)); }
@Test public void testDoesNotFindExistingResourceWithGetResourceAndNullOverride() { assertNotNull(thisClassLoader.getResource(EXISTING_RESOURCE)); overridingLoader.override(EXISTING_RESOURCE, null); assertNull(overridingLoader.getResource(EXISTING_RESOURCE)); }