List of utility methods to do Resource Get
File | getResource(String name) get Resource URI uri = locate(name); if (uri == null) { return null; return new File(uri); |
URL | getResource(String name) Determines the url of the indicated resource using the currently set class loader. return getClassLoader().getResource(name);
|
URL | getResource(String name) Get URL name of resource and check if it exists somewhere in the classpath. URL url = Thread.currentThread().getContextClassLoader().getResource(name); if (url == null) { throw new IOException("could not find " + name + " in classpath"); return url; |
URL | getResource(String name) get Resource ClassLoader cl = getClassLoader(); if (cl == null) { return null; return cl.getResource(name); |
URL | getResource(String name) Resources are those stored in the class path (e.g., src/main/resources). ClassLoader loader = Thread.currentThread().getContextClassLoader();
return loader.getResource(name);
|
URL | getResource(String name, Class neighbor) get Resource if (neighbor == null) { return getResource(name); return getResource(resolveName(neighbor, name), neighbor.getClassLoader()); |
URL | getResource(String name, Class> caller) get Resource ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); if (threadClassLoader != null) { URL url = threadClassLoader.getResource(name); if (url != null) return url; ClassLoader callerClassLoader = caller.getClassLoader(); return callerClassLoader.getResource(name); ... |
InputStream | getResource(String res) get Resource URL tokensResource = ClassLoader.getSystemClassLoader().getResource(res); FileInputStream is; try { is = new FileInputStream(new File(tokensResource.toURI())); return is; } catch (URISyntaxException e) { throw new RuntimeException(e); |
URL | getResource(String resource, Class> context) Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used. return getResource(resource, context, false);
|
byte[] | getResourceAsBytes(String resource) get Resource As Bytes ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource(resource); InputStream is = url.openStream(); byte[] data = getStreamContentAsBytes(is); is.close(); return data; |