|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.fileutil.SafeFileUtils
public class SafeFileUtils
Field Summary | |
---|---|
static int |
CLEAN_LOCK
|
static int |
DEFAULT_OPTIONS
|
static int |
LOCK_FILE
|
static long |
ONE_KB
|
static long |
ONE_MB
|
static int |
PRESERVE_DATE
|
Constructor Summary | |
---|---|
SafeFileUtils()
|
Method Summary | |
---|---|
static boolean |
closeQuietly(java.nio.channels.FileChannel stream)
|
static boolean |
closeQuietly(java.io.InputStream stream)
|
static boolean |
closeQuietly(java.io.OutputStream stream)
|
static void |
copyFile(java.io.File srcFile,
java.io.File destFile)
Copies a file to a new location preserving the file date. |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile,
int options)
Copies a file to a new location. |
static boolean |
deleteQuietly(java.io.File file)
Deletes a file, never throwing an exception. |
static void |
moveFile(java.io.File srcFile,
java.io.File destFile)
|
static void |
moveFile(java.io.File srcFile,
java.io.File destFile,
int options)
Moves a file. |
static void |
setDefaultOptions(int options)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long ONE_KB
public static final long ONE_MB
public static final int LOCK_FILE
public static final int CLEAN_LOCK
public static final int PRESERVE_DATE
public static int DEFAULT_OPTIONS
Constructor Detail |
---|
public SafeFileUtils()
Method Detail |
---|
public static void moveFile(java.io.File srcFile, java.io.File destFile, int options) throws java.io.IOException
When the destination file is on another file system, do a "copy and delete".
srcFile
- the file to be moveddestFile
- the destination file
java.lang.NullPointerException
- if source or destination is null
FileExistsException
- if the destination file exists
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs moving the filepublic static void moveFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
java.io.IOException
public static boolean deleteQuietly(java.io.File file)
The difference between File.delete() and this method are:
file
- file or directory to delete, can be null
true
if the file or directory was deleted, otherwise
false
public static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: This method tries to preserve the file's last
modified date/times using File.setLastModified(long)
, however
it is not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingpublic static void copyFile(java.io.File srcFile, java.io.File destFile, int options) throws java.io.IOException
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File.setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
options
- determine whether to use file locks and preserve date information
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingpublic static boolean closeQuietly(java.io.InputStream stream)
public static boolean closeQuietly(java.io.OutputStream stream)
public static boolean closeQuietly(java.nio.channels.FileChannel stream)
public static void setDefaultOptions(int options)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |