public abstract class AbstractFileSystem extends Object implements FileSystem
FileSystem| Constructor and Description |
|---|
AbstractFileSystem(String basePath) |
| Modifier and Type | Method and Description |
|---|---|
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,
Object... params) |
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(org.mule.runtime.api.metadata.MediaType originalMediaType,
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,FileAttributes>> |
list(FileConnectorConfig config,
String directoryPath,
boolean recursive,
org.mule.runtime.api.metadata.MediaType mediaType,
Predicate<FileAttributes> matcher)
Lists all the files in the
directoryPath which match the given matcher. |
PathLock |
lock(Path path,
Object... params)
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,FileAttributes> |
read(FileConnectorConfig config,
String filePath,
org.mule.runtime.api.metadata.MediaType mediaType,
boolean lock)
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,
String encoding)
Writes the
content into the file pointed by filePath. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchangeToBaseDir, getAttributesTypepublic 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()
CreateDirectoryCommandpublic List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,FileAttributes>> list(FileConnectorConfig config, String directoryPath, boolean recursive, org.mule.runtime.api.metadata.MediaType mediaType, Predicate<FileAttributes> 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.
If recursive is set to true but a found directory is rejected by the matcher, then there won't be any
recursion into such directory.
list in interface FileSystemconfig - the config that is parameterizing this operationdirectoryPath - the path to the directory to be listedrecursive - whether to include the contents of sub-directoriesmediaType - the MediaType of the message which entered the operationmatcher - 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 org.mule.runtime.extension.api.runtime.operation.Result<InputStream,FileAttributes> read(FileConnectorConfig config, String filePath, org.mule.runtime.api.metadata.MediaType mediaType, 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 FileSystemconfig - the config that is parameterizing this operationfilePath - the path of the file you want to readmediaType - The MediaType of the message that on which this operations is being executedlock - 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 void write(String filePath, InputStream content, FileWriteMode mode, boolean lock, boolean createParentDirectories, String encoding)
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, MediaType, boolean) method
write in interface FileSystemfilePath - 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 copy(FileConnectorConfig config, String sourcePath, String targetDirectory, boolean overwrite, boolean createParentDirectories, String renameTo)
sourcePath into the targetPath.
If targetPath doesn't exists, 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 FileSystemconfig - 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 move(FileConnectorConfig config, String sourcePath, String targetDirectory, boolean overwrite, boolean createParentDirectories, String renameTo)
sourcePath into the targetPath.
If targetPath doesn't exists, 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 FileSystemconfig - 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 FileSystemfilePath - the path to the file to be deletedpublic final void rename(String filePath, String newName, boolean overwrite)
filePath to the provided newNamerename in interface FileSystemfilePath - 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 FileSystemdirectoryName - the new directory's pathpublic final PathLock lock(Path path, Object... params)
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 FileSystempath - the path to the file you want to lockparams - vararg of generic arguments depending on the underlying implementationPathLockpublic org.mule.runtime.api.metadata.MediaType getFileMessageMediaType(org.mule.runtime.api.metadata.MediaType originalMediaType,
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 FileSystemoriginalMediaType - the original MediaType that the Message had before executing the operationattributes - 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 FileSystempath - the path to testpublic Lock createMuleLock(String lockId)
createMuleLock in interface FileSystempublic String getBasePath()
getBasePath in interface FileSystemCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.