public class ClassLoaderFileSystem extends FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
FileSystem
implementation looking up resources using a ClassLoader.Modifier and Type | Class and Description |
---|---|
static class |
ClassLoaderFileSystem.ClassLoaderFileSystemRegistrar
AutoService registrar for the ClassLoaderFileSystem . |
static class |
ClassLoaderFileSystem.ClassLoaderResourceId |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SCHEMA |
Modifier and Type | Method and Description |
---|---|
protected void |
copy(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds,
java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds)
Copies a
List of file-like resources from one location to another. |
protected java.nio.channels.WritableByteChannel |
create(ClassLoaderFileSystem.ClassLoaderResourceId resourceId,
CreateOptions createOptions)
Returns a write channel for the given
ResourceIdT . |
protected void |
delete(java.util.Collection<ClassLoaderFileSystem.ClassLoaderResourceId> resourceIds)
Deletes a collection of resources.
|
protected java.lang.String |
getScheme()
Get the URI scheme which defines the namespace of the
FileSystem . |
protected java.util.List<MatchResult> |
match(java.util.List<java.lang.String> specs)
This is the entry point to convert user-provided specs to
ResourceIds . |
protected ClassLoaderFileSystem.ClassLoaderResourceId |
matchNewResource(java.lang.String path,
boolean isDirectory)
Returns a new
ResourceId for this filesystem that represents the named resource. |
protected java.nio.channels.ReadableByteChannel |
open(ClassLoaderFileSystem.ClassLoaderResourceId resourceId)
Returns a read channel for the given
ResourceIdT . |
protected void |
rename(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds,
java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds,
MoveOptions... moveOptions)
Renames a
List of file-like resources from one location to another. |
reportLineage
public static final java.lang.String SCHEMA
protected java.util.List<MatchResult> match(java.util.List<java.lang.String> specs) throws java.io.IOException
FileSystem
ResourceIds
.
Callers should use FileSystem.match(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:
spec
could be a glob or a uri. FileSystem.match(java.util.List<java.lang.String>)
should be able to tell and choose
efficient implementations.
spec
might 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"
. The FileSystem
should be able to recognize a
directory with the trailing /
omitted, but should always return a correct ResourceIdT
(e.g., "/tmp/dir/"
inside the returned MatchResult
.
All FileSystem
implementations should support glob in the final hierarchical path
component of ResourceIdT
. This allows SDK libraries to construct file system agnostic
spec. FileSystems
can support additional patterns for user-provided specs.
match
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
List<MatchResult>
in the same order of the input specs.java.io.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 with MatchResult.metadata()
.protected java.nio.channels.WritableByteChannel create(ClassLoaderFileSystem.ClassLoaderResourceId resourceId, CreateOptions createOptions) throws java.io.IOException
FileSystem
ResourceIdT
.
The resource is not expanded; it is used verbatim.
create
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
resourceId
- the reference of the file-like resource to createcreateOptions
- the configuration of the create operationjava.io.IOException
protected java.nio.channels.ReadableByteChannel open(ClassLoaderFileSystem.ClassLoaderResourceId resourceId) throws java.io.IOException
FileSystem
ResourceIdT
.
The resource is not expanded; it is used verbatim.
If seeking is supported, then this returns a SeekableByteChannel
.
open
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
resourceId
- the reference of the file-like resource to openjava.io.IOException
protected void copy(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds) throws java.io.IOException
FileSystem
List
of 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.
copy
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resourcesjava.io.FileNotFoundException
- if the source resources are missing. When copy throws, each
resource might or might not be copied. In such scenarios, callers can use match()
to determine the state of the resources.java.io.IOException
protected void rename(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds, MoveOptions... moveOptions) throws java.io.IOException
FileSystem
List
of 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.
rename
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resourcesmoveOptions
- move options specifying handling of error conditionsjava.io.FileNotFoundException
- 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 use match()
to determine the state of the
resource.java.io.IOException
protected void delete(java.util.Collection<ClassLoaderFileSystem.ClassLoaderResourceId> resourceIds) throws java.io.IOException
FileSystem
delete
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
resourceIds
- the references of the resources to delete.java.io.FileNotFoundException
- if resources are missing. When delete throws, each resource might
or might not be deleted. In such scenarios, callers can use match()
to determine
the state of the resources.java.io.IOException
protected ClassLoaderFileSystem.ClassLoaderResourceId matchNewResource(java.lang.String path, boolean isDirectory)
FileSystem
ResourceId
for this filesystem that represents the named resource. The
user supplies both the resource spec and whether it is a directory.
The supplied singleResourceSpec
is expected to be in a proper format, including any
necessary escaping, for this FileSystem
.
This function may throw an IllegalArgumentException
if given an invalid argument,
such as when the specified singleResourceSpec
is not a valid resource name.
matchNewResource
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
protected java.lang.String getScheme()
FileSystem
FileSystem
.getScheme
in class FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>