public final class

JarResourceExtractor

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.JarResourceExtractor

Summary

Public Constructors
JarResourceExtractor()
Public Methods
static Path createTempDirWithPrefix(String prefix)
Creates a temporary directory using the specified prefix.
static void extractJarResources(Path jarPath, Path destinationDir)
Extracts resources from a JAR file to a specified directory using a reference to the JAR's Path.
static Path extractJarResourcesByClassName(String markerClassName)
Extracts resources from a JAR file to a newly created temporary directory using the package name of a marker class within the JAR.
static Path resolveJarPathFromClass(Class<?> markerClass)
Returns the Path to the JAR file from which the given class was loaded.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public JarResourceExtractor ()

Public Methods

public static Path createTempDirWithPrefix (String prefix)

Creates a temporary directory using the specified prefix. If the system property 'com.pdftron.systemloadtmpdir' is set, the directory will be created there; otherwise, it defaults to the system temp directory.

Important: The caller is responsible for deleting this directory and its contents when it is no longer needed to avoid resource leaks and clutter in the filesystem. This method does not perform any automatic cleanup.

Parameters
prefix the prefix string to be used in generating the directory's name; must not be null or empty
Returns
  • the Path to the created temporary directory
Throws
IOException if the directory could not be created
IllegalArgumentException if prefix is empty
NullPointerException if prefix is null

public static void extractJarResources (Path jarPath, Path destinationDir)

Extracts resources from a JAR file to a specified directory using a reference to the JAR's Path.

Parameters
jarPath the path to the JAR file to extract
destinationDir the directory to extract the contents of the JAR file into
Throws
IOException if an I/O error occurs or a zip-slip attempt is detected
IllegalArgumentException if the jarPath is invalid (not a file, doesn't exist, or doesn't end with .jar)

public static Path extractJarResourcesByClassName (String markerClassName)

Extracts resources from a JAR file to a newly created temporary directory using the package name of a marker class within the JAR.

The method attempts to locate the JAR file from which the specified marker class was loaded, creates a temporary directory with a prefix based on the marker class's package name, and extracts all resources from the JAR (except directories and META-INF entries) into this directory.

All files and directories extracted into the temporary directory are registered for automatic deletion on JVM exit using deleteOnExit().

Note: While this helps clean up resources, it only guarantees deletion when the JVM shuts down normally. If the JVM is abruptly terminated, the files may remain on disk.

The caller does not need to explicitly delete the temporary directory, but should be aware that the directory may persist during the JVM's lifetime.

Parameters
markerClassName the fully-qualified name of a class inside the JAR to be extracted; must not be null or empty
Returns
  • the Path to the temporary directory where resources were extracted if successful; null if extraction failed for any reason (e.g., class not found, class not loaded from a JAR, I/O errors)
Throws
NullPointerException if markerClassName is null
IllegalArgumentException if markerClassName is empty

public static Path resolveJarPathFromClass (Class<?> markerClass)

Returns the Path to the JAR file from which the given class was loaded. Returns null if the class was not loaded from a JAR.

Parameters
markerClass a class inside the JAR you want to resolve.
Returns
  • the JAR Path, or null if not found