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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • 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 from
        path - 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 from
        path - Path to the resource.
        Returns:

        Resource as URL, or null if it doesn't exist