Class DefaultTempFileCreationStrategy

  • All Implemented Interfaces:
    TempFileCreationStrategy
    Direct Known Subclasses:
    UserNameAwareTempFileCreationStrategy

    public class DefaultTempFileCreationStrategy
    extends java.lang.Object
    implements TempFileCreationStrategy
    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 
      Modifier and Type Field Description
      static java.lang.String DELETE_FILES_ON_EXIT
      To use files.deleteOnExit after clean JVM exit, set the -Dpoi.delete.tmp.files.on.exit JVM property
      static java.lang.String POIFILES
      Name of POI files directory in temporary directory.
    • Method Summary

      All Methods Instance Methods Concrete 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.
      protected java.lang.String getJavaIoTmpDir()  
      protected java.nio.file.Path getPOIFilesDirectoryPath()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • POIFILES

        public static final java.lang.String POIFILES
        Name of POI files directory in temporary directory.
        See Also:
        Constant Field Values
      • DELETE_FILES_ON_EXIT

        public static final java.lang.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​(java.io.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 java.io.File createTempFile​(java.lang.String prefix,
                                           java.lang.String suffix)
                                    throws java.io.IOException
        Description copied from interface: TempFileCreationStrategy
        Creates a new and empty temporary file.
        Specified by:
        createTempFile in interface TempFileCreationStrategy
        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

        public java.io.File createTempDirectory​(java.lang.String prefix)
                                         throws java.io.IOException
        Description copied from interface: TempFileCreationStrategy
        Creates a new and empty temporary directory.
        Specified by:
        createTempDirectory in interface TempFileCreationStrategy
        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.
      • getJavaIoTmpDir

        protected java.lang.String getJavaIoTmpDir()
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getPOIFilesDirectoryPath

        protected java.nio.file.Path getPOIFilesDirectoryPath()
                                                       throws java.io.IOException
        Throws:
        java.io.IOException