The list of methods to do Resource File are organized into topic(s).
File
copyResource(String name) copy Resource
InputStream is = URLClassLoader.getSystemResourceAsStream(name);
String tempDir = System.getProperty("java.io.tmpdir");
File tmp = new File(tempDir + File.separator + name);
tmp.deleteOnExit();
ByteStreams.copy(is, new FileOutputStream(tmp));
return tmp;
String
expendResource(String fileName) expend Resource
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
if (url != null) {
return new File(url.getPath()).toString();
} else {
throw new IOException(String.format("Resource file [%s] doesn't exist", fileName));
URL[]
getAllResources(Class> clazz, String resource) get All Resources
if (resource == null || resource.trim().length() == 0) {
throw new IllegalArgumentException("resource is null!");
ArrayList<URL> urlList = new ArrayList<URL>();
if (clazz != null) {
URL url = clazz.getResource(resource);
if (url != null) {
urlList.add(url);
...
String
getBaseLineFolder(String resourceFile) get Base Line Folder
String result = null;
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL localUrl = classLoader.getResource(resourceFile);
if (localUrl != null) {
result = convertFileUrlToPath(localUrl);
} catch (Exception ex) {
...
Map
> getBundlesContainingResource(BundleContext bundleContext, String resourcePattern)
Returns all bundles that contain a class
Map<Bundle, List<String>> result = new HashMap<Bundle, List<String>>();
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
List<String> entries = findEntries(bundle, resourcePattern);
if (entries != null && entries.size() != 0) {
result.put(bundle, entries);
return result;
URL
getDefaultWebXmlResourceLocation() get Default Web Xml Resource Location
return Thread.currentThread().getContextClassLoader()
.getResource("org/bladerunnerjs/model/appserver/non-j2ee-app-web.xml");