Class CachingJavaSourceClassLoader

    • Constructor Detail

      • CachingJavaSourceClassLoader

        public CachingJavaSourceClassLoader​(java.lang.ClassLoader parentClassLoader,
                                            ResourceFinder sourceFinder,
                                            @Nullable
                                            java.lang.String characterEncoding,
                                            ResourceFinder classFileCacheResourceFinder,
                                            ResourceCreator classFileCacheResourceCreator)
        Notice that this class is thread-safe if and only if the classFileCacheResourceCreator stores its data atomically, i.e. the classFileCacheResourceFinder sees the resource written by the classFileCacheResourceCreator only after the OutputStream is closed.

        In order to make the caching scheme work, both the classFileCacheResourceFinder and the sourceFinder must support the Resource.lastModified() method, so that the modification time of the source and the class files can be compared.

        Parameters:
        parentClassLoader - Attempt to load classes through this one before looking for source files
        sourceFinder - Finds Java source for class pkg.Cls in resource pkg/Cls.java
        characterEncoding - Encoding of Java source or null for platform default encoding
        classFileCacheResourceFinder - Finds precompiled class pkg.Cls in resource pkg/Cls.class (see class description)
        classFileCacheResourceCreator - Stores compiled class pkg.Cls in resource pkg/Cls.class (see class description)
    • Method Detail

      • generateBytecodes

        @Nullable
        protected java.util.Map<java.lang.String,​byte[]> generateBytecodes​(java.lang.String className)
                                                                          throws java.lang.ClassNotFoundException
        Overrides JavaSourceClassLoader.generateBytecodes(String) to implement class file caching.
        Overrides:
        generateBytecodes in class JavaSourceClassLoader
        Returns:
        String name => byte[] bytecode, or null if no source code could be found
        Throws:
        java.lang.ClassNotFoundException - Compilation problems or class file cache I/O problems