Class ResourceUtil


  • public class ResourceUtil
    extends java.lang.Object
    ResourceUtil is a utility class for retrieving resources (images, property-files, etc) from the classpath.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ResourceUtil.CallerResolver
      A helper class to get the call context.
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.Class<?> getCaller()
      Retrieve the calling class of a method in this class.
      static java.io.InputStream getInputStream​(java.lang.String resourceName)
      Get an inputstream on the specified resource.
      static java.util.Properties getProperties​(java.lang.String resourceName)
      Retrieve a properties resource.
      static java.lang.String getString​(java.lang.String resourceName)
      Retrieve the String contents of the specified resource, obtained by opening in inputstream on the resource and then interpreting the bytes contained in the inputstream as if they represented characters.
      static java.net.URL getURL​(java.lang.String resourceName)
      The URL to the specified resource
      • 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

      • getURL

        public static java.net.URL getURL​(java.lang.String resourceName)
        The URL to the specified resource
        Parameters:
        resourceName - the name of the resource
        Returns:
        the URL to the specified resource, or null if the resource could not be found
      • getInputStream

        public static java.io.InputStream getInputStream​(java.lang.String resourceName)
        Get an inputstream on the specified resource.
        Parameters:
        resourceName - the name of the resource
        Returns:
        an inputstream on the specified resource, or null if the resource could not be found
      • getString

        public static java.lang.String getString​(java.lang.String resourceName)
                                          throws java.io.IOException
        Retrieve the String contents of the specified resource, obtained by opening in inputstream on the resource and then interpreting the bytes contained in the inputstream as if they represented characters. This may not make sense on all resources. There is no "magic" in this method to read anything other than plain text.
        Parameters:
        resourceName - the name of the resource
        Returns:
        the String contents of the specified resource, or null if the specified resource could not be found
        Throws:
        java.io.IOException - when something goes wrong trying to read the resource
      • getProperties

        public static java.util.Properties getProperties​(java.lang.String resourceName)
                                                  throws java.io.IOException
        Retrieve a properties resource.
        Parameters:
        resourceName - the name of the resource
        Returns:
        a Properties object representing the contents of the resource, or null if the specified resource could not be found
        Throws:
        java.io.IOException
      • getCaller

        private static java.lang.Class<?> getCaller()
        Retrieve the calling class of a method in this class.
        Returns:
        the calling class of a method in this class, or this class if no other class could be determined.