Class ResourceUtil


  • public class ResourceUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream getResourceAsStream​(java.lang.String resourcePath)
      We must get the Resource as a stream from the ContextClassLoader and not from the normal classLoader acquired by using getClass.getClassLoader, since we must be able to load resources from different threads e.g.
      static java.lang.String readResourceAsString​(java.lang.String resource)
      Helper method to read a resource from class using Class.getResourceAsStream(String) and convert into a String.
      • Methods inherited from class java.lang.Object

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

      • ResourceUtil

        public ResourceUtil()
    • Method Detail

      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String resourcePath)
        We must get the Resource as a stream from the ContextClassLoader and not from the normal classLoader acquired by using getClass.getClassLoader, since we must be able to load resources from different threads e.g. running in ant.
        Parameters:
        resourcePath - path to the resource
        Returns:
        resource as InputStream
      • readResourceAsString

        public static java.lang.String readResourceAsString​(java.lang.String resource)
                                                     throws java.io.IOException
        Helper method to read a resource from class using Class.getResourceAsStream(String) and convert into a String.
        Parameters:
        resource - The resource to read.
        Returns:
        The requested resource as String, resolved using Class.getResourceAsStream(String), or null if the requested resource cannot be resolved for some reason
        Throws:
        java.io.IOException - if the Resource Stream cannot be read