Package org.apache.poi.util
Interface TempFileCreationStrategy
-
- All Known Implementing Classes:
DefaultTempFileCreationStrategy
public interface TempFileCreationStrategy
Interface used by theTempFile
utility class to create temporary files. Classes that implement a TempFileCreationStrategy attempt to handle the cleanup of temporary files. Examples include:DefaultTempFileCreationStrategy
deletes temporary files when the JVM exits. This may not be suitable for long-running applications that never shut down the JVM since the list of registered files and disk space usage would grow for as long as the JVM is running. You may wish to implement your own strategy that meets the needs of your situation.- A strategy that keeps the
n
most-recent files, discarding older files on a first-in, first-out basis. A java.util.Deque or org.apache.commons.collections4.queue.CircularFifoQueue may be helpful for achieving this. - A strategy that keeps track of every temporary file that has been
created by the class or instance and provides a method to explicitly
delete the temporary files in the reverse order that they were created.
This is the same as DefaultTempFileCreationStrategy, except the strategy
class would maintain the list of files to delete rather than or in
addition to
DeleteOnExitHook
maintaining the list, and the files could be deleted before the JVM exit. - A strategy that creates a directory that is deleted on JVM exit.
Any files inside the directory do not need to be registered since the
entire directory will be deleted at exit.
This could be dangerous if files were added to the temporary directory
outside of this TempFileCreationStrategy's control.
This could be accomplished with
createTempDirectory(String)
and creating regular (unregistered) files in the temp directory.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.io.File
createTempDirectory(java.lang.String prefix)
Creates a new and empty temporary directory.java.io.File
createTempFile(java.lang.String prefix, java.lang.String suffix)
Creates a new and empty temporary file.
-
-
-
Method Detail
-
createTempFile
java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
Creates a new and empty temporary file.- 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:
java.io.IOException
- If no temporary file could be created.
-
createTempDirectory
java.io.File createTempDirectory(java.lang.String prefix) throws java.io.IOException
Creates a new and empty temporary directory.- 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:
java.io.IOException
- If no temporary directory could be created.- Since:
- POI 3.15 beta 3.
-
-