Class ThreadSafeUnzipper

java.lang.Object
org.apache.tika.plugins.ThreadSafeUnzipper

public class ThreadSafeUnzipper extends Object
Thread-safe and process-safe plugin unzipper using atomic rename.

This avoids file locking issues on Windows by using a simple strategy:

  1. Check if destination directory exists with completion marker - if yes, already extracted
  2. Extract to a temporary directory with a unique name
  3. Create a completion marker file in the temp directory
  4. Atomically rename temp dir to final destination
  5. If rename fails (another process won), clean up temp dir

The completion marker ensures that even if atomic move is not supported, other processes won't attempt to load a partially-moved directory.

  • Constructor Details

    • ThreadSafeUnzipper

      public ThreadSafeUnzipper()
  • Method Details

    • unzipPlugin

      public static void unzipPlugin(Path source) throws IOException
      Unzips a plugin zip file to a directory with the same name (minus .zip extension). Safe for concurrent calls from multiple threads or processes. See documentation at the head of this class for how it works.
      Parameters:
      source - path to the .zip file
      Throws:
      IOException - if extraction fails