public final class StorageUtils extends Object
This class wraps instance of StorageEditor for
all file content related operations, like deleting, copying and moving of file/directory
content on the file system. Note, that all exceptions thrown by the editor need to be handled
by a caller of the StorageUtils API itself.
| Modifier and Type | Method and Description |
|---|---|
static int |
copyDirectories(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String... fromPaths)
Copies all directories at the given fromPaths on the file system.
|
static int |
copyDirectories(int flags,
String toPath,
String... fromPaths)
Same as
copyDirectories(int, FileFilter, FilenameFilter, String, String...)
with null filters. |
static boolean |
copyDirectory(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String fromPath)
Wrapped
StorageEditor.copyDirectoryContent(int, File, File, FileFilter, FilenameFilter)
upon this utils editor instance. |
static boolean |
copyDirectory(int flags,
String toPath,
String fromPath)
Same as
copyDirectory(int, FileFilter, FilenameFilter, String, String)
with null filters. |
static boolean |
copyFile(int flags,
String toPath,
String fromPath)
Wrapped
StorageEditor.copyFileContent(int, File, File)
upon this utils editor instance. |
static int |
copyFiles(int flags,
String toPath,
String... fromPaths)
Copies all files at the given fromPaths on the file system.
|
static int |
createDirectories(String... paths)
Same as
createDirectories(String, String...) with empty basePath. |
static int |
createDirectories(String basePath,
String... paths)
Creates all directories at the given paths on the file system.
|
static boolean |
createDirectory(String path)
Creates a new empty directory at the specified path on the file system.
|
static boolean |
createFile(String path)
Creates a new empty File at the specified path on the file system.
|
static int |
createFiles(String... paths)
Same as
createFiles(String, String...) with empty basePath. |
static int |
createFiles(String basePath,
String... paths)
Creates all files at the given paths on the file system.
|
static int |
deleteDirectories(FileFilter filter,
FilenameFilter nameFilter,
String basePath,
String... paths)
Deletes all directories at the given paths on the file system.
|
static int |
deleteDirectories(String... paths)
Same as
deleteDirectories(String, String...) with empty basePath. |
static int |
deleteDirectories(String basePath,
String... paths)
Same as
deleteDirectories(FileFilter, FilenameFilter, String, String...)
with null filters. |
static boolean |
deleteDirectory(FileFilter filter,
FilenameFilter nameFilter,
String path)
Wrapped
StorageEditor.deleteDirectory(File, FileFilter, FilenameFilter)
upon this utils editor instance. |
static boolean |
deleteDirectory(String path)
Same as
deleteDirectory(FileFilter, FilenameFilter, String) with null filters. |
static boolean |
deleteFile(String path)
Deletes a file at the specified path on the file system.
|
static int |
deleteFiles(String... paths)
Same as
deleteFiles(String, String...) with empty basePath. |
static int |
deleteFiles(String basePath,
String... paths)
Deletes all files at the given paths on the file system.
|
static boolean |
directoryExists(String path)
Checks whether a directory at the specified path on the file system exists or not.
|
static boolean |
fileExists(String path)
Checks whether a file at the specified path on the file system exists or not.
|
static boolean |
isDirectoryEmpty(String path)
Checks whether a directory at the specified path contains any files/subdirectories
or not.
|
static int |
moveDirectories(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String... fromPaths)
Moves all directories at the given fromPaths on the file system.
|
static int |
moveDirectories(int flags,
String toPath,
String... fromPaths)
Same as
moveDirectories(int, FileFilter, FilenameFilter, String, String...)
with null filters. |
static boolean |
moveDirectory(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String fromPath)
Wrapped
StorageEditor.moveDirectoryContent(int, File, File, FileFilter, FilenameFilter)
upon this utils editor instance. |
static boolean |
moveDirectory(int flags,
String toPath,
String fromPath)
Same as
moveDirectory(int, FileFilter, FilenameFilter, String, String)
with null filters. |
static boolean |
moveFile(int flags,
String toPath,
String fromPath)
Wrapped
StorageEditor.moveFileContent(int, File, File)
upon this utils editor instance. |
static int |
moveFiles(int flags,
String toPath,
String... fromPaths)
Moves all files at the given fromPaths on the file system.
|
public static boolean fileExists(String path)
path - Path of the desired file to check.True if the given path points to file which at this time exists,
false if there is no file at the given path or it is a directory.public static boolean directoryExists(String path)
path - Path of the desired directory to check.True if the given path points to directory which at this time exists,
false if there is no directory at the given path or it is a file.public static boolean isDirectoryEmpty(String path)
path - Path of the desired directory to check.True if the given path points to directory which at this time exists and
doesn't contains any files/subdirectories, false if it doesn't exists or if it is
a file.public static boolean createFile(String path)
See File.createNewFile() for additional info.
path - Path of the desired file to be created.True if the requested file was successfully created or already exists,
false if at the specified path already exists a directory with the same path
or some IO error occurs.public static int createFiles(String... paths)
createFiles(String, String...) with empty basePath.public static int createFiles(String basePath, String... paths)
This is a bulk operation for createFile(String) method, so the given paths will be
looped to perform the requested action for each of them.
basePath - A path to be used as base for the given paths, in case when they represents
a relative paths.paths - Paths of the desired files to be created.public static boolean createDirectory(String path)
See File.mkdirs() for additional info.
path - Path of the desired directory to be created.True if the requested directory was successfully created or already exists,
false if at the specified path already exists a file with the same path or some
IO error occurs.public static int createDirectories(String... paths)
createDirectories(String, String...) with empty basePath.public static int createDirectories(String basePath, String... paths)
This is a bulk operation for createDirectory(String) method, so the given paths will
be looped to perform the requested action for each of them.
basePath - A path to be used as base for the given paths, in case when they represents
a relative paths.paths - Paths of the desired directories to be created.public static boolean deleteFile(String path)
path - Path to the desired file to be deleted.True if the requested file was successfully deleted, false
if it is actually a directory or it doesn't exists.public static int deleteFiles(String... paths)
deleteFiles(String, String...) with empty basePath.public static int deleteFiles(String basePath, String... paths)
This is a bulk operation for deleteFiles(String...) method, so the given paths will
be looped to perform the requested action for each of them.
basePath - A path to be used as base for the given paths, in case when they represents
a relative paths.paths - Paths to the desired files to be deleted.public static boolean deleteDirectory(String path)
deleteDirectory(FileFilter, FilenameFilter, String) with null filters.public static boolean deleteDirectory(FileFilter filter, FilenameFilter nameFilter, String path)
StorageEditor.deleteDirectory(File, FileFilter, FilenameFilter)
upon this utils editor instance.path - The path to be used to create directory parameter for editor.public static int deleteDirectories(String... paths)
deleteDirectories(String, String...) with empty basePath.public static int deleteDirectories(String basePath, String... paths)
deleteDirectories(FileFilter, FilenameFilter, String, String...)
with null filters.public static int deleteDirectories(FileFilter filter, FilenameFilter nameFilter, String basePath, String... paths)
This is a bulk operation for deleteDirectory(FileFilter, FilenameFilter, String)
method, so the given paths will be looped to perform the requested action for each of them.
basePath - A path to be used as base for the given paths, in case when they represents
a relative paths.paths - Paths to the desired directories to be deleted.public static boolean copyFile(int flags,
String toPath,
String fromPath)
throws IOException
StorageEditor.copyFileContent(int, File, File)
upon this utils editor instance.
Note, that the given toPath will be appended with a last path segment obtained from the given fromPath.
toPath - The path to be used to create fromFile parameter for editor.fromPath - The path to be used to create toFile parameter for editor.IOExceptionpublic static int copyFiles(int flags,
String toPath,
String... fromPaths)
throws IOException
This is a bulk operation for copyFile(int, String, String) method, so the given paths
will be looped to perform the requested action for each of them.
fromPaths - Paths to the desired files to be copied.IOExceptionpublic static boolean copyDirectory(int flags,
String toPath,
String fromPath)
throws IOException
copyDirectory(int, FileFilter, FilenameFilter, String, String)
with null filters.IOExceptionpublic static boolean copyDirectory(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String fromPath)
throws IOException
StorageEditor.copyDirectoryContent(int, File, File, FileFilter, FilenameFilter)
upon this utils editor instance.
Note, that the given toPath will be appended with a last path segment obtained from the given fromPath.
toPath - The path to be used to create fromDirectory parameter for editor.fromPath - The path to be used to create toDirectory parameter for editor.IOExceptionpublic static int copyDirectories(int flags,
String toPath,
String... fromPaths)
throws IOException
copyDirectories(int, FileFilter, FilenameFilter, String, String...)
with null filters.IOExceptionpublic static int copyDirectories(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String... fromPaths)
throws IOException
This is a bulk operation for copyDirectory(int, FileFilter, FilenameFilter, String, String)
method, so the given paths will be looped to perform the requested action for each of them.
fromPaths - Paths to the desired directories to be copied.IOExceptionpublic static boolean moveFile(int flags,
String toPath,
String fromPath)
throws IOException
StorageEditor.moveFileContent(int, File, File)
upon this utils editor instance.
Note, that the given toPath will be appended with a last path segment obtained from the given fromPath.
toPath - The path to be used to create fromFile parameter for editor.fromPath - The path to be used to create toFile parameter for editor.IOExceptionpublic static int moveFiles(int flags,
String toPath,
String... fromPaths)
throws IOException
This is a bulk operation for moveFile(int, String, String) method, so the given paths
will be looped to perform the requested action for each of them.
fromPaths - Paths to the desired files to be moved.IOExceptionpublic static boolean moveDirectory(int flags,
String toPath,
String fromPath)
throws IOException
moveDirectory(int, FileFilter, FilenameFilter, String, String)
with null filters.IOExceptionpublic static boolean moveDirectory(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String fromPath)
throws IOException
StorageEditor.moveDirectoryContent(int, File, File, FileFilter, FilenameFilter)
upon this utils editor instance.
Note, that the given toPath will be appended with a last path segment obtained from the given fromPath.
toPath - The path to be used to create fromDirectory parameter for editor.fromPath - The path to be used to create toDirectory parameter for editor.IOExceptionpublic static int moveDirectories(int flags,
String toPath,
String... fromPaths)
throws IOException
moveDirectories(int, FileFilter, FilenameFilter, String, String...)
with null filters.IOExceptionpublic static int moveDirectories(int flags,
FileFilter filter,
FilenameFilter nameFilter,
String toPath,
String... fromPaths)
throws IOException
This is a bulk operation for moveDirectory(int, FileFilter, FilenameFilter, String, String)
method, so the given paths will be looped to perform the requested action for each of them.
fromPaths - Paths to the desired directories to be moved.IOException