Class ClassFileLocator.ForJarFile

    • Field Detail

      • RUNTIME_LOCATIONS

        private static final java.util.List<java.lang.String> RUNTIME_LOCATIONS
        A list of potential locations of the runtime jar for different platforms.
      • jarFile

        private final java.util.jar.JarFile jarFile
        The jar file to read from.
      • close

        @ValueHandling(IGNORE)
        private final boolean close
        Indicates if the jar file should be closed upon closing this class file locator.
    • Constructor Detail

      • ForJarFile

        public ForJarFile​(java.util.jar.JarFile jarFile)
        Creates a new class file locator for the given jar file. The jar file will not be closed upon closing this class file locator.
        Parameters:
        jarFile - The jar file to read from.
      • ForJarFile

        protected ForJarFile​(int[] version,
                             java.util.jar.JarFile jarFile,
                             boolean close)
        Creates a new class file locator for the given jar file.
        Parameters:
        version - Contains the existing multi-release jar folders that are available for the current JVM version in decreasing order.
        jarFile - The jar file to read from.
        close - Indicates if the jar file should be closed upon closing this class file locator.
    • Method Detail

      • of

        public static ClassFileLocator of​(java.io.File file)
                                   throws java.io.IOException
        Creates a new class file locator for the given jar file. Multi-release jars are not considered.
        Parameters:
        file - The jar file to read from.
        Returns:
        A class file locator for the jar file.
        Throws:
        java.io.IOException - If an I/O exception is thrown.
      • of

        public static ClassFileLocator of​(java.io.File file,
                                          ClassFileVersion classFileVersion)
                                   throws java.io.IOException
        Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version.
        Parameters:
        file - The jar file to read from.
        classFileVersion - The class file version to consider when resolving class files in multi-release jars.
        Returns:
        A class file locator for the jar file.
        Throws:
        java.io.IOException - If an I/O exception is thrown.
      • of

        public static ClassFileLocator of​(java.util.jar.JarFile jarFile,
                                          ClassFileVersion classFileVersion)
                                   throws java.io.IOException
        Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version. The jar file will not be closed upon closing this class file locator.
        Parameters:
        jarFile - The jar file to read from.
        classFileVersion - The class file version to consider when resolving class files in multi-release jars.
        Returns:
        A class file locator for the jar file.
        Throws:
        java.io.IOException - If an I/O exception is thrown.
      • of

        private static ClassFileLocator of​(java.util.jar.JarFile jarFile,
                                           ClassFileVersion classFileVersion,
                                           boolean close)
                                    throws java.io.IOException
        Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version.
        Parameters:
        jarFile - The jar file to read from.
        classFileVersion - The class file version to consider when resolving class files in multi-release jars.
        close - Indicates if the jar file should be closed upon closing this class file locator.
        Returns:
        A class file locator for the jar file.
        Throws:
        java.io.IOException - If an I/O exception is thrown.
      • ofClassPath

        public static ClassFileLocator ofClassPath()
                                            throws java.io.IOException
        Resolves a class file locator for the class path that reads class files directly from the file system. The resulting class file locator does not imply classes on the boot path.
        Returns:
        A class file locator for the class path.
        Throws:
        java.io.IOException - If an I/O exception occurs.
      • ofClassPath

        public static ClassFileLocator ofClassPath​(java.lang.String classPath)
                                            throws java.io.IOException

        Resolves a class file locator for the class path that reads class files directly from the file system.

        Note: The resulting class file locator does not include classes of the bootstrap class loader.

        Parameters:
        classPath - The class path to scan with the elements separated by path.separator.
        Returns:
        A class file locator for the class path.
        Throws:
        java.io.IOException - If an I/O exception occurs.
      • ofRuntimeJar

        public static ClassFileLocator ofRuntimeJar()
                                             throws java.io.IOException
        Resolves a class file locator for the runtime jar. If such a file does not exist or cannot be located, a runtime exception is thrown.
        Returns:
        A class file locator for the runtime jar, if available.
        Throws:
        java.io.IOException - If an I/O exception occurs.
      • doLocate

        @MaybeNull
        protected byte[] doLocate​(java.lang.String path)
                           throws java.io.IOException
        Resolves a possible multi-release entry, if it exists.
        Specified by:
        doLocate in class ClassFileLocator.MultiReleaseAware
        Parameters:
        path - The path of the class file.
        Returns:
        The class file's binary representation or null if it does not exist.
        Throws:
        java.io.IOException - If an I/O exception occurs.
      • close

        public void close()
                   throws java.io.IOException
        Throws:
        java.io.IOException