java.lang.Object
org.verapdf.io.TempFileHandler
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 Summary
Modifier and TypeMethodDescriptionstatic voidRemoves the per-thread temporary-file directory, falling back to the process-wide default.static FilecreateTempFile(String prefix, String suffix) Creates a temporary file, honouring the configured directory.static Filestatic Filestatic voidsetDefaultTempDirectory(File directory) Sets the process-wide default directory for parser temporary files.static voidsetTempDirectory(File directory) Sets the temporary-file directory for the current thread only.
-
Method Details
-
setDefaultTempDirectory
Sets the process-wide default directory for parser temporary files.nullrestores the JVM default (java.io.tmpdir).- Parameters:
directory- target directory, ornullfor the JVM default
-
getDefaultTempDirectory
- Returns:
- the process-wide default directory, or
nullif none is configured
-
setTempDirectory
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, ornullto 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
- 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
Creates a temporary file, honouring the configured directory. Equivalent toFile.createTempFile(String, String)when no directory is configured.- Parameters:
prefix- file-name prefix, as forFile.createTempFile(String, String, File)suffix- file-name suffix, ornull- Returns:
- the newly created temporary file
- Throws:
IOException- if the file could not be created
-