Package org.apache.poi.util
Class DefaultTempFileCreationStrategy
- java.lang.Object
-
- org.apache.poi.util.DefaultTempFileCreationStrategy
-
- All Implemented Interfaces:
TempFileCreationStrategy
public class DefaultTempFileCreationStrategy extends Object implements TempFileCreationStrategy
Default implementation of theTempFileCreationStrategy
used byTempFile
: Files are collected into one directory and by default are deleted on exit from the VM. Files may be manually deleted by user prior to JVM exit. Files can be kept by defining the system propertyDELETE_FILES_ON_EXIT
. Each file is registered for deletion with the JVM and the temporary directory is not deleted after the JVM exits. Files that are created in the poifiles directory outside the control of DefaultTempFileCreationStrategy are not deleted. SeeTempFileCreationStrategy
for better strategies for long-running processes or limited temporary storage.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DELETE_FILES_ON_EXIT
To use files.deleteOnExit after clean JVM exit, set the-Dpoi.delete.tmp.files.on.exit
JVM propertystatic String
POIFILES
Name of POI files directory in temporary directory.
-
Constructor Summary
Constructors Constructor Description DefaultTempFileCreationStrategy()
Creates the strategy so that it creates the temporary files in the default directory.DefaultTempFileCreationStrategy(File dir)
Creates the strategy allowing to set the
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
createTempDirectory(String prefix)
Creates a new and empty temporary directory.File
createTempFile(String prefix, String suffix)
Creates a new and empty temporary file.
-
-
-
Field Detail
-
POIFILES
public static final String POIFILES
Name of POI files directory in temporary directory.- See Also:
- Constant Field Values
-
DELETE_FILES_ON_EXIT
public static final String DELETE_FILES_ON_EXIT
To use files.deleteOnExit after clean JVM exit, set the-Dpoi.delete.tmp.files.on.exit
JVM property- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultTempFileCreationStrategy
public DefaultTempFileCreationStrategy()
Creates the strategy so that it creates the temporary files in the default directory.- See Also:
File.createTempFile(String, String)
-
DefaultTempFileCreationStrategy
public DefaultTempFileCreationStrategy(File dir)
Creates the strategy allowing to set the- Parameters:
dir
- The directory where the temporary files will be created (null
to use the default directory).- See Also:
Files.createTempFile(Path, String, String, FileAttribute[])
-
-
Method Detail
-
createTempFile
public File createTempFile(String prefix, String suffix) throws IOException
Description copied from interface:TempFileCreationStrategy
Creates a new and empty temporary file.- Specified by:
createTempFile
in interfaceTempFileCreationStrategy
- Parameters:
prefix
- The prefix to be used to generate the name of the temporary file.suffix
- The suffix to be used to generate the name of the temporary file.- Returns:
- The path to the newly created and empty temporary file.
- Throws:
IOException
- If no temporary file could be created.
-
createTempDirectory
public File createTempDirectory(String prefix) throws IOException
Description copied from interface:TempFileCreationStrategy
Creates a new and empty temporary directory.- Specified by:
createTempDirectory
in interfaceTempFileCreationStrategy
- Parameters:
prefix
- The directory name to be used to generate the name of the temporary directory.- Returns:
- The path to the newly created and empty temporary directory.
- Throws:
IOException
- If no temporary directory could be created.
-
-