|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tuscany.sca.contribution.service.util.FileHelper
public class FileHelper
Nested Class Summary | |
---|---|
static class |
FileHelper.RegExpFilter
A regular-expression based resource filter |
Constructor Summary | |
---|---|
FileHelper()
|
Method Summary | |
---|---|
static void |
cleanDirectory(java.io.File directory)
Clean a directory without deleting it. |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir)
Copies a whole directory to a new location preserving the file dates. |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir,
boolean preserveFileDate)
Copies a whole directory to a new location. |
static void |
copyDirectoryToDirectory(java.io.File srcDir,
java.io.File destDir)
Copies a directory to within another directory preserving the file dates. |
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,
boolean preserveFileDate)
Copies a file to a new location. |
static void |
copyFileToDirectory(java.io.File srcFile,
java.io.File destDir)
Copies a file to a directory preserving the file date. |
static void |
copyFileToDirectory(java.io.File srcFile,
java.io.File destDir,
boolean preserveFileDate)
Copies a file to a directory optionally preserving the file date. |
static void |
deleteDirectory(java.io.File directory)
Recursively delete a directory. |
static void |
forceDelete(java.io.File file)
Delete a file. |
static void |
forceDeleteOnExit(java.io.File file)
Schedule a file to be deleted when JVM exits. |
static void |
forceMkdir(java.io.File directory)
Make a directory, including any necessary but nonexistent parent directories. |
static java.lang.String |
getExtension(java.lang.String filename)
Gets the extension of a filename. |
static java.io.FileFilter |
getFileFilter(java.lang.String regExp,
boolean ignoreCase)
|
static java.lang.String |
getName(java.lang.String fileName)
Gets the name minus the path from a full filename. |
static int |
indexOfExtension(java.lang.String filename)
Returns the index of the last extension separator character, which is a dot. |
static int |
indexOfLastSeparator(java.lang.String filename)
Returns the index of the last directory separator character. |
static java.io.File |
toFile(java.net.URL url)
Convert from a URL to a File . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileHelper()
Method Detail |
---|
public static int indexOfLastSeparator(java.lang.String filename)
This method will handle a file in either Unix or Windows format. The position of the last forward or backslash is returned.
The output will be the same irrespective of the machine that the code is running on.
filename
- the filename to find the last path separator in, null
returns -1
public static int indexOfExtension(java.lang.String filename)
This method also checks that there is no directory separator after the
last dot. To do this it uses indexOfLastSeparator(String)
which
will handle a file in either Unix or Windows format.
The output will be the same irrespective of the machine that the code is running on.
filename
- the filename to find the last path separator in, null
returns -1
public static java.lang.String getName(java.lang.String fileName)
This method will handle a file in either Unix or Windows format. The text after the last forward or backslash is returned.
a/b/c.txt --> c.txt a.txt --> a.txt a/b/c --> c a/b/c/ --> ""
The output will be the same irrespective of the machine that the code is running on.
fileName
- the filename to query, null returns null
public static java.lang.String getExtension(java.lang.String filename)
This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.
foo.txt --> "txt" a/b/c.jpg --> "jpg" a/b.txt/c --> "" a/b/c --> ""
The output will be the same irrespective of the machine that the code is running on.
filename
- the filename to retrieve the extension of.
public static void forceMkdir(java.io.File directory) throws java.io.IOException
directory
- directory to create, not null
java.lang.NullPointerException
- if the directory is null
java.io.IOException
- if the directory cannot be createdpublic static void forceDelete(java.io.File file) throws java.io.IOException
The difference between File.delete() and this method are:
file
- file or directory to delete, not null
java.lang.NullPointerException
- if the directory is null
java.io.IOException
- in case deletion is unsuccessfulpublic static java.io.File toFile(java.net.URL url)
URL
to a File
.
From version 1.1 this method will decode the URL. Syntax such as
file:///my%20docs/file.txt
will be correctly decoded to
/my docs/file.txt
.
url
- the file URL to convert, null returns null
File
object, or null
if the URL's protocol is not file
java.lang.IllegalArgumentException
- if the file is incorrectly encodedpublic static java.io.FileFilter getFileFilter(java.lang.String regExp, boolean ignoreCase)
public static void cleanDirectory(java.io.File directory) throws java.io.IOException
directory
- directory to clean
java.io.IOException
- in case cleaning is unsuccessfulpublic static void copyDirectory(java.io.File srcDir, java.io.File destDir) throws java.io.IOException
This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
srcDir
- an existing directory to copy, must not be
null
destDir
- the new directory, 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 copyDirectory(java.io.File srcDir, java.io.File destDir, boolean preserveFileDate) throws java.io.IOException
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
srcDir
- an existing directory to copy, must not be
null
destDir
- the new directory, must not be null
preserveFileDate
- true if the file date of the copy should be the
same as the original
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 copyDirectoryToDirectory(java.io.File srcDir, java.io.File destDir) throws java.io.IOException
This method copies the source directory and all its contents to a directory of the same name in the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
srcDir
- an existing directory to copy, must not be
null
destDir
- the directory to place the copy in, 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) 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.
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 copyingcopyFileToDirectory(File, File)
public static void copyFile(java.io.File srcFile, java.io.File destFile, boolean preserveFileDate) 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.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
preserveFileDate
- true if the file date of the copy should be the
same as the original
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 copyingcopyFileToDirectory(File, File, boolean)
public static void copyFileToDirectory(java.io.File srcFile, java.io.File destDir) throws java.io.IOException
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
srcFile
- an existing file to copy, must not be null
destDir
- the directory to place the copy in, 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 copyingcopyFile(File, File, boolean)
public static void copyFileToDirectory(java.io.File srcFile, java.io.File destDir, boolean preserveFileDate) throws java.io.IOException
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
srcFile
- an existing file to copy, must not be null
destDir
- the directory to place the copy in, must not be
null
preserveFileDate
- true if the file date of the copy should be the
same as the original
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 copyingcopyFile(File, File, boolean)
public static void deleteDirectory(java.io.File directory) throws java.io.IOException
directory
- directory to delete
java.io.IOException
- in case deletion is unsuccessfulpublic static void forceDeleteOnExit(java.io.File file) throws java.io.IOException
file
- file or directory to delete, must not be null
java.lang.NullPointerException
- if the file is null
java.io.IOException
- in case deletion is unsuccessful
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |