List of utility methods to do Resource Load
Properties | getResource(final String resource) Reads configuration from a classpath resource stream obtained from the current thread's class loader through ClassLoader#getSystemResourceAsStream(String) . InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); if (input == null) { throw new IllegalArgumentException("configuration file '" + resource + "' not found on classpath"); final Properties config = new Properties(); try { config.load(input); } catch (final IOException e) { ... |
File | getResource(String fileName) get Resource return new File(attemptResolvePathFromBSearchRoot("resources/" + fileName)); |
File | getResource(String fileName, int type) Returns a game resource. String filePath; switch (type) { default: filePath = paths.get(type) + fileName; break; case RES_PREFERENCE: filePath = paths.get(type) + fileName + ".properties"; break; ... |
InputStream | getResource(String name) get Resource ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream(name);
return is;
|
InputStream | getResource(String path) Get a resource relative to the application class. InputStream x = ClassLoader.getSystemResourceAsStream("./" + path); if (x != null) return x; try { return new FileInputStream("./data/" + path); } catch (FileNotFoundException e) { e.printStackTrace(); return null; |
InputStream | getResource(String propertiesPath) get Resource return new FileInputStream(new File(propertiesPath)); |
InputStream | getResource(String uri) Get an InputStream from specified resource uri. try { return new URL(uri).openStream(); } catch (MalformedURLException mue) { return new FileInputStream(uri); |
String | getResourceAbsolutePath(String pluginId, String... path) Provide bundle resource absolute path StringBuilder builder = new StringBuilder(); for (String fragment : path) { builder.append("/" + fragment); String filePath = ""; try { filePath = FileLocator.toFileURL(Platform.getBundle(pluginId).getEntry("/")).getFile() + "resources" + builder.toString(); ... |
BufferedReader | getResourceAsBufferedReader(Class> clazz, String resourceName) get Resource As Buffered Reader return new BufferedReader(getResourceAsInputStreamReader(clazz, resourceName)); |
byte[] | getResourceAsByteArray(Object context, String resourceName) get Resource As Byte Array InputStream inputStream = getResourceAsStream(context, resourceName); final ByteArrayOutputStream fileBytes = new ByteArrayOutputStream(); try { writeInputToOutput(inputStream, fileBytes); } finally { inputStream.close(); return fileBytes.toByteArray(); ... |