public class TempFileManager
extends java.lang.Object
Constructor and Description |
---|
TempFileManager()
Default constructor, passes "omero" to
TempFileManager(String) |
TempFileManager(java.lang.String prefix)
Initializes a
TempFileManager instance with the user's
temporary directory containing the given prefix value. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
access(java.io.File dir)
Returns true if the current user can write to the give directory.
|
protected void |
cleanTempDir()
Deletes the top-level temporary directory.
|
protected void |
cleanup()
Releases the lock and deletes the top-level temporary directory.
|
protected void |
cleanUserDir()
Attempts to delete all directories under self.userdir other than the one
owned by this process.
|
static java.io.File |
create_path()
Calls
createPath(String, String, boolean)
with defaults of "omero", ".tmp", and false. |
static java.io.File |
create_path(java.lang.String prefix)
Calls
createPath(String, String, boolean)
with defaults of ".tmp", and false. |
static java.io.File |
create_path(java.lang.String prefix,
java.lang.String suffix)
Calls
createPath(String, String, boolean)
with ".tmp", and false arguments. |
static java.io.File |
create_path(java.lang.String prefix,
java.lang.String suffix,
boolean folder)
|
protected boolean |
create(java.io.File dir)
If the given directory doesn't exist, creates it and returns true.
|
java.io.File |
createPath(java.lang.String prefix,
java.lang.String suffix,
boolean folder)
Uses
File.createTempFile(String, String, File) to create
temporary files and folders under the top-level temporary directory. |
static java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix)
Emulates
File.createTempFile(String, String) by calling
create_path(String, String) . |
static void |
gettempdir()
Calls
getTempDir() . |
java.io.File |
getTempDir()
Returns the directory under which all temporary files and folders will be
created.
|
static void |
main(java.lang.String[] _args)
Command-line interface to the global
TempFileManager instance. |
protected java.lang.String |
pid()
Returns some representation of the current process's id
|
static void |
remove_path(java.io.File file)
Calls
removePath(File) . |
void |
removePath(java.io.File file)
If the given file is under the top-level temporary directory
then it is deleted whether file or folder.
|
protected java.io.File |
tmpdir()
Returns a platform-specific user-writable temporary directory.
|
protected java.lang.String |
username()
Returns the current OS-user's name.
|
public TempFileManager()
TempFileManager(String)
public TempFileManager(java.lang.String prefix)
TempFileManager
instance with the user's
temporary directory containing the given prefix value. Also adds a
shutdown hook
to call
cleanup()
on exit.prefix
- the prefix for the user's temporary directoryprotected void cleanup() throws java.io.IOException
java.io.IOException
protected java.io.File tmpdir()
protected java.lang.String username()
protected java.lang.String pid()
protected boolean access(java.io.File dir)
protected boolean create(java.io.File dir)
public java.io.File getTempDir()
public java.io.File createPath(java.lang.String prefix, java.lang.String suffix, boolean folder) throws java.io.IOException
File.createTempFile(String, String, File)
to create
temporary files and folders under the top-level temporary directory.
For folders, first a temporary file is created, then deleted,
and finally a directory produced.java.io.IOException
public void removePath(java.io.File file) throws java.io.IOException
RuntimeException
is thrown.java.io.IOException
protected void cleanTempDir() throws java.io.IOException
java.io.IOException
protected void cleanUserDir() throws java.io.IOException
java.io.IOException
public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
File.createTempFile(String, String)
by calling
create_path(String, String)
.java.io.IOException
public static java.io.File create_path() throws java.io.IOException
createPath(String, String, boolean)
with defaults of "omero", ".tmp", and false.java.io.IOException
public static java.io.File create_path(java.lang.String prefix) throws java.io.IOException
createPath(String, String, boolean)
with defaults of ".tmp", and false.java.io.IOException
public static java.io.File create_path(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
createPath(String, String, boolean)
with ".tmp", and false arguments.java.io.IOException
public static java.io.File create_path(java.lang.String prefix, java.lang.String suffix, boolean folder) throws java.io.IOException
java.io.IOException
public static void remove_path(java.io.File file) throws java.io.IOException
removePath(File)
.java.io.IOException
public static void gettempdir()
getTempDir()
.public static void main(java.lang.String[] _args) throws java.io.IOException
TempFileManager
instance.
Valid arguments: "--debug", "clean", "dir", and for
testing, "lock"java.io.IOException