Class JarLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
org.apache.derby.impl.services.reflect.JarLoader

final class JarLoader extends SecureClassLoader
  • Field Details

    • name

      private final String[] name
      Two part name for the jar file.
    • installedJar

      private StorageFile installedJar
      Handle to the installed jar file.
    • jar

      private JarFile jar
      When the jar file can be manipulated as a java.util.JarFile this holds the reference to the open jar. When the jar can only be manipulated as an InputStream (because the jar is itself in a database jar) then this will be null.
    • isStream

      private boolean isStream
      True if the jar can only be accessed using a stream, because the jar is itself in a database jar. When fals the jar is accessed using the jar field.
    • updateLoader

      private UpdateLoader updateLoader
    • vs

      private HeaderPrintWriter vs
  • Constructor Details

  • Method Details

    • initialize

      void initialize()
      Initialize the class loader so it knows if it is loading from a ZipFile or an InputStream
    • loadClass

      protected Class loadClass(String className, boolean resolve) throws ClassNotFoundException
      Handle all requests to the top-level loader.
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException - Class can not be found
    • getResourceAsStream

      public InputStream getResourceAsStream(String name)
      Overrides:
      getResourceAsStream in class ClassLoader
    • getJarName

      final String getJarName()
      Return the SQL name for the installed jar. Used for error and informational messages.
    • loadClassData

      Class loadClassData(String className, String jvmClassName, boolean resolve)
    • getStream

      InputStream getStream(String name)
      Get an InputStream for the given resource.
    • loadClassDataFromJar

      private Class loadClassDataFromJar(String className, String jvmClassName, boolean resolve) throws IOException
      Load the class data when the installed jar is accessible as a java.util.jarFile.
      Throws:
      IOException
    • loadClassData

      private Class loadClassData(InputStream in, String className, String jvmClassName, boolean resolve) throws IOException
      Load the class data when the installed jar is accessible only as an input stream (the jar is itself in a database jar).
      Throws:
      IOException
    • loadClassData

      private Class loadClassData(JarEntry e, InputStream in, String className, boolean resolve) throws IOException
      Load and optionally resolve the class given its JarEntry and an InputStream to the class fiel format. This is common code for when the jar is accessed directly using JarFile or through InputStream.
      Throws:
      IOException
    • checkLoaded

      Class checkLoaded(String className, boolean resolve)
    • setInvalid

      void setInvalid()
      Set this loader to be invaid so that it will not resolve any classes or resources.
    • getRawStream

      private InputStream getRawStream(String name)
      Get a stream for a resource directly from a JarFile. In this case we can safely return the stream directly. It's a new stream set up by the zip code to read just the contents of this entry.
    • getRawStream

      private InputStream getRawStream(InputStream in, String name)
      Get a stream from a zip file that is itself a stream. We copy to the contents to a byte array and return a stream around that to the caller. Though a copy is involved it has the benefit of:
      • Isolating the application from the JarInputStream, thus denying any possibility of the application reading more of the jar that it should be allowed to. E.g. the contents class files are not exposed through getResource.
      • Avoids any possibility of the application holding onto the open stream beyond shutdown of the database, thus leading to leaked file descriptors or inability to remove the jar.
    • readData

      byte[] readData(JarEntry ze, InputStream in, String className) throws IOException
      Read the raw data for the class file format into a byte array that can be used for loading the class. If this is a signed class and it has been compromised then a SecurityException will be thrown.
      Throws:
      IOException
    • getSigners

      private Certificate[] getSigners(String className, JarEntry je) throws IOException
      Validate the security certificates (signers) for the class data.
      Throws:
      IOException
    • handleException

      private SecurityException handleException(Exception e, String className)
      Provide a SecurityManager with information about the class name and the jar file.
    • toString

      public String toString()
      Return the jar name if toString() is called on this class loader.
      Overrides:
      toString in class Object