Java Utililty Methods Resource Path Get

List of utility methods to do Resource Path Get

  1. HOME
  2. Java
  3. R
  4. Resource Path Get

Description

The list of methods to do Resource Path Get are organized into topic(s).

Method

String classToResource(String className)
class To Resource
if (className == null)
 return null;
return className.replace('.', '/') + CLASS_FILE_NAME_EXTENSION;
T deserialize(Class parentOfResource, String resourcePath, Class targetClass)
deserialize
URL resourceUrl = parentOfResource.getResource(resourcePath);
requireNonNull(resourceUrl,
 format("resource '%s' of class '%s' not found", resourcePath, parentOfResource.getCanonicalName()));
try {
 return objectMapper.readValue(resourceUrl, targetClass);
} catch (IOException e) {
 throw new RuntimeException(e);
boolean existsResource(String pathName)
exists Resource
URL url = ClassLoader.getSystemClassLoader().getResource(pathName);
return (url != null);
String getAbsolutePathFromResource(Class reference, String resource)
Returns the absolute path of the resource.
URL urlResource = reference.getResource(resource);
if (urlResource == null)
 return null;
String urlString = URLDecoder.decode(urlResource.toString());
if (urlString.startsWith("jar:"))
 urlString = urlString.substring("jar:".length());
if (urlString.startsWith("file:"))
 urlString = urlString.substring("file:".length());
...
URL getAbsoluteResource(String path)
get Absolute Resource
return _getAbsoluteResource(path, true);
File getAlternateResourceFile(final String resourcePath)
get Alternate Resource File
return getResourceFileRelativeToBase(alternateResourceRootFolder, resourcePath);
String getBasePath(Class clazz, String resource)
Get the path to the directory containing the resource (including the trailing slash).
final String filename = getFilename(clazz, resource);
return getBasePath(filename);
List getChildResources(String path)
get Child Resources
List<URL> result = new LinkedList<URL>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> p = classLoader.getResources(path);
while (p.hasMoreElements()) {
 URL resource = p.nextElement();
 if (resource.getProtocol().equalsIgnoreCase("FILE")) {
 result.addAll(loadDirectory(resource.getFile()));
 } else if (resource.getProtocol().equalsIgnoreCase("JAR")) {
...
URL getClassResource(Class clazz, String resPath)
get Class Resource
URL url = clazz.getResource(resPath);
if (url == null) {
 ClassLoader loader = clazz.getClassLoader();
 if (loader != null)
 url = loader.getResource(resPath);
 if (url == null) {
 loader = Thread.currentThread().getContextClassLoader();
 if (loader != null)
...
List getClassResources(Class clazz, String resPath)
get Class Resources
List<URL> urlList = new ArrayList<URL>();
Enumeration<URL> urls = null;
try {
 ClassLoader loader = clazz.getClassLoader();
 if (loader != null)
 urls = loader.getResources(resPath);
 if (urls == null || !urls.hasMoreElements()) {
 loader = Thread.currentThread().getContextClassLoader();
...


AltStyle によって変換されたページ (->オリジナル) /