/** * @return all resources in Brooklyn's {@link BrooklynClassLoadingContext} with the given name. */ public Iterable<URL> getResources(String name) { return getLoader().getResources(name); }
private InputStream getResourceViaClasspath(String url) throws IOException { assert url.startsWith("classpath:"); String subUrl = url.substring("classpath:".length()); while (subUrl.startsWith("/")) subUrl = subUrl.substring(1); URL u = getLoader().getResource(subUrl); if (u!=null) return u.openStream(); else throw new IOException(subUrl+" not found on classpath"); }
public String getClassLoaderDir(String resourceInThatDir) { resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/"); URL resourceUrl = getLoader().getResource(resourceInThatDir); if (resourceUrl==null) throw new NoSuchElementException("Resource ("+resourceInThatDir+") not found"); URL containerUrl = getContainerUrl(resourceUrl, resourceInThatDir); if (!"file".equals(containerUrl.getProtocol())) throw new IllegalStateException("Resource ("+resourceInThatDir+") not on file system (at "+containerUrl+")"); //convert from file: URL to File File file; try { file = new File(containerUrl.toURI()); } catch (URISyntaxException e) { throw new IllegalStateException("Resource ("+resourceInThatDir+") found at invalid URI (" + containerUrl + ")", e); } if (!file.exists()) throw new IllegalStateException("Context class url substring ("+containerUrl+") not found on filesystem"); return file.getPath(); }