Class ResourceLoader


  • public final class ResourceLoader
    extends Object
    Utility class for loading resource from class loader, relative to a given class.
    Since:
    1.14.0
    Author:
    Pascal Essiembre
    • Method Detail

      • getStream

        public static InputStream getStream​(Class<?> clazz,
                                            String suffix)
        Gets a resource from class loader as stream. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
        Parameters:
        clazz - the class to load related resource
        suffix - the suffix of the file to load with the same name as class
        Returns:
        input stream or null if class is null or resource could not be found.
      • getReader

        public static Reader getReader​(Class<?> clazz,
                                       String suffix)
        Gets a UTF-8 resource from class loader as a reader. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
        Parameters:
        clazz - the class to load related resource
        suffix - the suffix of the file to load with the same name as class
        Returns:
        reader or null if class is null or resource could not be found.
      • getString

        public static String getString​(Class<?> clazz,
                                       String suffix)
        Gets a UTF-8 a resource from class loader as a string. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
        Parameters:
        clazz - the class to load related resource
        suffix - the suffix of the file to load with the same name as class
        Returns:
        string or null if class is null or resource could not be found.
      • getXmlStream

        public static InputStream getXmlStream​(Class<?> clazz)
        Gets a stream from a resource matching class name with ".xml" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        XML stream or null
      • getXmlReader

        public static Reader getXmlReader​(Class<?> clazz)
        Gets a UTF-8 reader from resource matching class name with ".xml" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        XML reader or null
      • getXmlString

        public static String getXmlString​(Class<?> clazz)
        Gets a UTF-8 string from resource matching class name with ".xml" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        XML string or null
      • getTxtStream

        public static InputStream getTxtStream​(Class<?> clazz)
        Gets a stream from a resource matching class name with ".txt" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        text stream or null
      • getTxtReader

        public static Reader getTxtReader​(Class<?> clazz)
        Gets a UTF-8 reader from resource matching class name with ".txt" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        text reader or null
      • getTxtString

        public static String getTxtString​(Class<?> clazz)
        Gets a UTF-8 string from resource matching class name with ".txt" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        text string or null
      • getHtmlStream

        public static InputStream getHtmlStream​(Class<?> clazz)
        Gets a stream from a resource matching class name with ".html" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        HTML stream or null
      • getHtmlReader

        public static Reader getHtmlReader​(Class<?> clazz)
        Gets a UTF-8 reader from resource matching class name with ".html" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        HTML reader or null
      • getHtmlString

        public static String getHtmlString​(Class<?> clazz)
        Gets a UTF-8 string from resource matching class name with ".html" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        HTML string or null
      • getJsonStream

        public static InputStream getJsonStream​(Class<?> clazz)
        Gets a stream from a resource matching class name with ".json" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        JSON stream or null
      • getJsonReader

        public static Reader getJsonReader​(Class<?> clazz)
        Gets a UTF-8 reader from resource matching class name with ".json" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        JSON reader or null
      • getJsonString

        public static String getJsonString​(Class<?> clazz)
        Gets a UTF-8 string from resource matching class name with ".json" suffix.
        Parameters:
        clazz - the class to load related resource
        Returns:
        JSON string or null