public class TempFileManager extends Object
Constructor and Description |
---|
TempFileManager()
Default constructor, passes "omero" to
TempFileManager(String) |
TempFileManager(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(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 File |
create_path()
Calls
createPath(String, String, boolean)
with defaults of "omero", ".tmp", and false. |
static File |
create_path(String prefix)
Calls
createPath(String, String, boolean)
with defaults of ".tmp", and false. |
static File |
create_path(String prefix,
String suffix)
Calls
createPath(String, String, boolean)
with ".tmp", and false arguments. |
static File |
create_path(String prefix,
String suffix,
boolean folder)
|
protected boolean |
create(File dir)
If the given directory doesn't exist, creates it and returns true.
|
File |
createPath(String prefix,
String suffix,
boolean folder)
Uses
File.createTempFile(String, String, File) to create
temporary files and folders under the top-level temporary directory. |
static File |
createTempFile(String prefix,
String suffix)
Emulates
File.createTempFile(String, String) by calling
create_path(String, String) . |
static void |
gettempdir()
Calls
getTempDir() . |
File |
getTempDir()
Returns the directory under which all temporary files and folders will be
created.
|
static void |
main(String[] _args)
Command-line interface to the global
TempFileManager instance. |
protected String |
pid()
Returns some representation of the current process's id
|
static void |
remove_path(File file)
Calls
removePath(File) . |
void |
removePath(File file)
If the given file is under the top-level temporary directory
then it is deleted whether file or folder.
|
protected File |
tmpdir()
Returns a platform-specific user-writable temporary directory.
|
protected String |
username()
Returns the current OS-user's name.
|
public TempFileManager()
TempFileManager(String)
public TempFileManager(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 IOException
IOException
protected File tmpdir()
protected String username()
protected String pid()
protected boolean access(File dir)
protected boolean create(File dir)
public File getTempDir()
public File createPath(String prefix, String suffix, boolean folder) throws 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.IOException
public void removePath(File file) throws IOException
RuntimeException
is thrown.IOException
protected void cleanTempDir() throws IOException
IOException
protected void cleanUserDir() throws IOException
IOException
public static File createTempFile(String prefix, String suffix) throws IOException
File.createTempFile(String, String)
by calling
create_path(String, String)
.IOException
public static File create_path() throws IOException
createPath(String, String, boolean)
with defaults of "omero", ".tmp", and false.IOException
public static File create_path(String prefix) throws IOException
createPath(String, String, boolean)
with defaults of ".tmp", and false.IOException
public static File create_path(String prefix, String suffix) throws IOException
createPath(String, String, boolean)
with ".tmp", and false arguments.IOException
public static File create_path(String prefix, String suffix, boolean folder) throws IOException
IOException
public static void remove_path(File file) throws IOException
removePath(File)
.IOException
public static void gettempdir()
getTempDir()
.public static void main(String[] _args) throws IOException
TempFileManager
instance.
Valid arguments: "--debug", "clean", "dir", and for
testing, "lock"IOException
Version: 5.3.3-ice35-b63
Copyright © 2017 The University of Dundee & Open Microscopy Environment. All Rights Reserved.