Class ClassAsset

  • All Implemented Interfaces:
    Asset

    public class ClassAsset
    extends java.lang.Object
    implements Asset
    ClassAsset Implementation of a Asset backed by a loaded Class
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<?> clazz  
      private static char DELIMITER_CLASS_NAME_PATH
      Delimiter for paths in fully-qualified class names
      private static char DELIMITER_RESOURCE_PATH
      Delimiter for paths while looking for resources
      private static java.lang.String EXTENSION_CLASS
      The filename extension appended to classes
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassAsset​(java.lang.Class<?> clazz)
      Load any class as a resource.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String getResourceNameOfClass​(java.lang.Class<?> clazz)
      Returns the name of the class such that it may be accessed via ClassLoader.getResource()
      java.lang.Class<?> getSource()
      Returns the loaded class.
      java.io.InputStream openStream()
      Converts the Class name into a Resource URL and uses the ClassloaderResource for loading the Class.
      • Methods inherited from class java.lang.Object

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

      • DELIMITER_RESOURCE_PATH

        private static final char DELIMITER_RESOURCE_PATH
        Delimiter for paths while looking for resources
        See Also:
        Constant Field Values
      • DELIMITER_CLASS_NAME_PATH

        private static final char DELIMITER_CLASS_NAME_PATH
        Delimiter for paths in fully-qualified class names
        See Also:
        Constant Field Values
      • EXTENSION_CLASS

        private static final java.lang.String EXTENSION_CLASS
        The filename extension appended to classes
        See Also:
        Constant Field Values
      • clazz

        private java.lang.Class<?> clazz
    • Constructor Detail

      • ClassAsset

        public ClassAsset​(java.lang.Class<?> clazz)
        Load any class as a resource.
        Parameters:
        clazz - The class to load
        Throws:
        java.lang.IllegalArgumentException - Class can not be null
    • Method Detail

      • openStream

        public java.io.InputStream openStream()
        Converts the Class name into a Resource URL and uses the ClassloaderResource for loading the Class.
        Specified by:
        openStream in interface Asset
        Returns:
        A new open InputStream for each call
      • getSource

        public java.lang.Class<?> getSource()
        Returns the loaded class.
      • getResourceNameOfClass

        private java.lang.String getResourceNameOfClass​(java.lang.Class<?> clazz)
                                                 throws java.lang.IllegalArgumentException
        Returns the name of the class such that it may be accessed via ClassLoader.getResource()
        Parameters:
        clazz - The class
        Throws:
        java.lang.IllegalArgumentException - If the class was not specified