public class StandardFileSystemOperations extends Object
| Constructor and Description |
|---|
StandardFileSystemOperations() |
| Modifier and Type | Method and Description |
|---|---|
void |
copy(FileConnectorConfig config,
FileSystem fileSystem,
String sourcePath,
String targetPath,
boolean overwrite,
boolean createParentDirectories,
Event event)
Copies the file at the
sourcePath into the targetPath. |
void |
createDirectory(FileSystem fileSystem,
String directoryPath)
Creates a new directory on
directoryPath |
void |
delete(FileSystem fileSystem,
String path,
Event event)
Deletes the file pointed by
path, provided that it's not locked |
TreeNode |
list(FileConnectorConfig config,
FileSystem fileSystem,
String directoryPath,
boolean recursive,
org.mule.runtime.api.message.Message message,
FilePredicateBuilder matchWith)
Lists all the files in the
directoryPath which match the given matcher. |
void |
move(FileConnectorConfig config,
FileSystem fileSystem,
String sourcePath,
String targetPath,
boolean overwrite,
boolean createParentDirectories,
Event event)
Moves the file at the
sourcePath into the targetPath. |
org.mule.runtime.extension.api.runtime.operation.Result<InputStream,FileAttributes> |
read(FileConnectorConfig config,
FileSystem fileSystem,
org.mule.runtime.api.message.Message message,
String path,
boolean lock)
Obtains the content and metadata of a file at a given path.
|
void |
rename(FileSystem fileSystem,
String path,
String to,
boolean overwrite,
Event event)
Renames the file pointed by
path to the name provided on the to parameter |
void |
write(FileConnectorConfig config,
FileSystem fileSystem,
String path,
Object content,
FileWriteMode mode,
boolean lock,
boolean createParentDirectories,
String encoding,
Event event)
Writes the
content into the file pointed by path. |
@Summary(value="List all the files from given directory") @OutputResolver(output=FileTreeNodeMetadataResolver.class) public TreeNode list(@UseConfig FileConnectorConfig config, @Connection FileSystem fileSystem, @Optional String directoryPath, @Optional(defaultValue="false") boolean recursive, org.mule.runtime.api.message.Message message, @Optional @Summary(value="Matcher to filter the listed files") FilePredicateBuilder matchWith)
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 parameter.
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-directories. Defaults to false.message - the Message on which this operation was triggeredmatchWith - a matcher used to filter the output listTreeNode object representing the listed directoryIllegalArgumentException - if directoryPath points to a file which doesn't exists or is not a directory@DataTypeParameters @Summary(value="Obtains the content and metadata of a file at a given path") public org.mule.runtime.extension.api.runtime.operation.Result<InputStream,FileAttributes> read(@UseConfig FileConnectorConfig config, @Connection FileSystem fileSystem, org.mule.runtime.api.message.Message message, @DisplayName(value="File Path") String path, @Optional(defaultValue="false") boolean lock)
Message which payload is a
InputStream with the file's content, and the metadata is represent as a FileAttributes object that's placed
as the message attributes.
If the lock parameter is set to true, then a file system level lock will be placed on the file until the
input stream this operation returns is closed or fully consumed. Because the lock is actually provided by the host file
system, its behavior might change depending on the mounted drive and the operation system on which mule is running. Take that
into consideration before blindly relying on this lock.
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. The user also has the chance to force the output enconding and
mimeType through the outputEncoding and outputMimeType optional parameters.
config - the config that is parameterizing this operationfileSystem - a reference to the host FileSystemmessage - the incoming Messagepath - the path to the file to be readlock - whether or not to lock the file. Defaults to false.FileAttributes instanceIllegalArgumentException - if the file at the given path doesn't exists@Summary(value="Writes the given \"Content\" in the file pointed by \"Path\"")
public void write(@UseConfig
FileConnectorConfig config,
@Connection
FileSystem fileSystem,
@Optional
String path,
@Content @Summary(value="Content to be written into the file")
Object content,
@Optional(defaultValue="OVERWRITE") @Summary(value="How the file is going to be written") @DisplayName(value="Write Mode")
FileWriteMode mode,
@Optional(defaultValue="false")
boolean lock,
@Optional(defaultValue="true")
boolean createParentDirectories,
@Optional @Summary(value="Encoding when trying to write a String file. If not set, defaults to the configuration one or the Mule default")
String encoding,
Event event)
content into the file pointed by path.
The content can be of any of the given types:
StringString[]bytebyte[]OutputHandlerIterableIterator
null contents are not allowed and will result in an IllegalArgumentException.
To support pass-through scenarios, the path attribute is optional. If not provided, then the current
Message.getAttributes() value will be tested to be an instance of FileAttributes, in which case
FileAttributes.getPath() will be used. If that's not the case, then an IllegalArgumentException will be
thrown.
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 operation also supports locking support depending on the value of the lock argument, but following the same
rules and considerations as described in the read operation.
config - the FileConnectorConfig on which the operation is being executedfileSystem - a reference to the host FileSystempath - the path of the file to be writtencontent - the content to be written into the file. Defaults to the current Message payloadmode - a FileWriteMode. Defaults to OVERWRITElock - whether or not to lock the file. Defaults to falsecreateParentDirectories - whether or not to attempt creating any parent directories which don't exists.encoding - when content is a String, this attribute specifies the encoding to be used when writing. If
not set, then it defaults to FileConnectorConfig.getDefaultWriteEncoding()event - The current EventIllegalArgumentException - if an illegal combination of arguments is supplied@Summary(value="Copies a file in another directory")
public void copy(@UseConfig
FileConnectorConfig config,
@Connection
FileSystem fileSystem,
@Optional
String sourcePath,
String targetPath,
@Optional(defaultValue="false")
boolean overwrite,
@Optional(defaultValue="true")
boolean createParentDirectories,
Event event)
sourcePath into the targetPath.
To support pass-through scenarios, the sourcePath attribute is optional. If not provided, then the current
Message.getAttributes() value will be tested to be an instance of FileAttributes, in which case
FileAttributes.getPath() will be used. If that's not the case, then an IllegalArgumentException will be
thrown.
If targetPath doesn't exists, and neither does its parent, then an attempt will be made to create depending on the
value of the createParentFolder argument. If such argument is , then an IllegalArgumentException will
be thrown.
If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise,
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
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 operationfileSystem - a reference to the host FileSystemsourcePath - the path to the file to be copiedtargetPath - the target directory where the file is going to be copiedoverwrite - 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.event - the Event which triggered this operationIllegalArgumentException - if an illegal combination of arguments is supplied@Summary(value="Moves a file to another directory")
public void move(@UseConfig
FileConnectorConfig config,
@Connection
FileSystem fileSystem,
@Optional
String sourcePath,
String targetPath,
@Optional(defaultValue="false")
boolean overwrite,
@Optional(defaultValue="true")
boolean createParentDirectories,
Event event)
sourcePath into the targetPath.
To support pass-through scenarios, the sourcePath attribute is optional. If not provided, then the current
Message.getAttributes() value will be tested to be an instance of FileAttributes, in which case
FileAttributes.getPath() will be used. If that's not the case, then an IllegalArgumentException will be
thrown.
If targetPath doesn't exists, and neither does its parent, then an attempt will be made to create depending on the
value of the createParentFolder argument. If such argument is false, then an IllegalArgumentException
will be thrown.
If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise,
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 copied to the a/c/ directory but renamed as test.json
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 operationfileSystem - a reference to the host FileSystemsourcePath - 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.event - The current EventIllegalArgumentException - if an illegal combination of arguments is supplied@Summary(value="Deletes a file")
public void delete(@Connection
FileSystem fileSystem,
@Optional
String path,
Event event)
path, provided that it's not locked
To support pass-through scenarios, the path attribute is optional. If not provided, then the current
Message.getAttributes() value will be tested to be an instance of FileAttributes, in which case
FileAttributes.getPath() will be used. If that's not the case, then an IllegalArgumentException will be
thrown.
fileSystem - a reference to the host FileSystempath - the path to the file to be deletedevent - The current EventIllegalArgumentException - if filePath doesn't exists or is locked@Summary(value="Renames a file")
public void rename(@Connection
FileSystem fileSystem,
@Optional
String path,
@DisplayName(value="New Name")
String to,
@Optional(defaultValue="false")
boolean overwrite,
Event event)
path to the name provided on the to parameter
To support pass-through scenarios, the path attribute is optional. If not provided, then the current
Message.getAttributes() value will be tested to be an instance of FileAttributes, in which case
FileAttributes.getPath() will be used. If that's not the case, then an IllegalArgumentException will be
thrown.
to argument should not contain any path separator. IllegalArgumentException will be thrown if this
precondition is not honored.
fileSystem - a reference to the host FileSystempath - the path to the file to be renamedto - the file's new nameoverwrite - whether or not overwrite the file if the target destination already exists.event - The current Event@Summary(value="Creates a new directory")
public void createDirectory(@Connection
FileSystem fileSystem,
String directoryPath)
directoryPathfileSystem - a reference to the host FileSystemdirectoryPath - the new directory's nameCopyright © 2003–2016 MuleSoft, Inc.. All rights reserved.