MCPcopy Create free account
hub / github.com/0opslab/opslabJutil / getFile

Method getFile

src/main/java/com/opslab/helper/ClassHelper.java:477–496  ·  view source on GitHub ↗

获取资源文件 @param resourceLocation @return @throws FileNotFoundException

(String resourceLocation)

Source from the content-addressed store, hash-verified

475 * @throws FileNotFoundException
476 */
477 public static File getFile(String resourceLocation) throws FileNotFoundException {
478 AssertUtil.notNull(resourceLocation,"Resource location must not be null");
479 if (resourceLocation.startsWith("classpath:")) {
480 String path = resourceLocation.substring("classpath:".length());
481 String description = "class path resource [" + path + "]";
482 ClassLoader cl = getContextClassLoader();
483 URL url = cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path);
484 if (url == null) {
485 throw new FileNotFoundException(description + " cannot be resolved to absolute file path because it does not exist");
486 } else {
487 return getFile(url, description);
488 }
489 } else {
490 try {
491 return getFile(new URL(resourceLocation));
492 } catch (MalformedURLException var5) {
493 return new File(resourceLocation);
494 }
495 }
496 }
497
498 public static File getFile(URL resourceUrl) throws FileNotFoundException {
499 return getFile(resourceUrl, "URL");

Callers 1

resourcePathMethod · 0.80

Calls 4

notNullMethod · 0.95
getContextClassLoaderMethod · 0.95
toURIMethod · 0.95
equalsMethod · 0.80

Tested by

no test coverage detected