Class ShrinkWrapClassLoader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ShrinkWrapClassLoader
    extends java.net.URLClassLoader
    implements java.io.Closeable
    Extension that will create a ClassLoader based on a Array of Archives. When done, call close() to free resources.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String EMPTY
      Empty String
      private static java.util.logging.Logger log
      Logger
      private java.util.List<java.io.InputStream> openedStreams
      List of all streams opened, such that they may be closed in close().
    • Constructor Summary

      Constructors 
      Constructor Description
      ShrinkWrapClassLoader​(java.lang.ClassLoader parent, Archive<?>... archives)
      Constructs a new ShrinkWrapClassLoader for the given Archives.
      ShrinkWrapClassLoader​(Archive<?>... archives)
      Constructs a new ShrinkWrapClassLoader for the specified Archives using the default delegation parent ClassLoader.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addArchive​(Archive<?> archive)  
      private void addArchives​(Archive<?>[] archives)  
      void close()  
      • Methods inherited from class java.net.URLClassLoader

        addURL, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
      • Methods inherited from class java.security.SecureClassLoader

        defineClass, defineClass
      • Methods inherited from class java.lang.ClassLoader

        clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
      • Methods inherited from class java.lang.Object

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

      • log

        private static final java.util.logging.Logger log
        Logger
      • openedStreams

        private final java.util.List<java.io.InputStream> openedStreams
        List of all streams opened, such that they may be closed in close(). Guarded by "this".
    • Constructor Detail

      • ShrinkWrapClassLoader

        public ShrinkWrapClassLoader​(Archive<?>... archives)
        Constructs a new ShrinkWrapClassLoader for the specified Archives using the default delegation parent ClassLoader. The Archives will be searched in the order specified for classes and resources after first searching in the parent class loader.
        Parameters:
        archives - the Archives from which to load classes and resources
      • ShrinkWrapClassLoader

        public ShrinkWrapClassLoader​(java.lang.ClassLoader parent,
                                     Archive<?>... archives)
        Constructs a new ShrinkWrapClassLoader for the given Archives. The Archives will be searched in the order specified for classes and resources after first searching in the specified parent class loader.
        Parameters:
        parent - the parent class loader for delegation
        archives - the Archives from which to load classes and resources
    • Method Detail

      • addArchives

        private void addArchives​(Archive<?>[] archives)
      • addArchive

        private void addArchive​(Archive<?> archive)
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.net.URLClassLoader
        Throws:
        java.io.IOException