List of utility methods to do Resource Path Get
Enumeration | getResources(String path, ClassLoader loader) get Resources if (loader == null) { return null; Enumeration<URL> enm = loader.getResources(path); if (enm.hasMoreElements()) { return enm; return loader.getResources(togglePath(path)); ... |
List | getResources(String resourcePath, Class> caller) get Resources ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (resourcePath.startsWith("/")) { resourcePath = resourcePath.substring(1); if (classLoader != null) { return toList(classLoader.getResources(resourcePath)); classLoader = caller.getClassLoader(); ... |
InputStream | getResourceStream(final String bundle, final String path) Returns an InputStream for a given resource within a bundle. String location = Platform.getBundle(bundle).getLocation(); try { if (location.toLowerCase().endsWith(".jar")) { final int pos = location.indexOf("file:"); if (pos != -1) { location = location.substring(pos + 5); if (!location.startsWith("/")) { location = (Platform.getInstallLocation().getURL().toString() + location).substring(6); ... |
InputStream | getResourceStream(String path) get Resource Stream return getResourceStream(path, null);
|
String | getStringFromResource(Class> clazz, String path) get String From Resource if (clazz == null) throw new IllegalArgumentException("clazz is null."); if (path == null) throw new IllegalArgumentException("path is null."); StringWriter swOut = new StringWriter(); try { URL resource = clazz.getResource(path); if (resource == null) ... |
URL | getSystemResource(String path) Returns a URL from the path used to load classes. return ClassLoader.getSystemResource(path);
|
File | getSystemResource(String path) get System Resource try { URL url = classLoader.getResource(path); if (url != null) { return new File(url.toURI()); } else { throw new FileNotFoundException(path); } catch (URISyntaxException e) { ... |
T | loadResource(final Class> bundleClazz, final Class Loads a resource from any OSGi Bundle final Bundle bundle = FrameworkUtil.getBundle(bundleClazz); final URL url = bundle.getEntry(pathToFile); final InputStream stream = new FileInputStream(url.getFile()); try { if (resourceTypeclazz.isInstance(InputStream.class)) { return resourceTypeclazz.cast(stream); } catch (final Exception e) { ... |
List | loadResources(ClassLoader loader, String path) Utility to load the specified resources indicated by the path using the specified classloader ClassLoader classLoader = loader; ArrayList<URL> list = new ArrayList<>(); try { Enumeration<URL> resources = classLoader.getResources(path); while (resources.hasMoreElements()) { URL url = resources.nextElement(); list.add(url); } catch (IOException e) { e.printStackTrace(); return list; |
boolean | resourceExists(String path) resource Exists if (isRemote(path)) { try { URL url = createURL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); int code = conn.getResponseCode(); return code >= 200 && code < 300; } catch (IOException e) { return false; ... |