Created
October 29, 2017 11:36
-
-
Save saikocat/bd4e4f2be1cd895984f09b05de50dd92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Guava 14.0 - bundled with Spark | |
// https://github.com/google/guava/blob/v14.0/guava/src/com/google/common/io/Resources.java#L191 | |
/** | |
* Returns a {@code URL} pointing to {@code resourceName} if the resource is | |
* found in the class path. {@code Resources.class.getClassLoader()} is used | |
* to locate the resource. | |
*/ | |
public static URL getResource(String resourceName) { | |
URL url = Resources.class.getClassLoader().getResource(resourceName); | |
checkArgument(url != null, "resource %s not found.", resourceName); | |
return url; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------- | |
// Guava 18.0 - dependency for embedded-redis | |
// https://github.com/google/guava/blob/v18.0/guava/src/com/google/common/io/Resources.java | |
/** | |
* Returns a {@code URL} pointing to {@code resourceName} if the resource is | |
* found using the {@linkplain 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 different class loaders, for example app servers, the context class | |
* loader will typically have been set to an appropriate loader for the | |
* current thread. | |
* | |
* <p>In the unusual case where the context class loader is null, the class | |
* loader that loaded this class ({@code Resources}) will be used instead. | |
* | |
*/ | |
public static URL getResource(String resourceName) { | |
ClassLoader loader = MoreObjects.firstNonNull( | |
Thread.currentThread().getContextClassLoader(), | |
Resources.class.getClassLoader()); | |
URL url = loader.getResource(resourceName); | |
checkArgument(url != null, "resource %s not found.", resourceName); | |
return url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment