public interface FileSystem
This interface acts as a facade which allows performing common files operations regardless of those files being in a local disk, an FTP server, a cloud storage service, etc.
| Modifier and Type | Method and Description |
|---|---|
void |
changeToBaseDir()
Changes the current working directory to the user base
|
void |
copy(FileConnectorConfig config,
String sourcePath,
String targetPath,
boolean overwrite,
boolean createParentDirectories,
String renameTo)
Copies the file at the
sourcePath into the targetPath. |
void |
createDirectory(String directoryPath)
Creates a new directory
|
Lock |
createMuleLock(String id) |
void |
delete(String filePath)
Deletes the file pointed by
filePath, provided that it's not locked |
Class<? extends FileAttributes> |
getAttributesType()
The concrete class that represents the attributes related to the
FileSystem implementation. |
String |
getBasePath() |
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 |
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 targetPath,
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. |
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.
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 listmediaType - the MediaType of the message which entered the operationList of Result objects, each one containing each file's content in the payload and metadata in the attributesIllegalArgumentException - if directoryPath points to a file which doesn't exists or is not a directoryorg.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
config - 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()IllegalArgumentException - if the file at the given path doesn't existsvoid 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 read(FileConnectorConfig, String, MediaType, boolean) method
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()IllegalArgumentException - if an illegal combination of arguments is suppliedvoid copy(FileConnectorConfig config, String sourcePath, String targetPath, 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
config - the config that is parameterizing this operationsourcePath - the path to the file to be copiedtargetPath - 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 renamedIllegalArgumentException - if an illegal combination of arguments is suppliedvoid move(FileConnectorConfig config, String sourcePath, String targetPath, 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
config - the config that is parameterizing this operationsourcePath - the path to the file to be copiedtargetPath - 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 renamedIllegalArgumentException - if an illegal combination of arguments is suppliedvoid delete(String filePath)
filePath, provided that it's not lockedfilePath - the path to the file to be deletedIllegalArgumentException - if filePath doesn't exists or is lockedvoid rename(String filePath, String newName, boolean overwrite)
filePath to the provided newNamefilePath - 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.void createDirectory(String directoryPath)
directoryPath - the new directory's pathPathLock 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.
path - the path to the file you want to lockparams - vararg of generic arguments depending on the underlying implementationPathLockIllegalArgumentException - if a lock could not be acquiredorg.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
originalMediaType - the original MediaType that the Message had before executing the operationattributes - the FileAttributes of the file being processedDataType the resulting DataType.void verifyNotLocked(Path path)
path is not lockedpath - the path to testIllegalStateException - if the path is indeed lockedvoid changeToBaseDir()
Class<? extends FileAttributes> getAttributesType()
FileSystem implementation.
This method is called when handling the dynamic resolution for the output attributes metadata of an operation.
String getBasePath()
Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.