public abstract class AbstractFileSystem<A extends FileAttributes> extends Object implements FileSystem<A>
FileSystem| Constructor and Description |
|---|
AbstractFileSystem(String basePath) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
acquireLock(PathLock lock)
Attempts to lock the given
lock and throws FileLockedException if already locked |
void |
copy(FileConnectorConfig config,
String sourcePath,
String targetDirectory,
boolean overwrite,
boolean createParentDirectories,
String renameTo)
Copies the file at the
sourcePath into the targetPath. |
void |
createDirectory(String directoryName)
Creates a new directory
|
protected abstract PathLock |
createLock(Path path) |
Lock |
createMuleLock(String lockId) |
void |
delete(String filePath)
Deletes the file pointed by
filePath, provided that it's not locked |
String |
getBasePath() |
protected abstract CopyCommand |
getCopyCommand() |
protected abstract CreateDirectoryCommand |
getCreateDirectoryCommand() |
protected abstract DeleteCommand |
getDeleteCommand() |
org.mule.runtime.api.metadata.MediaType |
getFileMessageMediaType(FileAttributes attributes)
Creates a new
DataType to be associated with a Message which payload is a InputStream and the
attributes an instance of FileAttributes |
protected abstract ListCommand |
getListCommand() |
protected abstract MoveCommand |
getMoveCommand() |
protected abstract ReadCommand |
getReadCommand() |
protected abstract RenameCommand |
getRenameCommand() |
protected abstract WriteCommand |
getWriteCommand() |
protected boolean |
isLocked(Path path)
Try to acquire a lock on a file and release it immediately.
|
List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A>> |
list(FileConnectorConfig config,
String directoryPath,
boolean recursive,
Predicate<A> matcher)
Deprecated.
|
List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A>> |
list(FileConnectorConfig config,
String directoryPath,
boolean recursive,
Predicate<A> matcher,
Long timeBetweenSizeCheck)
Lists all the files in the
directoryPath which match the given matcher. |
PathLock |
lock(Path path)
Acquires and returns lock over the given
path. |
void |
move(FileConnectorConfig config,
String sourcePath,
String targetDirectory,
boolean overwrite,
boolean createParentDirectories,
String renameTo)
Moves the file at the
sourcePath into the targetPath. |
org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A> |
read(FileConnectorConfig config,
String filePath,
boolean lock)
Deprecated.
|
org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A> |
read(FileConnectorConfig config,
String filePath,
boolean lock,
Long timeBetweenSizeCheck)
Obtains the content and metadata of a file at a given path.
|
void |
rename(String filePath,
String newName,
boolean overwrite)
Renames the file pointed by
filePath to the provided newName |
void |
verifyNotLocked(Path path)
Verify that the given
path is not locked |
void |
write(String filePath,
InputStream content,
FileWriteMode mode,
boolean lock,
boolean createParentDirectories)
Writes the
content into the file pointed by filePath. |
void |
write(String filePath,
InputStream content,
FileWriteMode mode,
boolean lock,
boolean createParentDirectories,
String encoding)
Deprecated.
write(String, InputStream, FileWriteMode, boolean, boolean) must be used instead.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchangeToBaseDirpublic AbstractFileSystem(String basePath)
protected abstract ListCommand getListCommand()
ListCommandprotected abstract ReadCommand getReadCommand()
ReadCommandprotected abstract WriteCommand getWriteCommand()
WriteCommandprotected abstract CopyCommand getCopyCommand()
CopyCommandprotected abstract MoveCommand getMoveCommand()
MoveCommandprotected abstract DeleteCommand getDeleteCommand()
DeleteCommandprotected abstract RenameCommand getRenameCommand()
RenameCommandprotected abstract CreateDirectoryCommand getCreateDirectoryCommand()
CreateDirectoryCommand@Deprecated public List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A>> list(FileConnectorConfig config, String directoryPath, boolean recursive, Predicate<A> matcher)
directoryPath which match the given matcher.
If the listing encounters a directory, the output list will include its contents depending on the value of the
recursive argument. If recursive is enabled, then all the files in that directory will be
listed immediately after their parent directory.
list in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationdirectoryPath - the path to the directory to be listedrecursive - whether to include the contents of sub-directoriesmatcher - a Predicate of FileAttributes used to filter the output listList of Result objects, each one containing each file's content in the payload and metadata in the attributespublic List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A>> list(FileConnectorConfig config, String directoryPath, boolean recursive, Predicate<A> matcher, Long timeBetweenSizeCheck)
directoryPath which match the given matcher.
If the listing encounters a directory, the output list will include its contents depending on the value of the
recursive argument. If recursive is enabled, then all the files in that directory will be listed immediately
after their parent directory.
list in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationdirectoryPath - the path to the directory to be listedrecursive - whether to include the contents of sub-directoriesmatcher - a Predicate of FileAttributes used to filter the output listtimeBetweenSizeCheck - wait time between size checks to determine if a file is ready to be read in milliseconds.List of Result objects, each one containing each file's content in the payload and metadata in the
attributes@Deprecated public org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A> read(FileConnectorConfig config, String filePath, boolean lock)
Locking can be actually enabled through the lock argument, however, the extent of such lock will depend on the
implementation. What is guaranteed by passing true on the lock argument is that this instance will
not attempt to modify this file until the InputStream returned by Result.getOutput() this method
returns is closed or fully consumed. Some implementation might actually perform a file system level locking which goes beyond
the extend of this instance or even mule. For some other file systems that might be simply not possible and no extra
assumptions are to be taken.
This method also makes a best effort to determine the mime type of the file being read. a MimetypesFileTypeMap will
be used to make an educated guess on the file's mime type
read in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationfilePath - the path of the file you want to readlock - whether or not to lock the fileResult with an InputStream with the file's content as payload and a
FileAttributes object as Message.getAttributes()public org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A> read(FileConnectorConfig config, String filePath, boolean lock, Long timeBetweenSizeCheck)
Locking can be actually enabled through the lock argument, however, the extent of such lock will depend on the
implementation. What is guaranteed by passing true on the lock argument is that this instance will
not attempt to modify this file until the InputStream returned by Result.getOutput() this method returns is
closed or fully consumed. Some implementation might actually perform a file system level locking which goes beyond the extend
of this instance or even mule. For some other file systems that might be simply not possible and no extra assumptions
are to be taken.
This method also makes a best effort to determine the mime type of the file being read. a MimetypesFileTypeMap will
be used to make an educated guess on the file's mime type
read in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationfilePath - the path of the file you want to readlock - whether or not to lock the filetimeBetweenSizeCheck - wait time between size checks to determine if a file is ready to be read in milliseconds.Result with an InputStream with the file's content as payload and a FileAttributes object
as Message.getAttributes()@Deprecated public void write(String filePath, InputStream content, FileWriteMode mode, boolean lock, boolean createParentDirectories, String encoding)
write(String, InputStream, FileWriteMode, boolean, boolean) must be used instead.
write in interface FileSystem<A extends FileAttributes>filePath - the path of the file to be writtencontent - the content to be written into the filemode - a FileWriteModelock - whether or not to lock the filecreateParentDirectories - whether or not to attempt creating any parent directories which don't exists.encoding - when is a String, this attribute specifies the encoding to be used when writing. If
not set, then it defaults to FileConnectorConfig.getDefaultWriteEncoding()public void write(String filePath, InputStream content, FileWriteMode mode, boolean lock, boolean createParentDirectories)
content into the file pointed by filePath.
The content can be of any of the given types:
null contents are not allowed and will result in an IllegalArgumentException.
If the directory on which the file is attempting to be written doesn't exist, then the operation will either throw
IllegalArgumentException or create such folder depending on the value of the createParentDirectory.
If the file itself already exists, then the behavior depends on the supplied mode.
This method also supports locking support depending on the value of the lock argument, but following the same rules
and considerations as described in the FileSystem.read(FileConnectorConfig, String, boolean) method
write in interface FileSystem<A extends FileAttributes>filePath - the path of the file to be writtencontent - the content to be written into the filemode - a FileWriteModelock - whether or not to lock the filecreateParentDirectories - whether or not to attempt creating any parent directories which don't exists.public void copy(FileConnectorConfig config, String sourcePath, String targetDirectory, boolean overwrite, boolean createParentDirectories, String renameTo)
sourcePath into the targetPath.
If targetPath doesn't exist, and neither does its parent, then an attempt will be made to create depending on the
value of the createParentDirectory argument. If such argument is , then an IllegalArgumentException
will be thrown.
It is also possible to use the targetPath to specify that the copied file should also be renamed. For example, if
sourcePath has the value a/b/test.txt and targetPath is assigned to a/c/test.json, then the
file will indeed be copied to the a/c/ directory but renamed as test.json
If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise,
IllegalArgumentException will be thrown
As for the sourcePath, it can either be a file or a directory. If it points to a directory, then it will be copied
recursively
copy in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationsourcePath - the path to the file to be copiedtargetDirectory - the target directoryoverwrite - whether or not overwrite the file if the target destination already exists.createParentDirectories - whether or not to attempt creating any parent directories which doesn't exist.renameTo - the new file name, null if the file doesn't need to be renamedpublic void move(FileConnectorConfig config, String sourcePath, String targetDirectory, boolean overwrite, boolean createParentDirectories, String renameTo)
sourcePath into the targetPath.
If targetPath doesn't exist, and neither does its parent, then an attempt will be made to create depending on the
value of the createParentDirectory argument. If such argument is , then an IllegalArgumentException
will be thrown.
It is also possible to use the targetPath to specify that the moved file should also be renamed. For example, if
sourcePath has the value a/b/test.txt and targetPath is assigned to a/c/test.json, then the
file will indeed be moved to the a/c/ directory but renamed as test.json
If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise,
IllegalArgumentException will be thrown
As for the sourcePath, it can either be a file or a directory. If it points to a directory, then it will be moved
recursively
move in interface FileSystem<A extends FileAttributes>config - the config that is parameterizing this operationsourcePath - the path to the file to be copiedtargetDirectory - the target directoryoverwrite - whether or not overwrite the file if the target destination already exists.createParentDirectories - whether or not to attempt creating any parent directories which don't exists.renameTo - the new file name, null if the file doesn't need to be renamedpublic void delete(String filePath)
filePath, provided that it's not lockeddelete in interface FileSystem<A extends FileAttributes>filePath - the path to the file to be deletedpublic final void rename(String filePath, String newName, boolean overwrite)
filePath to the provided newNamerename in interface FileSystem<A extends FileAttributes>filePath - the path to the file to be renamednewName - the file's new nameoverwrite - whether or not overwrite the file if the target destination already exists.public void createDirectory(String directoryName)
createDirectory in interface FileSystem<A extends FileAttributes>directoryName - the new directory's pathpublic final PathLock lock(Path path)
path.
Depending on the underlying filesystem, the extent of the lock will depend on the implementation. If a lock can not be
acquired, then an IllegalStateException is thrown.
Whoever request the lock MUST release it as soon as possible.
lock in interface FileSystem<A extends FileAttributes>path - the path to the file you want to lockPathLockprotected void acquireLock(PathLock lock)
lock and throws FileLockedException if already lockedlock - the PathLock to be acquiredFileLockedException - if the lock is already acquiredpublic org.mule.runtime.api.metadata.MediaType getFileMessageMediaType(FileAttributes attributes)
DataType to be associated with a Message which payload is a InputStream and the
attributes an instance of FileAttributes
It will try to update the DataType.getMediaType() with a best guess derived from the given attributes. If no
best-guess is possible, then the originalDataType's mimeType is honoured.
As for the MediaType.getCharset(), the dataType one is respected
getFileMessageMediaType in interface FileSystem<A extends FileAttributes>attributes - the FileAttributes of the file being processedDataType the resulting DataType.protected boolean isLocked(Path path)
public void verifyNotLocked(Path path)
path is not lockedverifyNotLocked in interface FileSystem<A extends FileAttributes>path - the path to testpublic Lock createMuleLock(String lockId)
createMuleLock in interface FileSystem<A extends FileAttributes>public String getBasePath()
getBasePath in interface FileSystem<A extends FileAttributes>Copyright © 2003–2019 MuleSoft, Inc.. All rights reserved.