List of utility methods to do Resource Get
List | getResourcesFromDirectory(File resource, Pattern pattern) get Resources From Directory ArrayList<URL> urls = new ArrayList<>(); final File[] fileList = resource.listFiles(); if (fileList == null) return urls; for (final File file : fileList) { if (file.isDirectory()) { urls.addAll(getResourcesFromDirectory(file, pattern)); } else { ... |
String | getResourceString(ResourceBundle rb, String key, Object param1) Get formatted string from resource bundle String raw = rb.getString(key); Object params[] = new Object[1]; params[0] = param1; String formatted = MessageFormat.format(raw, params); return formatted; |
String | getResourceString(String key) Returns a string from the resource bundle. try { return resourceBundle.getString(key); } catch (MissingResourceException e) { return key; } catch (NullPointerException e) { return "!" + key + "!"; |
String | getResourceString(String key, Object... args) get Resource String ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE);
String str = bundle.getString(key);
return MessageFormat.format(str, args);
|
URL | loadResource(Class> contextClass, String resourceName) Returns the url of a resource. URL url = null; if (contextClass != null) { url = Resources.getResource(contextClass, resourceName); if (url == null && Thread.currentThread().getContextClassLoader() != null) { url = Thread.currentThread().getContextClassLoader().getResource(resourceName); return url; ... |
InputStream | loadResource(final String name) Load given resource and return as an input stream. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL url = classLoader.getResource(name); if (url != null) { return url.openStream(); return new FileInputStream(name); |
byte[] | loadResource(final String s) Method loadResource final URL url = new URL(s); final InputStream inputstream = url.openStream(); final byte data[] = readFully(inputstream); inputstream.close(); return data; |
byte[] | readResource(String resource, Class c) _more_ return readResource(resource, c, false);
|
String | readToString(final Class nearClass, final String resource) Returns text content read from the file located near specified class. try { return readToString(nearClass.getResourceAsStream(resource)); } catch (final Throwable e) { return null; |
String | readToString(final Class nearClass, final String resource, final String encoding) Returns content read from the file located near specified class. try { return readToString(nearClass.getResourceAsStream(resource), encoding); } catch (final Throwable e) { return null; |