Class TempFileHandler

java.lang.Object
org.verapdf.io.TempFileHandler

public final class TempFileHandler extends Object
Central creation point for the temporary files that the parser writes while turning non-seekable input (embedded font programs, CMaps, decoded object streams, incremental-update output) into seekable data.

By default this behaves exactly like File.createTempFile(String, String) and writes into the JVM temporary directory (java.io.tmpdir). A caller that needs the temporary files in a specific directory - for example one directory per worker so files stay inside an isolated working area and can be removed deterministically - can configure a target directory. Two levels are offered: a process-wide default and a per-thread override that takes precedence. Both are optional; when neither is set the historical behaviour is preserved, so this change is backward compatible.

The per-thread override is the natural fit for a server that validates one document per worker thread: set it before parsing, clear it afterwards.

  • Method Details

    • setDefaultTempDirectory

      public static void setDefaultTempDirectory(File directory)
      Sets the process-wide default directory for parser temporary files. null restores the JVM default (java.io.tmpdir).
      Parameters:
      directory - target directory, or null for the JVM default
    • getDefaultTempDirectory

      public static File getDefaultTempDirectory()
      Returns:
      the process-wide default directory, or null if none is configured
    • setTempDirectory

      public static void setTempDirectory(File directory)
      Sets the temporary-file directory for the current thread only. It takes precedence over the process-wide default and should be cleared when the thread is done (clearTempDirectory()).
      Parameters:
      directory - target directory for this thread, or null to fall back to the default
    • clearTempDirectory

      public static void clearTempDirectory()
      Removes the per-thread temporary-file directory, falling back to the process-wide default.
    • getTempDirectory

      public static File getTempDirectory()
      Returns:
      the directory that will be used for new temporary files on the current thread: the per-thread override if set, otherwise the process-wide default, otherwise null (JVM default)
    • createTempFile

      public static File createTempFile(String prefix, String suffix) throws IOException
      Creates a temporary file, honouring the configured directory. Equivalent to File.createTempFile(String, String) when no directory is configured.
      Parameters:
      prefix - file-name prefix, as for File.createTempFile(String, String, File)
      suffix - file-name suffix, or null
      Returns:
      the newly created temporary file
      Throws:
      IOException - if the file could not be created