Class ClassFileLoader


  • public class ClassFileLoader
    extends java.lang.Object
    Cache and manager for the loaded ClassFiles
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader bootLoader  
      private java.util.HashMap<java.lang.String,​ClassFile> cache  
      private java.lang.ClassLoader loader  
      private java.util.HashMap<java.lang.String,​ClassFile> replace  
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassFileLoader​(java.lang.ClassLoader loader)
      Create a new instance
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cache​(ClassFile classFile)
      Add a class file to the weak cache.
      ClassFile get​(java.lang.String className)
      Get the ClassFile from cache or load it.
      (package private) void partial​(java.lang.String className, ClassFile partialClassFile)
      Add a partial class with the given instance to the loader cache.
      (package private) void replace​(java.lang.String className, ClassFile classFile)
      Replace the class in the cache with the given instance to the loader cache.
      • Methods inherited from class java.lang.Object

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

      • replace

        private final java.util.HashMap<java.lang.String,​ClassFile> replace
      • cache

        private final java.util.HashMap<java.lang.String,​ClassFile> cache
      • loader

        private final java.lang.ClassLoader loader
      • bootLoader

        private final java.lang.ClassLoader bootLoader
    • Constructor Detail

      • ClassFileLoader

        public ClassFileLoader​(java.lang.ClassLoader loader)
        Create a new instance
        Parameters:
        loader - the classloader to find the *.class files
    • Method Detail

      • get

        @Nullable
        public ClassFile get​(java.lang.String className)
                      throws java.io.IOException
        Get the ClassFile from cache or load it.
        Parameters:
        className - the class name like "java/lang/Object"
        Returns:
        the ClassFile or null
        Throws:
        java.io.IOException - If any I/O error occur
      • cache

        public void cache​(@Nonnull
                          ClassFile classFile)
        Add a class file to the weak cache.
        Parameters:
        classFile - the class file
      • replace

        void replace​(java.lang.String className,
                     ClassFile classFile)
        Replace the class in the cache with the given instance to the loader cache.
        Parameters:
        className - the name of the class to replace
        classFile - the replacing ClassFile
      • partial

        void partial​(java.lang.String className,
                     ClassFile partialClassFile)
              throws java.io.IOException
        Add a partial class with the given instance to the loader cache.
        Parameters:
        className - the name of the class to replace like "java/lang/String"
        partialClassFile - the partial ClassFile
        Throws:
        java.io.IOException - If any I/O error occur