List of utility methods to do Resource Load
String | getResourceAsString(String path) get Resource As String InputStream is = ClassLoader.getSystemResourceAsStream(path); BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { sb.append(line).append('\n'); ... |
String | getResourceAsString(String relativePath) get Resource As String InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(relativePath); Scanner s = new Scanner(inputStream, "UTF-8"); Scanner s2 = s.useDelimiter("\\A"); String result = s2.hasNext() ? s2.next() : ""; s.close(); s2.close(); try { inputStream.close(); ... |
File | getResourceAsTempFile(Object context, String resourceName) get Resource As Temp File InputStream is = getResourceAsStream(context, resourceName);
return writeStreamToTempFile(resourceName, is);
|
ResourceBundle | getResourceBundle(String baseName) get Resource Bundle return ResourceBundle.getBundle(i18nDirectory.toString() + File.separator + baseName);
|
ResourceBundle | getResourceBundle(String resourceURI, Locale targetLocale) get Resource Bundle int index = resourceURI.lastIndexOf("/"); if (index == -1) { throw new IllegalArgumentException("Invalid resourceURI"); String resourceDirectory = resourceURI.substring(0, index + 1); String resourceBundleName = resourceURI.substring(index + 1); URL[] classpath = new URL[1]; classpath[0] = Platform.resolve(new URL(resourceDirectory)); ... |
Object | getResourceBundleForLoc(String language, String fileName) Gets the Resource bundle object given the language if ((language == null) || ("".equals(language))) { language = "en"; Locale locale = new Locale(language); ResourceBundle rb = ResourceBundle.getBundle(fileName, locale); return rb; |
byte[] | getResourceBytes(String path) get Resource Bytes InputStream s = ClassLoader.getSystemClassLoader().getResourceAsStream(path); try { return readAll(s); } finally { try { s.close(); } catch (IOException e) { e.printStackTrace(); ... |
InputStream | getResourceByZip(final ZipInputStream zipIN, final String resourcePath) get Resource By Zip ZipEntry e = null; while ((e = zipIN.getNextEntry()) != null) { if (e.getName().equals(resourcePath) == true) { return zipIN; zipIN.closeEntry(); return null; ... |
File | getResourceDirectory() get Resource Directory File resourceDir = new File("./smos-box/smos-reader/src/test/resources/org/esa/smos/dataio/smos/dddb/"); if (!resourceDir.isDirectory()) { resourceDir = new File("./src/test/resources/org/esa/smos/dataio/smos/dddb/"); return resourceDir; |
File | getResourceFile(Class> clazz, String path) Get resource File corresponding to a given path in clazz package try { return new File(clazz.getResource(path).getPath()); } catch (NullPointerException e) { throw new RuntimeException("Resource '" + path + "' not found"); |