Class Resources


  • public class Resources
    extends java.lang.Object
    Author:
    Javier Paniza
    • Constructor Summary

      Constructors 
      Constructor Description
      Resources()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream getAsStreamInPrefixes​(java.lang.String resourceName, java.lang.String... prefixes)
      Load the resource as a stream from classpath, looking for all path prefixes until find it in one.
      static java.lang.String loadAsString​(java.lang.Class baseClass, java.lang.String resourceName)
      Load a resource from the classpath and return it in String format.
      static java.lang.String loadAsString​(java.lang.String fileName)
      Load a resource from the file system and return it in String format.
      • Methods inherited from class java.lang.Object

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

      • Resources

        public Resources()
    • Method Detail

      • loadAsString

        public static java.lang.String loadAsString​(java.lang.Class baseClass,
                                                    java.lang.String resourceName)
                                             throws java.io.IOException
        Load a resource from the classpath and return it in String format.

        Parameters:
        baseClass - Base class from start the search of resource.
        resourceName -
        Throws:
        java.io.IOException
      • loadAsString

        public static java.lang.String loadAsString​(java.lang.String fileName)
                                             throws java.io.IOException
        Load a resource from the file system and return it in String format.

        Throws:
        java.io.IOException
      • getAsStreamInPrefixes

        public static java.io.InputStream getAsStreamInPrefixes​(java.lang.String resourceName,
                                                                java.lang.String... prefixes)
        Load the resource as a stream from classpath, looking for all path prefixes until find it in one. For example, the next code:
        Resources.getAsStreamInPrefixes("Customer.jrxml", "/reports/", "/informes/", "/") Look for /reports/Customer.jrxml, if not found for /informes/Customer.jrmxl, if not found for /Customer.jrxml.
        Parameters:
        resourceName - The name of the resource in classpath, a file name.
        prefixes - A list of path prefixes, to look for each one.
        Returns:
        The stream to get resource content, or null if not found.
        Since:
        7.0