|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microsoft.tfs.util.temp.TempStorageService
public final class TempStorageService
Creates temporary files and directories with more flexibility than the
File
class. Temp items can be deleted immediately with
cleanUpItem(File)
. By default items the service creates will be
deleted when the JVM shuts down, but this behavior can be changed per-item
with forgetItem(File)
.
This class is a singleton.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_EXTENSION
The default extension for files we create. |
Method Summary | |
---|---|
void |
cleanUpAllItems()
Cleans up (deletes) files and directories allocated by this service. |
void |
cleanUpItem(java.io.File item)
Cleans up (deletes) a file or directory which was allocated by this service. |
java.io.File |
createTempDirectory()
Creates a temporary directory (named after a new GUID) inside the system's default temporary directory and returns its full path. |
java.io.File |
createTempFile()
Creates a new empty file in a new directory inside the system's default temporary directory. |
java.io.File |
createTempFile(java.io.File userDirectory,
java.lang.String extension)
Creates a new empty file with the specified extension in the specified directory. |
java.io.File |
createTempFile(java.lang.String extension)
Creates a new empty file with the specified extension in a new directory inside the system's default temporary directory. |
void |
deleteItem(java.io.File item)
|
void |
forgetItem(java.io.File item)
Prevents the TempStorageService from cleaning up (deleting) this
item automatically in the future. |
static TempStorageService |
getInstance()
|
void |
renameItem(java.io.File sourceItem,
java.io.File targetItem)
Sometime a file cannot be renamed because it's locked by a file system scanning process like anti-viruses software, user virtualization client, Google console, etc. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_EXTENSION
".tmp"
Method Detail |
---|
public static TempStorageService getInstance()
TempStorageService
.public java.io.File createTempFile() throws java.io.IOException
Creates a new empty file in a new directory inside the system's default
temporary directory. See createTempFile(File, String)
for how to
delete the file.
java.io.IOException
- if a filesystem error occurred creating the temporary filepublic java.io.File createTempFile(java.lang.String extension) throws java.io.IOException
Creates a new empty file with the specified extension in a new directory
inside the system's default temporary directory. See
createTempFile(File, String)
for how to delete the file.
extension
- the extension (including the '.') to use for the temporary file's
name (pass null
or empty to use the default,
DEFAULT_EXTENSION
)
java.io.IOException
- if a filesystem error occurred creating the temporary filepublic java.io.File createTempFile(java.io.File userDirectory, java.lang.String extension) throws java.io.IOException
Creates a new empty file with the specified extension in the specified directory.
When done using the file, do one of:
cleanUpItem(File)
with the file;
TempStorageService
deletes it immediatelyTempStorageService
will delete it on JVM shutdown
forgetItem(File)
with the file to prevent deletion on
JVM shutdown; delete it yourself if desiredcleanUpAllItems()
to delete all items created by
TempStorageService
userDirectory
- the directory in which to create this file (which must already
exist). If null
or empty, a new directory is created
inside the system's temporary location and the file is created
there and that directory is automatically cleaned up when the file
is cleaned upextension
- the extension (including the '.') to use for the temporary file
(pass null
or empty to use the default).
java.io.IOException
- if a filesystem error occurred creating the temporary file.public java.io.File createTempDirectory() throws java.io.IOException
cleanUpItem(File)
to
have it deleted.
If you do not call cleanUpItem(File)
or
forgetItem(File)
in the future, any future call to
cleanUpAllItems()
will clean it up for you.
java.io.IOException
- if a filesystem error occurred creating the temporary directory.public void forgetItem(java.io.File item)
TempStorageService
from cleaning up (deleting) this
item automatically in the future.
item
- the file or directory created by TempStorageService
that
should not be cleaned up (deleted) by TempStorageService
in the future (must not be null
)public void renameItem(java.io.File sourceItem, java.io.File targetItem)
sourceItem
- the file or directory to rename (must not be null
)targetItem
- the new file or directory (must not be null
and not
exist in the file system)public void deleteItem(java.io.File item)
public void cleanUpItem(java.io.File item)
Cleans up (deletes) a file or directory which was allocated by this service. If the item is a file in a directory which was also created by the service, that directory is cleaned up (recursively).
If the path was not allocated by this TempStorageService
or was
already cleaned up, no exception is thrown and the item is ignored.
item
- an item that was created by createTempFile()
or
createTempDirectory()
(must not be null
)public void cleanUpAllItems()
TempStorageService
instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |