public interface FileSystem<A extends FileAttributes>
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 |
String |
getBasePath() |
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 |
List<org.mule.runtime.extension.api.runtime.operation.Result<InputStream,A>> |
list(FileConnectorConfig config,
String directoryPath,
boolean recursive,
Predicate<A> matcher)
Deprecated.
|
default 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 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,A> |
read(FileConnectorConfig config,
String filePath,
boolean lock)
Deprecated.
|
default 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 |
default 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.
Writes the content into the file pointed by filePath.
The
If the directory on which the file is attempting to be written doesn't exist, then the operation will either throw
If the file itself already exists, then the behavior depends on the supplied
This method also supports locking support depending on the value of the |
@Deprecated 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.
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 attributesIllegalArgumentException - if directoryPath points to a file which doesn't exist or is not a directorydefault 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.
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
attributesIllegalArgumentException - if directoryPath points to a file which doesn't exist or is not a directory@Deprecated 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
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()IllegalArgumentException - if the file at the given path doesn't existdefault 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
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()IllegalArgumentException - if the file at the given path doesn't exist@Deprecated void write(String filePath, InputStream content, FileWriteMode mode, boolean lock, boolean createParentDirectories, String encoding)
write(String, InputStream, FileWriteMode, boolean, boolean) must be used instead.
Writes the 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, 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 supplieddefault 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 read(FileConnectorConfig, String, 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.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 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
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 doesn't exist.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 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
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 exist 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)
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 lockPathLockIllegalArgumentException - if a lock could not be acquiredorg.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
attributes - 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()
String getBasePath()
Copyright © 2003–2019 MuleSoft, Inc.. All rights reserved.