public final class FileSupport extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DELETE_CONTENT
Delete all content but keep the root directory.
|
static int |
DELETE_FILES
Only files will be deleted, the directory structure remains untouched.
|
static int |
DELETE_ROOT
Delete everything including the root directory.
|
| Modifier and Type | Method and Description |
|---|---|
static File |
copy(File sourceLocation,
File targetLocation)
Copies the specified file from
sourceLocation to targetLocation and returns a reference
to the newly created file or directory. |
static File |
copy(File sourceFile,
File targetFile,
boolean overwrite)
Copies the specified
sourceLocation to targetLocation and returns a reference to the
newly created file or directory. |
static void |
copyContent(File sourceDirectory,
File targetDirectory)
Copies recursively the content of the specified
sourceDirectory to
targetDirectory. |
static void |
copyContent(File sourceDirectory,
File targetDirectory,
boolean overwrite)
Copies recursively the content of the specified
sourceDirectory to
targetDirectory. |
static boolean |
delete(File f)
Deletes the specified file and returns
true if the file was deleted. |
static boolean |
delete(File f,
boolean recurse)
Deletes the specified file and returns
true if the file was deleted. |
static boolean |
delete(File dir,
int mode)
Deletes the content of directory
dir and, if specified, the directory itself. |
static boolean |
deleteHierarchyIfEmpty(File limit,
File start)
Delete all directories from
start up to directory limit if they are empty. |
static boolean |
deleteQuietly(File f)
Like
delete(File) but does not throw any IO exceptions. |
static boolean |
deleteQuietly(File f,
boolean recurse)
Like
delete(File, boolean) but does not throw any IO exceptions. |
static boolean |
equals(File a,
File b)
Returns true if both canonical file paths are equal.
|
static File |
getTempDirectory()
Returns the webapp's temporary work directory.
|
static File |
getTempDirectory(String subdir)
Returns a directory
subdir inside the webapp's temporary work directory. |
static boolean |
isEqual(File a,
File b)
Compare two files by their canonical paths.
|
static boolean |
isParent(File a,
File b)
Check if
a is a parent of b. |
static File |
link(File sourceLocation,
File targetLocation)
Links the specified file or directory from
sourceLocation to targetLocation. |
static File |
link(File sourceLocation,
File targetLocation,
boolean overwrite)
Links the specified file or directory from
sourceLocation to targetLocation. |
static File |
move(File sourceLocation,
File targetDirectory)
Moves the specified file or directory from
sourceLocation to targetDirectory. |
static void |
setTempDirectory(File tmpDir)
Sets the webapp's temporary directory.
|
static boolean |
supportsLinking(File sourceLocation,
File targetLocation)
Returns
true if the operating system as well as the disk layout support creating a hard link from
src to dest. |
public static final int DELETE_FILES
public static final int DELETE_ROOT
public static final int DELETE_CONTENT
public static File move(File sourceLocation, File targetDirectory) throws IOException
sourceLocation to targetDirectory. If
targetDirectory does not exist, it will be created.sourceLocation - the source file or directorytargetDirectory - the target directoryIOExceptionpublic static File copy(File sourceLocation, File targetLocation) throws IOException
sourceLocation to targetLocation and returns a reference
to the newly created file or directory.
If targetLocation is an existing directory, then the source file or directory will be copied into this
directory, otherwise the source file will be copied to the file identified by targetLocation.
Note that existing files and directories will be overwritten.
Also note that if targetLocation is a directory than the directory itself, not only its content is
copied.
sourceLocation - the source file or directorytargetLocation - the directory to copy the source file or directory toIOException - if copying of the file or directory failedpublic static File copy(File sourceFile, File targetFile, boolean overwrite) throws IOException
sourceLocation to targetLocation and returns a reference to the
newly created file or directory.
If targetLocation is an existing directory, then the source file or directory will be copied into this
directory, otherwise the source file will be copied to the file identified by targetLocation.
If overwrite is set to false, this method throws an IOException if the target
file already exists.
Note that if targetLocation is a directory than the directory itself, not only its content is copied.
sourceFile - the source file or directorytargetFile - the directory to copy the source file or directory tooverwrite - true to overwrite existing filesIOException - if copying of the file or directory failedpublic static void copyContent(File sourceDirectory, File targetDirectory, boolean overwrite) throws IOException
sourceDirectory to
targetDirectory.
If overwrite is set to false, this method throws an IOException if the target
file already exists.
sourceDirectory - the source directorytargetDirectory - the target directory to copy the content of the source directory tooverwrite - true to overwrite existing filesIOException - if copying failspublic static void copyContent(File sourceDirectory, File targetDirectory) throws IOException
sourceDirectory to
targetDirectory.
Note that existing files and directories will be overwritten.
sourceDirectory - the source directorytargetDirectory - the target directory to copy the content of the source directory toIOException - if copying failspublic static File link(File sourceLocation, File targetLocation) throws IOException
sourceLocation to targetLocation. If
targetLocation does not exist, it will be created, if the target file already exists, an
IOException will be thrown.
If this fails (because linking is not supported on the current filesystem, then a copy is made.
sourceLocation - the source file or directorytargetLocation - the targetLocationIOException - if linking of the file or directory failedpublic static File link(File sourceLocation, File targetLocation, boolean overwrite) throws IOException
sourceLocation to targetLocation. If
targetLocation does not exist, it will be created.
If this fails (because linking is not supported on the current filesystem, then a copy is made.
Ifoverwrite is set to false, this method throws an IOException if the target
file already exists.sourceLocation - the source file or directorytargetLocation - the targetLocationoverwrite - true to overwrite existing filesIOException - if linking of the file or directory failedpublic static boolean supportsLinking(File sourceLocation, File targetLocation)
true if the operating system as well as the disk layout support creating a hard link from
src to dest. Note that this implementation requires two files rather than directories and
will overwrite any existing file that might already be present at the destination.sourceLocation - the source filetargetLocation - the target filetrue if the link was created, false otherwhisepublic static boolean deleteHierarchyIfEmpty(File limit, File start)
start up to directory limit if they are empty. Directory
limit is exclusive and will not be deleted.public static boolean isParent(File a, File b)
a is a parent of b. This can only be the case if a is a directory
and a sub path of b. isParent(a, a) == true.public static boolean delete(File f) throws IOException
true if the file was deleted.
If f is a directory, it will only be deleted if it doesn't contain any other files or directories. To
do a recursive delete, you may use delete(File, boolean).
f - the file or directoryIOExceptiondelete(File, boolean)public static boolean deleteQuietly(File f)
delete(File) but does not throw any IO exceptions.
In case of an IOException it will only be logged at warning level and the method returns false.public static boolean deleteQuietly(File f, boolean recurse)
delete(File, boolean) but does not throw any IO exceptions.
In case of an IOException it will only be logged at warning level and the method returns false.public static boolean delete(File f, boolean recurse) throws IOException
true if the file was deleted.
In the case that f references a directory, it will only be deleted if it doesn't contain other files
or directories, unless recurse is set to true.
f - the file or directoryrecurse - true to do a recursive deletes for directoriesIOExceptionpublic static boolean delete(File dir, int mode)
dir and, if specified, the directory itself. If dir is a
normal file it will always be deleted.public static void setTempDirectory(File tmpDir) throws IllegalArgumentException, IllegalStateException
tmpDir - the new temporary directoryIllegalArgumentException - if the file object doesn't represent a directoryIllegalStateException - if the directory is write protectedpublic static File getTempDirectory()
public static File getTempDirectory(String subdir)
subdir inside the webapp's temporary work directory.subdir - name of the subdirectoryCopyright © 2009–2020 Opencast Project. All rights reserved.