Class FileSystem<ResourceIdT extends ResourceId>
- Direct Known Subclasses:
ClassLoaderFileSystem
It defines APIs for writing file systems agnostic code.
All methods are protected, and they are for file system providers to implement. Clients should
use the FileSystems utility.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcopy(List<ResourceIdT> srcResourceIds, List<ResourceIdT> destResourceIds) Copies aListof file-like resources from one location to another.protected abstract WritableByteChannelcreate(ResourceIdT resourceId, CreateOptions createOptions) Returns a write channel for the givenFileSystem.protected abstract voiddelete(Collection<ResourceIdT> resourceIds) Deletes a collection of resources.protected abstract StringGet the URI scheme which defines the namespace of theFileSystem.protected abstract List<MatchResult> This is the entry point to convert user-provided specs toResourceIds.protected abstract ResourceIdTmatchNewResource(String singleResourceSpec, boolean isDirectory) Returns a newResourceIdfor this filesystem that represents the named resource.protected abstract ReadableByteChannelopen(ResourceIdT resourceId) Returns a read channel for the givenFileSystem.protected abstract voidrename(List<ResourceIdT> srcResourceIds, List<ResourceIdT> destResourceIds, MoveOptions... moveOptions) Renames aListof file-like resources from one location to another.protected voidreportLineage(ResourceIdT resourceId, Lineage lineage) ReportLineagemetrics for resource id at file level.protected voidreportLineage(ResourceIdT unusedId, Lineage unusedLineage, FileSystem.LineageLevel level) ReportLineagemetrics for resource id to a given level.
-
Constructor Details
-
FileSystem
public FileSystem()
-
-
Method Details
-
match
This is the entry point to convert user-provided specs toResourceIds. Callers should usematch(java.util.List<java.lang.String>)to resolve users specs ambiguities before calling other methods.Implementation should handle the following ambiguities of a user-provided spec:
speccould be a glob or a uri.match(java.util.List<java.lang.String>)should be able to tell and choose efficient implementations.- The user-provided
specmight refer to files or directories. It is common that users that wish to indicate a directory will omit the trailing/, such as in a spec of"/tmp/dir". TheFileSystemshould be able to recognize a directory with the trailing/omitted, but should always return a correctFileSystem(e.g.,"/tmp/dir/"inside the returnedMatchResult.
All
FileSystemimplementations should support glob in the final hierarchical path component ofFileSystem. This allows SDK libraries to construct file system agnostic spec.FileSystemscan support additional patterns for user-provided specs.- Returns:
List<MatchResult>in the same order of the input specs.- Throws:
IllegalArgumentException- if specs are invalid.IOException- if all specs failed to match due to issues like: network connection, authorization. Exception for individual spec need to be deferred until callers retrieve metadata withMatchResult.metadata().
-
create
protected abstract WritableByteChannel create(ResourceIdT resourceId, CreateOptions createOptions) throws IOException Returns a write channel for the givenFileSystem.The resource is not expanded; it is used verbatim.
- Parameters:
resourceId- the reference of the file-like resource to createcreateOptions- the configuration of the create operation- Throws:
IOException
-
open
Returns a read channel for the givenFileSystem.The resource is not expanded; it is used verbatim.
If seeking is supported, then this returns a
SeekableByteChannel.- Parameters:
resourceId- the reference of the file-like resource to open- Throws:
IOException
-
copy
protected abstract void copy(List<ResourceIdT> srcResourceIds, List<ResourceIdT> destResourceIds) throws IOException Copies aListof file-like resources from one location to another.The number of source resources must equal the number of destination resources. Destination resources will be created recursively.
- Parameters:
srcResourceIds- the references of the source resourcesdestResourceIds- the references of the destination resources- Throws:
FileNotFoundException- if the source resources are missing. When copy throws, each resource might or might not be copied. In such scenarios, callers can usematch()to determine the state of the resources.IOException
-
rename
protected abstract void rename(List<ResourceIdT> srcResourceIds, List<ResourceIdT> destResourceIds, MoveOptions... moveOptions) throws IOException Renames aListof file-like resources from one location to another.The number of source resources must equal the number of destination resources. Destination resources will be created recursively.
- Parameters:
srcResourceIds- the references of the source resourcesdestResourceIds- the references of the destination resourcesmoveOptions- move options specifying handling of error conditions- Throws:
UnsupportedOperationException- if move options are specified and not supported by the FileSystemFileNotFoundException- if the source resources are missing. When rename throws, the state of the resources is unknown but safe: for every (source, destination) pair of resources, the following are possible: a) source exists, b) destination exists, c) source and destination both exist. Thus no data is lost, however, duplicated resource are possible. In such scenarios, callers can usematch()to determine the state of the resource.IOException
-
delete
Deletes a collection of resources.- Parameters:
resourceIds- the references of the resources to delete.- Throws:
FileNotFoundException- if resources are missing. When delete throws, each resource might or might not be deleted. In such scenarios, callers can usematch()to determine the state of the resources.IOException
-
matchNewResource
Returns a newResourceIdfor this filesystem that represents the named resource. The user supplies both the resource spec and whether it is a directory.The supplied
singleResourceSpecis expected to be in a proper format, including any necessary escaping, for thisFileSystem.This function may throw an
IllegalArgumentExceptionif given an invalid argument, such as when the specifiedsingleResourceSpecis not a valid resource name. -
getScheme
Get the URI scheme which defines the namespace of theFileSystem.- See Also:
-
reportLineage
ReportLineagemetrics for resource id at file level. -
reportLineage
protected void reportLineage(ResourceIdT unusedId, Lineage unusedLineage, FileSystem.LineageLevel level) ReportLineagemetrics for resource id to a given level.Unless override by FileSystem implementations, default to no-op.
-