MCPcopy Create free account
hub / github.com/antlr/codebuff / getResource

Method getResource

corpus/java/training/guava/io/Resources.java:190–200  ·  view source on GitHub ↗

Returns a URL pointing to resourceName if the resource is found using the plain Thread#getContextClassLoader() context class loader. In simple environments, the context class loader will find resources from the class path. In environments where different threads can have diffe

(String resourceName)

Source from the content-addressed store, hash-verified

188 * @throws IllegalArgumentException if the resource is not found
189 */
190 @CanIgnoreReturnValue // being used to check if a resource exists
191 // TODO(cgdecker): maybe add a better way to check if a resource exists
192 // e.g. Optional<URL> tryGetResource or boolean resourceExists
193 public static URL getResource(String resourceName) {
194 ClassLoader loader =
195 MoreObjects.firstNonNull(
196 Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader());
197 URL url = loader.getResource(resourceName);
198 checkArgument(url != null, "resource %s not found.", resourceName);
199 return url;
200 }
201
202 /**
203 * Given a {@code resourceName} that is relative to {@code contextClass}, returns a {@code URL}

Callers 5

urlMethod · 0.45
getBaseUrlMethod · 0.45
STGroupDirMethod · 0.45
getURLMethod · 0.45
setFormatMethod · 0.45

Calls 3

firstNonNullMethod · 0.95
checkArgumentMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected