Package org.apache.poi.util
Class DefaultTempFileCreationStrategy
java.lang.Object
org.apache.poi.util.DefaultTempFileCreationStrategy
- All Implemented Interfaces:
TempFileCreationStrategy
- Direct Known Subclasses:
UserNameAwareTempFileCreationStrategy
Default implementation of the
TempFileCreationStrategy used by TempFile:
Files are collected into one directory.
Files may be manually deleted by user prior to JVM exit.
You can define the system property DELETE_FILES_ON_EXIT if you want to
delete any stray files on clean JVM exit (any non-empty value means add the deleteOnExit flag).
The POI code should tidy up temp files when it no longer needs them.
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.
See TempFileCreationStrategy for better strategies for long-running
processes or limited temporary storage.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates the strategy so that it creates the temporary files in the default directory.Creates the strategy allowing to set a custom directory for the temporary files. -
Method Summary
Modifier and TypeMethodDescriptioncreateTempDirectory(String prefix) Creates a new and empty temporary directory.createTempFile(String prefix, String suffix) Creates a new and empty temporary file.protected Stringprotected Path
-
Field Details
-
POIFILES
Name of POI files directory in temporary directory.- See Also:
-
DELETE_FILES_ON_EXIT
To use files.deleteOnExit after clean JVM exit, set the-Dpoi.delete.tmp.files.on.exitJVM property- See Also:
-
-
Constructor Details
-
DefaultTempFileCreationStrategy
public DefaultTempFileCreationStrategy()Creates the strategy so that it creates the temporary files in the default directory.- See Also:
-
DefaultTempFileCreationStrategy
Creates the strategy allowing to set a custom directory for the temporary files.If you provide a non-null dir as input, it must be a directory (if it already exists). Since POI 5.5.0, this is checked at construction time. In previous versions, it was checked at the first call to
createTempFile(String, String)orcreateTempDirectory(String).- Parameters:
dir- The directory where the temporary files will be created (nullto use the default directory).- Throws:
IllegalArgumentException- if the provided directory does not exist or is not a directory- See Also:
-
-
Method Details
-
createTempFile
Description copied from interface:TempFileCreationStrategyCreates a new and empty temporary file.- Specified by:
createTempFilein 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
Description copied from interface:TempFileCreationStrategyCreates a new and empty temporary directory.- Specified by:
createTempDirectoryin 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.
-
getJavaIoTmpDir
- Throws:
IOException
-
getPOIFilesDirectoryPath
- Throws:
IOException
-