Package org.apache.poi.util
Class DefaultTempFileCreationStrategy
- java.lang.Object
-
- org.apache.poi.util.DefaultTempFileCreationStrategy
-
- All Implemented Interfaces:
TempFileCreationStrategy
- Direct Known Subclasses:
UserNameAwareTempFileCreationStrategy
public class DefaultTempFileCreationStrategy extends Object implements TempFileCreationStrategy
Default implementation of theTempFileCreationStrategyused byTempFile: Files are collected into one directory. Files may be manually deleted by user prior to JVM exit. You can define the system propertyDELETE_FILES_ON_EXITif 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. SeeTempFileCreationStrategyfor better strategies for long-running processes or limited temporary storage.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDELETE_FILES_ON_EXITTo use files.deleteOnExit after clean JVM exit, set the-Dpoi.delete.tmp.files.on.exitJVM propertystatic StringPOIFILESName 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 a custom directory for the temporary files.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FilecreateTempDirectory(String prefix)Creates a new and empty temporary directory.FilecreateTempFile(String prefix, String suffix)Creates a new and empty temporary file.protected StringgetJavaIoTmpDir()protected PathgetPOIFilesDirectoryPath()
-
-
-
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.exitJVM 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 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:
Files.createTempFile(Path, String, String, FileAttribute[])
-
-
Method Detail
-
createTempFile
public File createTempFile(String prefix, String suffix) throws IOException
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
public File createTempDirectory(String prefix) throws IOException
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
protected String getJavaIoTmpDir() throws IOException
- Throws:
IOException
-
getPOIFilesDirectoryPath
protected Path getPOIFilesDirectoryPath() throws IOException
- Throws:
IOException
-
-