Important: tasks in the build system should use this interface to read from or write to the file system as this interface is RMI compatible. Client code can use this to transparently access files on computers which are available through network.
This interface is similar in functionality that FileSystemProvider would provide. It allows clients to access the file system in a similar way, while allowing RMI compatibility.
Each file provider bears a key to itself which uniquely identifiers its location. If two file provider keys equal, clients can be sure that they will operate on the same files if their functions are called with the same paths. See getProviderKey() and FileProviderKey.
If a function name contains the phrase "Recursively"
then client should expect that it will not throw a
DirectoryNotEmptyException if the deleted directory is not empty.
Clients can install file event listeners for a file provider to get notified about changes in the file system. Build system task implementations are usually not recommended to do this, unless very specific use-cases. If they do, use it with the caching support of SakerEnvironment.
File providers can be used to wrap each other, providing restricted or enhanced functionality for a subject file provider. An example for this is a file provider that mounts a directory therefor limits access to a directory on a subject by allowing access to it using a specified root. File providers are considered root file providers if they do not wrap a subject file provider. Root file providers are required to return a RootFileProviderKey instance from getProviderKey().
File providers operate exclusively on absolute paths. Passing a relative path to them can result in an IllegalArgumentException.
Any method is allowed to throw NullPointerException if a null
path is passed to them.
public static final CopyOption[] | Singleton instance for an empty copy options array. |
public static final LinkOption[] | Singleton instance for an empty link options array. |
public static final OpenOption[] | Singleton instance for an empty open options array. |
public static final int | Operation flag to specify that if directories are being recursively created, then intermediate already existing
files should be deleted. |
public static final int | Operation flag constant specifying no flags. |
public static final int | Operation flag to specify that if a directory is encountered, it shouldn't be recursively deleted. |
public static final int | Operation result flag representing that some directories were created. |
public static final int | Operation result flag representing that some files were deleted. |
public static final int | Operation result flag representing that no changes were issued. |
public ListenerToken | addFileEventListener( Adds a file event listener for the specified directory. |
public default void | Clears the directory and all subdirectories at the specified path. |
public void | createDirectories( Creates the directory and necessary parent directors at the given path. |
public void | Deletes a file or directory at the given path. |
public default NavigableSet< | deleteChildrenRecursivelyIfNotIn( Deletes the children of a directory recursively, if the name of a given child is not in the specified set. |
public void | deleteRecursively( Deletes a file or directory at the given path, recursively if it is a directory. |
public default int | deleteRecursivelyIfNotFileType( Deletes the file at the given path if the type of it is not the specified one. |
public default ByteSink | ensureWriteOpenOutput( Ensures a write request for the given path and opens an output stream to it. |
public int | ensureWriteRequest( Ensures that a write request to the given path can be initiated with the given type. |
public default ByteArrayRegion | getAllBytes( Gets all of the byte contents of the file at the specified path. |
public NavigableMap< | getDirectoryEntries( Gets the entries in the directory denoted by the argument path. |
public NavigableMap< | Collects the entries in the specified directory, recursively. |
public default Entry< | Gets the attributes of a file in the directory specified by the argument path. |
public default NavigableSet< | Gets the names of the files present in the directory denoted by the specified path. |
public FileEntry | getFileAttributes( Gets the attributes of the file at the specified path. |
public default Set< | Gets the posix file permissions of the file at the given path. |
public FileProviderKey | Gets the file provider key for this file provider. |
public NavigableSet< | getRoots() Gets the file system roots of this file provider. |
public default NavigableSet< | Gets the names of subdirectories in the directory denoted by the specified path. |
public default SakerFileProvider | Gets the file provider this file provider wraps. |
public default FileHashResult | hash( Creates a hash using the specified algorithm based on the contents of the file at the specified path. |
public default boolean | isChanged( Checks if the given attributes of a file at the specified path are the same or not. |
public default boolean | modifyPosixFilePermissions( Modifies the posix file permissions for the file at the given path. |
public void | moveFile( Moves a file from on location to another. |
public ByteSource | openInput( Opens an input stream to the file at the specified path. |
public ByteSink | openOutput( Opens an output stream to the file at the specified path. |
public default void | removeFileEventListeners( Removes the file listeners in a bulk operation. |
public default SakerPath | resolveWrappedPath( Resolves the parameter path in a way that the result can be used to access the same files using the file provider
returned from getWrappedProvider(). |
public default void | setFileBytes( Writes the specified bytes to the file at the given path. |
public void | setLastModifiedMillis( Sets the last modified time of the file at the given path. |
public default boolean | setPosixFilePermissions( Sets the posix file permissions for the file at the given path. |
public default long | writeTo( Writes the contents of the file at the given path to the specified output stream. |
public default long | writeToFile( Writes the contents from the given input stream to the specified output file path. |
This flag doesn't necessary prevent the deletion of empty directories.
If the specified directory doesn't exist, the provider can either fail or succeed for installing the listener.
Callers should keep a strong reference to the returned token, and call FileEventListener.ListenerToken.removeListener() when the listener is no longer needed. Removing all references to the returned token is not sufficient for removing the listener from the provider.
Listeners might receive events before this method finishes.
The listener will receive file event changes with file names which are a children of the specified directory.
This method follows symbolic links for retrieving the children, but doesn't when deleting the entries. Meaning, if a directory contains a link, the link will be deleted and the directory at the end of the link will not be cleared.
If the directories cannot be created due to a non-directory file is already present at the path or at one of its parent paths, the method will fail.
The method will fail if the path denotes a directory and it is not empty.
If the path denotes a symbolic link, only the link will be deleted.
If there is no file at the given path, the method will succeed, and won't throw an exception. Therefore this methods works in the manner of "delete if exists".
If a directory child is a directory, it will be recursively deleted, meaning any of its subdirectories will be deleted too.
This method doesn't follow symbolic links. Meaning, if a directory contains a link, the link will be deleted and the directory at the end of the link will not be cleared.
This method will delete all files at the given path, clearing the directory beforehand if necessary.
This method doesn't follow symbolic links. Links to directories will be deleted, the directories won't be cleared if they are not under the specified path.
This method reads the attributes at the given path, and deletes the file recursively if it doesn't match the expected.
The attribute reading follows symbolic links, the deletion doesn't.
The file type argument should be one of the file type constants in FileEntry.
The method works the same way as if ensureWriteRequest(
ensureWriteRequest(path, FileEntry.TYPE_FILE, operationflag); return openOutput(path, openoptions);
null
.This method examines the current file at the given path, and ensures that the file is either has the same type, or a write request can be initiated to it.
The argument file type and behaviour based on it is the following:
- FileEntry.TYPE_FILE: If there is a directory at the path, it will be deleted recursively*. If there
is a file at the path, no operation will be done as it can be overwritten. If not all parent directories exist at
the path, the parent directories will be created recursively. This ensures that a following
openOutput(
SakerPath, OpenOption...) can succeed.
* If the OPERATION_FLAG_NO_RECURSIVE_DIRECTORY_DELETE is specified, the encountered directory will only be deleted if it is empty. An exception is thrown instead if it is not empty. - FileEntry.TYPE_DIRECTORY: If there is a non-directory file at the path, it will be deleted. If there is a directory at the path, no operation will be done. If there is no file at the path, all directories will be created, including the one at the path as well.
This method is mainly useful to batch the attribute reading-deletion-file creation operations into one call, therefore ensuring that a given path is writeable for the given file type.
Note that this function is not atomic. The checking of the currently present file, deletions, and creation are not done atomically, therefore this method may fail if concurrent modifications distrupt it. It is recommended for callers to ensure private and synchronized access to the given path.
The result contains the file names mapped to their attributes.
This method follows symbolic links when determining the attributes.
This method contains every file entry that is under the specified directory and its subdirectories.
Use this method judiciously as a large number of files might be queried.
The file attribute values in the result map are mapped to their relative path based on the argument path.
This method follows symbolic links for directories and when determining attributes.
This method only returns non-null
if there is a directory at the denoted path, and in that directory
there is only one file. The attributes for the file is returned.
This method follows symbolic links when determining the attribute.
null
if no file or more than one was found.This method doesn't follow symbolic links.
The method will query the posix file permissions of the specified file if the underlying file system supports them.
The method does not throw an exception if the underlying filesystem doesn't support posix file permissions.
null
if the underlying filesystem doesn't support
them.null
.If this file provider is a root provider, then the result will be an instance of RootFileProviderKey.
File system roots do not change during the lifetime of a file provider. They are normalized according to the
rules of SakerPath.normalizeRoot(
Note: It can happen that some file system drives are changed during the lifetime of a file provider. (E.g. USB drive inserted/removed, etc...) The file provider implementations are not required to recognize these changes, and restarting the build system process might be required to handle the file system changes.
This method follows symbolic links when determining if an entry is considered a directory.
this
file provider wraps. Wrapping file providers can be useful to extend the wrapped file providers functionality.
If this method returns null
, then getProviderKey() should return an instance of
RootFileProviderKey.
If this method returns non-null
, then the file provider implementation must override and provide an
implementation resolveWrappedPath(
null
if this file provider is a root provider.This method will read the contents of the file at the specified path and use the appropriate MessageDigest to create a hash of its contents.
When using RMI, it is preferable to call this method instead of opening the stream on client side and reading the contents, as it can avoid transferring the whole content of the file over the network.
This method retrieves the attributes of the file at the path and compares the specified attributes.
true
if failed to retrieve the attributes, or the attributes changed.
The method takes two permission set arguments which control how the permissions should be modified. First all
permissions in the add
argument are added, then all permissions in the remove
argument
are removed.
The adding and removal are performed in a single filesystem operation.
If a permission is present in both add
and remove
permission sets, then it will be
removed.
The method does not throw an exception if the underlying filesystem doesn't support posix file permissions.
null
to not add anything.null
to not remove anything.true
if the underlying filesystem supports posix file permissions. false
otherwise.null
.The OpenOption argument must contain elements which are enumerations.
The returned stream is not thread-safe.
The caller must close the returned stream to properly persist the written bytes to the stream. If the caller doesn't close the stream, data corruption might occur. If the stream is not closed, the data may not have been written to the disk. Implementations may cache the written bytes and flush them when close() is called.
If this method successfully returns, that doesn't necessarily mean that the file has been opened. Opening related exceptions may be thrown by the writing or closing methods of the returned stream.
The OpenOption argument must contain elements which are enumerations.
The returned stream is not thread-safe.
To remove a single file listener call FileEventListener.ListenerToken.removeListener().
The file listeners might still receive some events after this call, as the events can occur out of order. Listeners should handle that scenario gracefully.
The method will silently ignore any null
elements in the argument.
This method will throw an UnsupportedOperationException if and only if this
file provider is
root file provider.
The returned path will access the same file using the wrapped file provider as this file provider would with the argument path.
null
.
The milliseconds are converted using FileTime.fromMillis(
This method will only set the file permissions if the underlying filesystem supports it. In that case the method
will return true
. Otherwise false
.
The method does not throw an exception if the underlying filesystem doesn't support posix file permissions.
true
if the underlying filesystem supports posix file permissions. false
otherwise.null
.