F - the generic type of the FileSystem on which the operation is performedpublic abstract class FileCommand<F extends FileSystem> extends AbstractFileCommand<F,Path>
AbstractFileCommand for local file systems which use Path to identify and manage
files and directories.fileSystem| Modifier | Constructor and Description |
|---|---|
protected |
FileCommand(F fileSystem)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
FileAlreadyExistsException |
alreadyExistsException(Path 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(Path path,
boolean createParentFolder)
Method that, given a path, checks if its parent folder exists.
|
protected IllegalPathException |
cannotListFileException(Path 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(Path 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(Path directoryPath)
Creates the directory pointed by
directoryPath. |
protected abstract boolean |
exists(Path path)
Returns true if the given
path exists |
protected Path |
getAbsolutePath(Path path)
Returns an object representing the absolute path for the given path.
|
protected abstract Path |
getBasePath(FileSystem fileSystem)
Returns a path to which all non absolute paths are relative to
|
protected Path |
getParent(Path path)
Returns the parent path, or
null if this path does not
have a parent. |
protected void |
mkdirs(Path directoryPath)
Creates the directory pointed by
directoryPath also creating any missing parent directories |
protected IllegalPathException |
pathNotFoundException(Path path)
Returns a
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file. |
protected String |
pathToString(Path path) |
protected Path |
resolveExistingPath(String filePath)
Similar to
AbstractFileCommand.resolvePath(String) only that it throws a IllegalArgumentException if the
given path doesn't exist. |
protected Path |
resolvePath(Path basePath,
String filePath)
Resolve the given basePath against the filePath.
|
protected Path |
resolvePath(String filePath)
Returns an absolute path for the given
filePath |
exception, exception, isVirtualDirectoryprotected FileCommand(F fileSystem)
fileSystem - the FileSystem on which the operation is performedprotected String pathToString(Path path)
pathToString in class AbstractFileCommand<F extends FileSystem,Path><I> as a String.protected Path getAbsolutePath(Path 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.
getAbsolutePath in class AbstractFileCommand<F extends FileSystem,Path>path - the given pathPathprotected Path getParent(Path 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".
getParent in class AbstractFileCommand<F extends FileSystem,Path>Pathprotected Path resolvePath(Path 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.
resolvePath in class AbstractFileCommand<F extends FileSystem,Path>basePath - the base path considered as a directoryfilePath - the path to resolve against the basePathPathprotected abstract boolean exists(Path path)
path existsexists in class AbstractFileCommand<F extends FileSystem,Path>path - the path to testPath existsprotected abstract Path getBasePath(FileSystem fileSystem)
getBasePath in class AbstractFileCommand<F extends FileSystem,Path>fileSystem - the file system that we're connecting toPath existsprotected abstract void doMkDirs(Path directoryPath)
directoryPath.doMkDirs in class AbstractFileCommand<F extends FileSystem,Path>directoryPath - the path to the directory you want to createprotected void assureParentFolderExists(Path 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.assureParentFolderExists in class AbstractFileCommand<F extends FileSystem,Path>path - the path to testcreateParentFolder - indicates whether to create the parent folder or not.protected void mkdirs(Path directoryPath)
directoryPath also creating any missing parent directoriesmkdirs in class AbstractFileCommand<F extends FileSystem,Path>directoryPath - the path to the directory you want to createprotected Path resolvePath(String filePath)
filePathresolvePath in class AbstractFileCommand<F extends FileSystem,Path>filePath - the relative path to a file or directoryPath existsprotected Path resolveExistingPath(String filePath)
AbstractFileCommand.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)
resolveExistingPath in class AbstractFileCommand<F extends FileSystem,Path>filePath - the path to a file or directoryPathprotected IllegalPathException cannotReadDirectoryException(Path path)
IllegalPathException explaining that a
FileSystem.read(FileConnectorConfig, String, boolean) operation was attempted on a path pointing to
a directorycannotReadDirectoryException in class AbstractFileCommand<F extends FileSystem,Path>path - the path on which a read was attemptedIllegalPathExceptionprotected IllegalPathException cannotListFileException(Path path)
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file.cannotListFileException in class AbstractFileCommand<F extends FileSystem,Path>path - the path on which a list was attemptedIllegalPathExceptionprotected IllegalPathException pathNotFoundException(Path path)
IllegalPathException explaining that a
FileSystem.list(FileConnectorConfig, String, boolean, Predicate) operation was attempted on a path
pointing to a file.pathNotFoundException in class AbstractFileCommand<F extends FileSystem,Path>path - the on which a list was attemptedIllegalPathExceptionpublic FileAlreadyExistsException alreadyExistsException(Path path)
IllegalPathException explaining that an operation is trying to write to the given path but it
already exists and no overwrite instruction was provided.alreadyExistsException in class AbstractFileCommand<F extends FileSystem,Path>path - the that the operation tried to modifyIllegalPathExceptionCopyright © 2003–2019 MuleSoft, Inc.. All rights reserved.