F - the generic type of the FileSystem on which the operation is performedI - generic type for a class that identifies a file or directory.public abstract class AbstractFileCommand<F extends FileSystem,I> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected F |
fileSystem |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractFileCommand(F fileSystem)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
FileAlreadyExistsException |
alreadyExistsException(I path)
Returns a
IllegalPathException explaining that an operation is trying to write to the given path but it
already exists and no overwrite instruction was provided. |
protected void |
assureParentFolderExists(I path,
boolean createParentFolder)
Method that, given a path, checks if its parent folder exists.
|
protected IllegalPathException |
cannotListFileException(I path)
Returns a
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file. |
protected IllegalPathException |
cannotReadDirectoryException(I path)
Returns an
IllegalPathException explaining that a
FileSystem.read(FileConnectorConfig, String, boolean) operation was attempted on a path pointing to
a directory |
protected abstract void |
doMkDirs(I directoryPath)
Creates the directory pointed by
directoryPath. |
RuntimeException |
exception(String message)
Returns a properly formatted
MuleRuntimeException for the given message and cause |
RuntimeException |
exception(String message,
Exception cause)
Returns a properly formatted
MuleRuntimeException for the given message and cause |
protected abstract boolean |
exists(I path)
Returns true if the given
path exists |
protected abstract I |
getAbsolutePath(I path)
Returns an object representing the absolute path for the given path.
|
protected abstract I |
getBasePath(FileSystem fileSystem)
Returns a path to which all non absolute paths are relative to
|
protected abstract I |
getParent(I path)
Returns the parent path, or
null if this path does not
have a parent. |
protected boolean |
isVirtualDirectory(String fileName) |
protected void |
mkdirs(I directoryPath)
Creates the directory pointed by
directoryPath also creating any missing parent directories |
protected IllegalPathException |
pathNotFoundException(I path)
Returns a
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file. |
protected abstract String |
pathToString(I path) |
protected I |
resolveExistingPath(String filePath)
Similar to
resolvePath(String) only that it throws a IllegalArgumentException if the
given path doesn't exist. |
protected abstract I |
resolvePath(I basePath,
String filePath)
Resolve the given basePath against the filePath.
|
protected I |
resolvePath(String filePath)
Returns an absolute path for the given
filePath |
protected final F extends FileSystem fileSystem
protected AbstractFileCommand(F fileSystem)
fileSystem - the FileSystem on which the operation is performedprotected abstract boolean exists(I path)
path existspath - the path to testpath existsprotected void assureParentFolderExists(I path, boolean createParentFolder)
void.
Otherwise, this method allows to create such parent by setting the the createParentFolder parameter to true. If it
is set to false and the parent folder does not exist, this method throws IllegalPathException.path - the path to testcreateParentFolder - indicates whether to create the parent folder or not.{@link - IllegalPathException} if the parent path does not exists and createParentFolder is set to false.protected void mkdirs(I directoryPath)
directoryPath also creating any missing parent directoriesdirectoryPath - the path to the directory you want to createprotected I resolvePath(String filePath)
filePathfilePath - the relative path to a file or directoryprotected boolean isVirtualDirectory(String fileName)
fileName - the name of a filetrue if fileName equals to "." or ".."protected I resolveExistingPath(String filePath)
resolvePath(String) only that it throws a IllegalArgumentException if the
given path doesn't exist.
The existence of the obtained path is verified by delegating into #exists(I)
filePath - the path to a file or directoryprotected IllegalPathException cannotReadDirectoryException(I path)
IllegalPathException explaining that a
FileSystem.read(FileConnectorConfig, String, boolean) operation was attempted on a path pointing to
a directorypath - the path on which a read was attemptedIllegalPathExceptionprotected IllegalPathException cannotListFileException(I path)
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file.path - the path on which a list was attemptedIllegalPathExceptionprotected IllegalPathException pathNotFoundException(I path)
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file.path - the on which a list was attemptedRuntimeExceptionpublic FileAlreadyExistsException alreadyExistsException(I path)
IllegalPathException explaining that an operation is trying to write to the given path but it
already exists and no overwrite instruction was provided.path - the that the operation tried to modifyIllegalPathExceptionpublic RuntimeException exception(String message)
MuleRuntimeException for the given message and causemessage - the exception's messageRuntimeExceptionpublic RuntimeException exception(String message, Exception cause)
MuleRuntimeException for the given message and causemessage - the exception's messagecause - the exception's causeRuntimeExceptionprotected abstract I getParent(I path)
null if this path does not
have a parent.
The parent of this path object consists of this path's root
component, if any, and each element in the path except for the
farthest from the root in the directory hierarchy. This method
does not access the file system; the path or its parent may not exist.
Furthermore, this method does not eliminate special names such as "."
and ".." that may be used in some implementations. On UNIX for example,
the parent of "/a/b/c" is "/a/b", and the parent of
"x/y/." is "x/y".
protected abstract I getBasePath(FileSystem fileSystem)
fileSystem - the file system that we're connecting tonull base path for the filesystemprotected abstract I resolvePath(I basePath, String filePath)
If the filePath parameter is an absolute
path then this method trivially returns filePath. If filePath
is an empty path then this method trivially returns basePath.
Otherwise this method considers the basePath to be a directory and resolves
the given filePath against the basePath. In the simplest case, the given filePath
does not have a root component, in which case this method
joins both paths and returns a resulting path
that ends with the given filePath. Where the given filePath has
a root component then resolution is highly implementation dependent and
therefore unspecified.
basePath - the base path considered as a directoryfilePath - the path to resolve against the basePathprotected abstract I getAbsolutePath(I path)
If the given path is already absolute then this method simply returns it. Otherwise, this method resolves the path in an implementation dependent manner, typically by resolving the path against a file system default directory. Depending on the implementation, this method may throw an I/O error if the file system is not accessible.
path - the given pathprotected abstract String pathToString(I path)
<I> as a String.protected abstract void doMkDirs(I directoryPath)
directoryPath.directoryPath - the path to the directory you want to createCopyright © 2003–2019 MuleSoft, Inc.. All rights reserved.