Class TempFileManager
java.lang.Object
org.apache.maven.surefire.api.util.TempFileManager
Management of temporary files in surefire with support for sub directories of the system's directory
of temporary files.
The
This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix. It also helps you organize temporary files into sub-directories, and thus avoid bloating the temp directory root.
Apart from that, this class works in much the same way as
The
File.createTempFile(String, String)
API creates rather meaningless file names and
only in the system's temp directory.This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix. It also helps you organize temporary files into sub-directories, and thus avoid bloating the temp directory root.
Apart from that, this class works in much the same way as
File.createTempFile(String, String)
and File.deleteOnExit()
, and can be used as a drop-in replacement.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
The fixed base name used between prefix and suffix of temporary files created by this class.private boolean
Temporary files are delete on JVM exit if true.private static final AtomicInteger
An id unique across all file managers used as part of the temporary file's base name.private static final Map<File,
TempFileManager> private static Thread
private static final String
private final File
The temporary directory or sub-directory under which temporary files are created.List of successfully created temporary files. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static File
calcTempDir
(String subDirName) createTempFile
(String prefix) createTempFile
(String prefix, String suffix) Creates a new, uniquely-named temporary file in this object'stempDir
with user-defined prefix and suffix (both may be null or empty and won't be trimmed).void
static String
Returns the value of system propertyjava.io.tmpdir
, the system's temp directory.Returns the temporary directory or sub-directory under which temporary files are created.static TempFileManager
instance()
static TempFileManager
static TempFileManager
Creates an instance using a subdirectory of the system's temporary directory.boolean
void
setDeleteOnExit
(boolean deleteOnExit) Instructs this file manager to delete its temporary files during JVM shutdown.
This status can be turned on and off unlikeFile.deleteOnExit()
.(package private) static void
toString()
-
Field Details
-
INSTANCES
-
FILE_ID
An id unique across all file managers used as part of the temporary file's base name. -
SUFFIX_TMP
- See Also:
-
shutdownHook
-
tempDir
The temporary directory or sub-directory under which temporary files are created. -
baseName
The fixed base name used between prefix and suffix of temporary files created by this class. -
tempFiles
List of successfully created temporary files. -
deleteOnExit
private boolean deleteOnExitTemporary files are delete on JVM exit if true.
-
-
Constructor Details
-
TempFileManager
-
-
Method Details
-
calcTempDir
-
instance
-
instance
Creates an instance using a subdirectory of the system's temporary directory.- Parameters:
subDirName
- name of subdirectory- Returns:
- instance
-
instance
-
deleteAll
public void deleteAll() -
shutdownAll
static void shutdownAll() -
getTempDir
Returns the temporary directory or sub-directory under which temporary files are created.- Returns:
- temporary directory
-
createTempFile
Creates a new, uniquely-named temporary file in this object'stempDir
with user-defined prefix and suffix (both may be null or empty and won't be trimmed).This method behaves similarly to
File.createTempFile(String, String)
and may be used as a drop-in replacement.
This method issynchronized
to help ensure uniqueness of temporary files.- Parameters:
prefix
- optional file name prefixsuffix
- optional file name suffix- Returns:
- file object
-
createTempFile
-
isDeleteOnExit
public boolean isDeleteOnExit() -
setDeleteOnExit
public void setDeleteOnExit(boolean deleteOnExit) Instructs this file manager to delete its temporary files during JVM shutdown.
This status can be turned on and off unlikeFile.deleteOnExit()
.- Parameters:
deleteOnExit
- delete the file in a shutdown hook on JVM exit
-
toString
-
getJavaIoTmpDir
Returns the value of system propertyjava.io.tmpdir
, the system's temp directory.- Returns:
- path to system temp directory
-