Package com.github.spigotbasics.core
Object SafeResourceGetter
-
- All Implemented Interfaces:
public class SafeResourceGetter
Provides safe and easy access to a resource. This will first try to get the resource from the class loader of the given class, and if that fails, it will try to get it from Class.getResourceAsStream and Class.getResource.
It also adds a slash to the path if it doesn't start with one.
-
-
Field Summary
Fields Modifier and Type Field Description public final static SafeResourceGetter
INSTANCE
-
Method Summary
Modifier and Type Method Description final InputStream
getResourceAsStream(Class<?> clazz, String path)
Get resource as stream from the class loader of the given class, or from the class itself. final URL
getResource(Class<?> clazz, String path)
Get resource as URL from the class loader of the given class, or from the class itself. -
-
Method Detail
-
getResourceAsStream
final InputStream getResourceAsStream(Class<?> clazz, String path)
Get resource as stream from the class loader of the given class, or from the class itself.
- Parameters:
clazz
- Class to get the resource frompath
- Path to the resource.- Returns:
Resource as stream, or null if it doesn't exist
-
getResource
final URL getResource(Class<?> clazz, String path)
Get resource as URL from the class loader of the given class, or from the class itself.
- Parameters:
clazz
- Class to get the resource frompath
- Path to the resource.- Returns:
Resource as URL, or null if it doesn't exist
-
-
-
-