|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.utils.io.FileUtils
Provides various filesystem utilities.
Method Summary | |
static void |
copyFile(java.io.File src,
java.io.File dst)
Copies the given source file to a new destination. |
static void |
copyFile(java.io.File src,
java.io.OutputStream out)
Copies the source file to the given output stream. |
static void |
copyInputStream(java.io.InputStream in,
java.io.File dst)
Copies the given input stream to the destination file. |
static boolean |
deleteDirectory(java.io.File dir,
boolean top)
Recursivelly deletes the given directory. |
static boolean |
deleteFiles(java.io.File[] files)
Recursivelly deletes the given files. |
static byte[] |
digestFile(java.io.File file,
java.lang.String algorithm)
Computes message digest of a file. |
static void |
extractFile(java.io.File dir,
java.io.InputStream in,
java.util.zip.ZipEntry entry)
Extracts a file from the ZIP archive. |
static void |
extractFiles(java.io.File dir,
java.util.zip.ZipFile zip)
Extracts all files from the ZIP archive. |
static boolean |
lock(java.io.File file,
int retries)
Locks the given file or directory. |
static void |
prepareDirectory(java.io.File dir,
boolean delete)
Prepares the given directory for using. |
static void |
unlock(java.io.File file)
Unlocks the given file or directory. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void copyFile(java.io.File src, java.io.File dst) throws java.io.IOException
This method copies the given file to the new destination. If the dst argument represents an existing file, it will be overwritten.
src
- the source filedst
- the destination file
java.io.IOException
- if an error occuredpublic static void copyFile(java.io.File src, java.io.OutputStream out) throws java.io.IOException
This method copies the source file to the given output stream. It flushes the stream but does not close it before returning.
src
- the source fileout
- the output stream
java.io.IOException
- if an error occuredpublic static void copyInputStream(java.io.InputStream in, java.io.File dst) throws java.io.IOException
This method copies the given input stream to a new file. If the dst argument represents an existing file, it will be overwritten. The stream is left open after its content is copied to the file.
in
- the source input streamdst
- the destination file
java.io.IOException
- if an error occuredpublic static void prepareDirectory(java.io.File dir, boolean delete) throws java.io.IOException
If the given directory already exists, no action is performed and the method returns. Otherwise an attempt is made to create the directory and all its parent directories, if necessary. Method throws an IOException if the creation process fails for any reason. If the delete parameter is true, all files and directories within the given directory will be deleted.
dir
- the directory to be createddelete
- whether to clear the directory content
java.io.IOException
- if the directory can not be createdpublic static boolean deleteDirectory(java.io.File dir, boolean top)
This method recursivelly deletes all files within the specified directory. If the top parameter is true, it deletes also the top-level directory. Method returns true if all files and directories have been deleted successfully, otherwise it returns false.
dir
- the directory to be deletedtop
- true to delete the top-level directory
public static boolean deleteFiles(java.io.File[] files)
This method recursivelly deletes all files and directories referenced by the given array of file objects. It returns true if all files and directories have been deleted successfully, otherwise it returns false.
files
- the array of file objects
public static boolean lock(java.io.File file, int retries) throws java.io.IOException
If the given file argument denotes a directory, a special lock file named ".lock" is created within the directory. If it denotes a regular file, a special lock file with the original file name and the ".lock" suffix is created in the file's parent directory. The presence of this special file means the given file or directory is locked by an application process.
The retries argument specifies how many subsequent attempts will be made to lock the given file before giving up, if the very first attempt fails. Please note that there will be a pause between each subsequent attempt and this pause is extended each time a little bit. A reasonable value for this argument is from 1 to 5. Zero value means no additional locking attempt.
file
- the file to lockretries
- number of locking attempts
java.io.IOException
- if an error occurspublic static void unlock(java.io.File file) throws java.io.IOException
The given file is unlocked by removing the special lock file, created by the
lock(File, int)
method. It is completely OK to try to unlock a file, which
has not been locked before.
file
- the file to unlock
java.io.IOException
- if an error occurspublic static byte[] digestFile(java.io.File file, java.lang.String algorithm) throws java.io.IOException, java.security.NoSuchAlgorithmException
The digest algorithm can be specified via the algorithm parameter. If it is null, the default MD5 algorithm is used.
file
- the filealgorithm
- the digest algorithm
java.security.NoSuchAlgorithmException
- if the algorithm is not found
java.io.IOException
- if an error occured while reading the filepublic static void extractFiles(java.io.File dir, java.util.zip.ZipFile zip) throws java.io.IOException
This method extracts all files from the ZipFile to the given target directory. All directories are created as needed.
dir
- the target directoryzip
- the ZIP file
java.io.IOException
- if an error occured during the extractionpublic static void extractFile(java.io.File dir, java.io.InputStream in, java.util.zip.ZipEntry entry) throws java.io.IOException
This method extracts one file represented by the ZipEntry to the given target directory. All directories are created as needed.
dir
- the target directoryin
- the input stream to read the file fromentry
- the ZIP entry of the file
java.io.IOException
- if an error occured during the extracting
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |