org.alfresco.util
Class TempFileProvider

java.lang.Object
  extended by org.alfresco.util.TempFileProvider

public class TempFileProvider
extends java.lang.Object

A helper class that provides temporary files, providing a common point to clean them up.

The contents of ALFRESCO_TEMP_FILE_DIR [%java.io.tmpdir%/Alfresco] are managed by this class. Temporary files and directories are cleaned by TempFileCleanerJob so that after a delay [default 1 hour] the contents of the alfresco temp dir, both files and directories are removed.

Some temporary files may need to live longer than 1 hour. The temp file provider allows special sub folders which are cleaned less frequently. By default, files in the long life folders will remain for 24 hours unless cleaned by the application code earlier.

The other contents of %java.io.tmpdir% are not touched by the cleaner job.

TempFileCleanerJob Job Data: protectHours, number of hours to keep temporary files, default 1 hour.


Nested Class Summary
static class TempFileProvider.TempFileCleanerJob
          Cleans up all Alfresco temporary files that are older than the given number of hours.
 
Field Summary
static java.lang.String ALFRESCO_LONG_LIFE_FILE_DIR
          The prefix for the long life temporary files.
static java.lang.String ALFRESCO_TEMP_FILE_DIR
          subdirectory in the temp directory where Alfresco temporary files will go
static java.lang.String SYSTEM_KEY_TEMP_DIR
          the system property key giving us the location of the temp directory
 
Method Summary
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)
          Create a temp file in the alfresco temp dir.
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
           
static java.io.File getLongLifeTempDir(java.lang.String key)
          creates a longer living temp dir.
static java.io.File getSystemTempDir()
          Get the Java Temp dir e.g.
static java.io.File getTempDir()
          Get the Alfresco temp dir, by defaut %java.io.tempdir%/Alfresco.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALFRESCO_TEMP_FILE_DIR

public static final java.lang.String ALFRESCO_TEMP_FILE_DIR
subdirectory in the temp directory where Alfresco temporary files will go

See Also:
Constant Field Values

ALFRESCO_LONG_LIFE_FILE_DIR

public static final java.lang.String ALFRESCO_LONG_LIFE_FILE_DIR
The prefix for the long life temporary files.

See Also:
Constant Field Values

SYSTEM_KEY_TEMP_DIR

public static final java.lang.String SYSTEM_KEY_TEMP_DIR
the system property key giving us the location of the temp directory

See Also:
Constant Field Values
Method Detail

getSystemTempDir

public static java.io.File getSystemTempDir()
Get the Java Temp dir e.g. java.io.tempdir

Returns:
Returns the system temporary directory i.e. isDir == true

getTempDir

public static java.io.File getTempDir()
Get the Alfresco temp dir, by defaut %java.io.tempdir%/Alfresco. Will create the temp dir on the fly if it does not already exist.

Returns:
Returns a temporary directory, i.e. isDir == true

getLongLifeTempDir

public static java.io.File getLongLifeTempDir(java.lang.String key)
creates a longer living temp dir. Files within the longer living temp dir will not be garbage collected as soon as "normal" temporary files. By default long life temp files will live for for 24 hours rather than 1 hour.

Code using the longer life temporary files should be careful to clean up since abuse of this feature may result in out of memory/disk space errors.

Parameters:
key - can be blank in which case the system will generate a folder to be used by all processes or can be used to create a unique temporary folder name for a particular process. At the end of the process the client can simply delete the entire temporary folder.
Returns:
the long life temporary directory

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix)
Create a temp file in the alfresco temp dir.

Returns:
Returns a temp File that will be located in the Alfresco subdirectory of the default temp directory
See Also:
TempFileProvider.ALFRESCO_TEMP_FILE_DIR, File.createTempFile(java.lang.String, java.lang.String)

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          java.io.File directory)
Returns:
Returns a temp File that will be located in the given directory
See Also:
TempFileProvider.ALFRESCO_TEMP_FILE_DIR, File.createTempFile(java.lang.String, java.lang.String)


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.