|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.schmant.support.io.TempFileUtil
public final class TempFileUtil
Utility class with static methods for creating temporary files and directories. Files and directories created using the methods in this class are by default deleted when the Schmant program exits.
Field Summary | |
---|---|
static String |
DEFAULT_PREFIX
The default name prefix for temporary files and directories. |
static String |
DEFAULT_SUFFIX
The default name suffix for temporary files and directories. |
Method Summary | |
---|---|
static File |
createTempDir()
Create a temporary directory in the default temporary files directory (or the directory referenced by the java.io.tmpdir system property if
the default temporary files directory is not set). |
static File |
createTempDir(boolean keep)
Create a temporary directory in the default temporary files directory (or the directory referenced by the java.io.tmpdir system property if
the default temporary files directory is not set). |
static File |
createTempDir(File directory)
Create a temporary directory in the supplied directory (which must exist). |
static File |
createTempDir(File directory,
String prefix,
String suffix,
boolean keep)
Create a temporary directory in the given directory named with the supplied directory name prefix and suffix. |
static File |
createTempDir(String prefix,
String suffix,
boolean keep)
Create a temporary directory named with the supplied directory name prefix and suffix in the default temporary files directory. |
static Directory |
createTempDirectory()
Create a temporary directory entity in the default temporary files directory. |
static Directory |
createTempDirectory(boolean keep)
Create a temporary directory entity in the default temporary files directory. |
static DirectoryView |
createTempDirectory(DirectoryView d)
Create a temporary directory entity in the supplied directory. |
static DirectoryView |
createTempDirectory(DirectoryView d,
String prefix,
String suffix,
boolean keep)
Create a temporary directory entity in the supplied directory. |
static Directory |
createTempDirectory(FileSystem fs)
Create a temporary directory entity in the file system's default temporary files directory. |
static Directory |
createTempDirectory(String prefix,
String suffix,
boolean keep)
Create a temporary directory the in the default temporary files directory. |
static Directory |
createTempDirectoryInFSTempFilesDirectoryIfSet(FileSystem fs)
Create a temporary directory entity. |
static EFile |
createTempEFile()
Create a read/write temporary file entity in the platform's temporary files directory. |
static EFile |
createTempEFile(DirectoryView d)
Create a temporary, initially empty file entity in the supplied directory. |
static EFile |
createTempEFile(DirectoryView d,
String prefix,
String suffix,
boolean keep)
Create a temporary, initially empty file entity in the supplied directory. |
static EFile |
createTempEFile(FileSystem fs)
Create a temporary, initially empty file entity in the file system's default temporary files directory. |
static EFile |
createTempEFileInFSTempFilesDirectoryIfSet(FileSystem fs)
Create a temporary, initially empty file entity. |
static File |
createTempFile()
Create a temporary, initially empty, file in the default temporary files directory (or in the directory referenced by the java.io.tmpdir
system property if the default temporary files directory is not set). |
static File |
createTempFile(File directory)
Create a temporary, initially empty, file in the supplied directory (which must exist). |
static File |
createTempFile(File directory,
String prefix,
String suffix,
boolean keep)
Create a temporary file in the given directory named with the supplied file name prefix and suffix. |
static Object |
init(boolean keep)
The Launcher class uses this to initialize a new
context for temporary files. |
static void |
setDefaultTempDirectory(Directory d)
Set a default directory for temporary files. |
static void |
setDefaultTempDirectory(File d)
Set a default directory for temporary files. |
static void |
setMaxRandomNumber(int max)
Set the biggest random number (exclusive) to use when creating temporary files and directories. |
static void |
tearDown(Object prevContext)
Tear down the current temporary files context and restore the old, if any. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_PREFIX
public static final String DEFAULT_SUFFIX
Method Detail |
---|
public static Object init(boolean keep)
Launcher
class uses this to initialize a new
context for temporary files. If this class already has a context, it is
returned and Launcher
will keep it and return it
when it calls tearDown(Object)
.
keep
- Should temporary files be kept?
tearDown(Object)
public static void tearDown(Object prevContext)
This is used by the Launcher
class.
prevContext
- If init(boolean)
returned
a temporary files context, it should be passed in here.public static void setDefaultTempDirectory(Directory d)
java.io.tmpdir
for creating temporary entities in. It can be
useful, or at least aesthetically pleasing, for big build scripts to put
their temporary files in another catalog than java.io.tmpdir
since they often generate so many of them.
Use for instance setDefaultTempDirectory(createTempDirectory())
to put all temporary files in a subdirectory of java.io.tmpdir
.
d
- The temporary files directory.setDefaultTempDirectory(File)
public static void setDefaultTempDirectory(File d)
java.io.tmpdir
for creating temporary entities in. It can be
useful, or at least aesthetically pleasing, for big build scripts to put
their temporary files in another catalog than java.io.tmpdir
since they often generate so many of them.
Use for instance setDefaultTempDirectory(createTempDirectory())
to put all temporary files in a subdirectory of java.io.tmpdir
.
d
- The temporary files directory.setDefaultTempDirectory(Directory)
public static void setMaxRandomNumber(int max) throws IllegalArgumentException
max
- The biggest random number. Must be > 0
.
IllegalArgumentException
- If the number is <= 0
.public static File createTempDir()
java.io.tmpdir
system property if
the default temporary files directory is not set). The directory and all
its contents will be deleted when Schmant exits.
setDefaultTempDirectory(File)
public static File createTempDir(boolean keep)
java.io.tmpdir
system property if
the default temporary files directory is not set). If keep
is set
to true
, the directory will be kept when Schmant exits, otherwise
it and all of its contents will be deleted.
keep
- Should the directory be kept after Schmant exits?
setDefaultTempDirectory(File)
public static File createTempDir(File directory)
directory
- The directory to create the temporary directory in. This
directory must exist. Set to null
to use the default temporary
files directory (the java.io.tmpdir
system property).
setDefaultTempDirectory(File)
public static File createTempDir(String prefix, String suffix, boolean keep)
keep
is set to true
, the directory and its contents will
not be deleted when the Schmant program exits (unless the
directory is created in or in a subdirectory of a temporary files
directory that does not have its keep flag set).
prefix
- The directory name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The directory name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the directory and its contents will
not be deleted when the Schmant program exits. (Unless the file is
created in or in a subdirectory of a temporary directory that does not
have its keep flag set.)
createTempDir()
,
setDefaultTempDirectory(File)
public static File createTempDir(File directory, String prefix, String suffix, boolean keep)
keep
is set to
true
, the directory and its contents will not be deleted
when the Schmant program exits (unless the directory is created in or in
a subdirectory of a temporary files directory that does not have its
keep flag set).
directory
- The directory to create the temporary directory in. This
directory must exist. Set to null
to use the default temporary
files directory.prefix
- The directory name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The directory name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the directory and its contents will
not be deleted when the Schmant program exits. (Unless the file is
created in or in a subdirectory of a temporary directory that does not
have its keep flag set.)
setDefaultTempDirectory(File)
public static File createTempFile()
java.io.tmpdir
system property if the default temporary files directory is not set). The
file will be deleted when Schmant exits.
setDefaultTempDirectory(File)
public static File createTempFile(File directory)
directory
- The directory to create the temporary file in. This
directory must exist. Set to null
to use the default temporary
files directory (the java.io.tmpdir
system property).
setDefaultTempDirectory(File)
public static File createTempFile(File directory, String prefix, String suffix, boolean keep)
keep
is set to true
, the
file will not be deleted when the Schmant program exits (unless
the file is created in, or in a subdirectory of, a temporary directory
that does not have its keep flag set).
directory
- The directory to create the temporary file in. This
directory must exist. Set to null
to use the default temporary
files directory (the java.io.tmpdir
system property).prefix
- The file name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The file name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the file will not be deleted
when the Schmant program exits. (Unless the file is created in or in a
subdirectory of a temporary directory that does not have its keep flag
set.)
setDefaultTempDirectory(File)
public static EFile createTempEFile(FileSystem fs)
fs
- The file system.
setDefaultTempDirectory(Directory)
public static EFile createTempEFileInFSTempFilesDirectoryIfSet(FileSystem fs)
fs
- The file system.
setDefaultTempDirectory(Directory)
public static EFile createTempEFile(DirectoryView d)
d
- The directory.
setDefaultTempDirectory(Directory)
public static EFile createTempEFile(DirectoryView d, String prefix, String suffix, boolean keep)
keep
flag is set to true
, the file will
not be deleted when the Schmant program exits (unless the file is
created in, or in a subdirectory of, a temporary files directory that
does not have its keep flag set).
d
- The directory.prefix
- The file name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The file name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the file will not be deleted
when the Schmant program exits (unless the file is created in, or in a
subdirectory of, a temporary files directory that does not have its keep
flag set).
setDefaultTempDirectory(Directory)
public static EFile createTempEFile()
setDefaultTempDirectory(Directory)
public static Directory createTempDirectory()
setDefaultTempDirectory(Directory)
public static Directory createTempDirectory(boolean keep)
keep
is set to true
, the directory will be
kept when Schmant exits. Otherwise it and all of its contents will be
deleted.
Schmant program exits.
setDefaultTempDirectory(Directory)
public static Directory createTempDirectory(String prefix, String suffix, boolean keep)
keep
flag is set to true
, the directory
and its contents will not be deleted when the Schmant program
exits (unless the directory is created in, or in a subdirectory of, a
temporary files directory that does not have its keep flag set)..
prefix
- The directory name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The directory name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the directory and its contents will
not be deleted when the Schmant program exits (unless the
directory is created in, or in a subdirectory of, a temporary files
directory that does not have its keep flag set)..
setDefaultTempDirectory(Directory)
public static Directory createTempDirectory(FileSystem fs)
fs
- The file system.
setDefaultTempDirectory(Directory)
public static Directory createTempDirectoryInFSTempFilesDirectoryIfSet(FileSystem fs)
fs
- The file system.
setDefaultTempDirectory(Directory)
public static DirectoryView createTempDirectory(DirectoryView d)
d
- The directory to create the temporary directory in.
setDefaultTempDirectory(Directory)
public static DirectoryView createTempDirectory(DirectoryView d, String prefix, String suffix, boolean keep)
keep
flag is set to true
, the directory and its contents
will not be deleted when the Schmant program exits (unless the
directory is created in, or in a subdirectory of, a temporary files
directory that does not have its keep flag set)..
d
- The directory.prefix
- The directory name prefix. Set to null
to use the
default prefix ("schmant").suffix
- The directory name suffix. Set to null
to use the
default suffix ("tmp").keep
- If set to true
, the directory and its contents will
not be deleted when the Schmant program exits(unless the directory
is created in, or in a subdirectory of, a temporary files directory that
does not have its keep flag set)..
setDefaultTempDirectory(Directory)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |