Package org.jboss.vfs

Class TempFileProvider

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class TempFileProvider
    extends java.lang.Object
    implements java.io.Closeable
    A provider for temporary physical files and directories.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.ScheduledExecutorService executor  
      private static java.lang.String JBOSS_TMP_DIR_PROPERTY  
      private static java.lang.String JVM_TMP_DIR_PROPERTY  
      private java.util.concurrent.atomic.AtomicBoolean open  
      private java.io.File providerRoot  
      private static int RETRIES  
      private static java.util.Random rng  
      private static java.io.File TMP_ROOT  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TempFileProvider​(java.io.File providerRoot, java.util.concurrent.ScheduledExecutorService executor)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close this provider and delete any temp files associated with it.
      static TempFileProvider create​(java.lang.String providerType, java.util.concurrent.ScheduledExecutorService executor)
      Create a temporary file provider for a given type.
      static TempFileProvider create​(java.lang.String providerType, java.util.concurrent.ScheduledExecutorService executor, boolean cleanExisting)
      Create a temporary file provider for a given type.
      TempDir createTempDir​(java.lang.String originalName)
      Create a temp directory, into which temporary files may be placed.
      private static java.io.File createTempDir​(java.lang.String prefix, java.lang.String suffix, java.io.File root)  
      (package private) static java.lang.String createTempName​(java.lang.String prefix, java.lang.String suffix)  
      (package private) void delete​(java.io.File root)
      Deletes any temp files associated with this provider
      protected void finalize()  
      (package private) java.io.File getProviderRoot()  
      • Methods inherited from class java.lang.Object

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

      • JBOSS_TMP_DIR_PROPERTY

        private static final java.lang.String JBOSS_TMP_DIR_PROPERTY
        See Also:
        Constant Field Values
      • JVM_TMP_DIR_PROPERTY

        private static final java.lang.String JVM_TMP_DIR_PROPERTY
        See Also:
        Constant Field Values
      • TMP_ROOT

        private static final java.io.File TMP_ROOT
      • open

        private final java.util.concurrent.atomic.AtomicBoolean open
      • providerRoot

        private final java.io.File providerRoot
      • executor

        private final java.util.concurrent.ScheduledExecutorService executor
      • rng

        private static final java.util.Random rng
    • Constructor Detail

      • TempFileProvider

        private TempFileProvider​(java.io.File providerRoot,
                                 java.util.concurrent.ScheduledExecutorService executor)
    • Method Detail

      • create

        public static TempFileProvider create​(java.lang.String providerType,
                                              java.util.concurrent.ScheduledExecutorService executor)
                                       throws java.io.IOException
        Create a temporary file provider for a given type.

        This is the same as calling create(final String providerType, final ScheduledExecutorService executor, false)

        Parameters:
        providerType - the provider type string (used as a prefix in the temp file dir name)
        executor - the executor
        Returns:
        the new provider
        Throws:
        java.io.IOException - if an I/O error occurs
      • create

        public static TempFileProvider create​(java.lang.String providerType,
                                              java.util.concurrent.ScheduledExecutorService executor,
                                              boolean cleanExisting)
                                       throws java.io.IOException
        Create a temporary file provider for a given type.
        Parameters:
        providerType - The provider type string (used as a prefix in the temp file dir name)
        executor - Executor which will be used to manage temp file provider tasks (like cleaning up/deleting the temp files when needed)
        cleanExisting - If this is true, then this method will *try* to delete the existing temp content (if any) for the providerType. The attempt to delete the existing content (if any) will be done in the background and this method will not wait for the deletion to complete. The method will immediately return back with a usable TempFileProvider. Note that the cleanExisting will just act as a hint for this method to trigger the deletion of existing content. The method may not always be able to delete the existing contents.
        Returns:
        The new provider
        Throws:
        java.io.IOException - if an I/O error occurs
      • getProviderRoot

        java.io.File getProviderRoot()
      • createTempDir

        public TempDir createTempDir​(java.lang.String originalName)
                              throws java.io.IOException
        Create a temp directory, into which temporary files may be placed.
        Parameters:
        originalName - the original file name
        Returns:
        the temp directory
        Throws:
        java.io.IOException - for any error
      • createTempDir

        private static java.io.File createTempDir​(java.lang.String prefix,
                                                  java.lang.String suffix,
                                                  java.io.File root)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • createTempName

        static java.lang.String createTempName​(java.lang.String prefix,
                                               java.lang.String suffix)
      • close

        public void close()
                   throws java.io.IOException
        Close this provider and delete any temp files associated with it.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • finalize

        protected void finalize()
        Overrides:
        finalize in class java.lang.Object
      • delete

        void delete​(java.io.File root)
             throws java.io.IOException
        Deletes any temp files associated with this provider
        Throws:
        java.io.IOException