Class TempFileManager
- java.lang.Object
-
- org.apache.maven.surefire.api.util.TempFileManager
-
public final class TempFileManager extends java.lang.ObjectManagement of temporary files in surefire with support for sub directories of the system's directory of temporary files.
TheFile.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 asFile.createTempFile(String, String)andFile.deleteOnExit(), and can be used as a drop-in replacement.- Author:
- Markus Spann
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FilecreateTempFile(java.lang.String prefix)java.io.FilecreateTempFile(java.lang.String prefix, java.lang.String suffix)Creates a new, uniquely-named temporary file in this object'stempDirwith user-defined prefix and suffix (both may be null or empty and won't be trimmed).voiddeleteAll()static java.lang.StringgetJavaIoTmpDir()Returns the value of system propertyjava.io.tmpdir, the system's temp directory.java.io.FilegetTempDir()Returns the temporary directory or sub-directory under which temporary files are created.static TempFileManagerinstance()static TempFileManagerinstance(java.io.File tempDir)static TempFileManagerinstance(java.lang.String subDirName)Creates an instance using a subdirectory of the system's temporary directory.booleanisDeleteOnExit()voidsetDeleteOnExit(boolean deleteOnExit)Instructs this file manager to delete its temporary files during JVM shutdown.
This status can be turned on and off unlikeFile.deleteOnExit().java.lang.StringtoString()
-
-
-
Method Detail
-
instance
public static TempFileManager instance()
-
instance
public static TempFileManager instance(java.lang.String subDirName)
Creates an instance using a subdirectory of the system's temporary directory.- Parameters:
subDirName- name of subdirectory- Returns:
- instance
-
instance
public static TempFileManager instance(java.io.File tempDir)
-
deleteAll
public void deleteAll()
-
getTempDir
public java.io.File getTempDir()
Returns the temporary directory or sub-directory under which temporary files are created.- Returns:
- temporary directory
-
createTempFile
public java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)Creates a new, uniquely-named temporary file in this object'stempDirwith 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 issynchronizedto help ensure uniqueness of temporary files.- Parameters:
prefix- optional file name prefixsuffix- optional file name suffix- Returns:
- file object
-
createTempFile
public java.io.File createTempFile(java.lang.String prefix)
-
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getJavaIoTmpDir
public static java.lang.String getJavaIoTmpDir()
Returns the value of system propertyjava.io.tmpdir, the system's temp directory.- Returns:
- path to system temp directory
-
-