List of utility methods to do Resource Get
ImageInputStream | getResourceAsStream(Class> aClass, String name) get Resource As Stream final InputStream is = aClass.getResourceAsStream(name); if (is == null) { throw new IOException(MessageFormat.format("resource {0} not found", name)); return new FileCacheImageInputStream(is, null); |
InputStream | getResourceAsStream(final Class caller, final String resource) Get the specified resource as an input stream. if ((resource == null) || (resource.length() == 0)) { return null; final String absoluteResource; if (resource.charAt(0) == '/') { absoluteResource = resource; } else { final String callerName = caller.getName(); ... |
InputStream | getResourceAsStream(String resourceLocation) Resolve the given resource string to a java.io.InputStream .
if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); return Thread.currentThread().getContextClassLoader().getResourceAsStream(path); try { return new URL(resourceLocation).openStream(); } catch (MalformedURLException ex) { return new FileInputStream(resourceLocation); ... |
String | getResourceAsString(String prefix, String resource) get Resource As String Reader reader = new InputStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream(prefix + resource)); StringBuilder sb = new StringBuilder(); char[] c = new char[1024]; int l; while ((l = reader.read(c)) != -1) { sb.append(c, 0, l); return sb.toString(); |
String | getResourceAsString(String resource) Gets the resource as string. ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource(resource);
InputStream is = url.openStream();
return getStreamContentAsString(is);
|
URL | getResourceBase() Gets the Resource Base (resource directory). if (classLoader == null) { return null; return classLoader.getResource(RESOURCE_BASE_DIR); |
String | getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle) Returns the locale specific string for the given resource bundle key
ResourceBundle resourcebundleWS = ResourceBundle.getBundle(sResourceBundle); try { String sString = resourcebundleWS.getString(sKey); return MessageFormat.format(sString, sParam); } catch (Throwable e) { return sKey; |
String | getResourceContent(Object object, String resource) Returns the name of the resource file in the form of a string URL testURL = object.getClass().getResource(resource); String testFile = null; try { testFile = new URI(testURL.toString()).getPath(); } catch (URISyntaxException e) { e.printStackTrace(); File file = new File(testFile); ... |
File | getResourceDir(final Class> testClass) Get test resource directory final URL dir = ClassLoader.getSystemResource(testClass.getSimpleName()); if (dir == null) { throw new RuntimeException("Failed to find resource for " + testClass.getSimpleName()); try { return new File(dir.toURI()); } catch (URISyntaxException e) { throw new RuntimeException( ... |
String | getResourceExpression(String select) Returns the resource expression from the select xpath expression. if (select == null || (select.indexOf("/") == -1)) { return select; StringBuffer sb = new StringBuffer(100); StringTokenizer st = new StringTokenizer(select, "/"); while (st.hasMoreTokens()) { String token = (String) st.nextToken(); int index = token.indexOf("["); ... |