Package org.jboss.vfs
Class TempFileProvider
- java.lang.Object
-
- org.jboss.vfs.TempFileProvider
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class TempFileProvider extends java.lang.Object implements java.io.CloseableA provider for temporary physical files and directories.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classTempFileProvider.DeleteTask
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ScheduledExecutorServiceexecutorprivate static java.lang.StringJBOSS_TMP_DIR_PROPERTYprivate static java.lang.StringJVM_TMP_DIR_PROPERTYprivate java.util.concurrent.atomic.AtomicBooleanopenprivate java.io.FileproviderRootprivate static intRETRIESprivate static java.util.Randomrngprivate static java.io.FileTMP_ROOT
-
Constructor Summary
Constructors Modifier Constructor Description privateTempFileProvider(java.io.File providerRoot, java.util.concurrent.ScheduledExecutorService executor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this provider and delete any temp files associated with it.static TempFileProvidercreate(java.lang.String providerType, java.util.concurrent.ScheduledExecutorService executor)Create a temporary file provider for a given type.static TempFileProvidercreate(java.lang.String providerType, java.util.concurrent.ScheduledExecutorService executor, boolean cleanExisting)Create a temporary file provider for a given type.TempDircreateTempDir(java.lang.String originalName)Create a temp directory, into which temporary files may be placed.private static java.io.FilecreateTempDir(java.lang.String prefix, java.lang.String suffix, java.io.File root)(package private) static java.lang.StringcreateTempName(java.lang.String prefix, java.lang.String suffix)(package private) voiddelete(java.io.File root)Deletes any temp files associated with this providerprotected voidfinalize()(package private) java.io.FilegetProviderRoot()
-
-
-
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
-
RETRIES
private static final int RETRIES
- See Also:
- Constant Field Values
-
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
-
-
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 callingcreate(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 theproviderType. 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 usableTempFileProvider. Note that thecleanExistingwill 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.IOExceptionClose this provider and delete any temp files associated with it.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
finalize
protected void finalize()
- Overrides:
finalizein classjava.lang.Object
-
delete
void delete(java.io.File root) throws java.io.IOExceptionDeletes any temp files associated with this provider- Throws:
java.io.IOException
-
-