Class ClassLoaderFileSystem
- java.lang.Object
-
- org.apache.beam.sdk.io.FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
-
- org.apache.beam.sdk.io.ClassLoaderFileSystem
-
public class ClassLoaderFileSystem extends FileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
A read-onlyFileSystem
implementation looking up resources using a ClassLoader.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassLoaderFileSystem.ClassLoaderFileSystemRegistrar
AutoService
registrar for theClassLoaderFileSystem
.static class
ClassLoaderFileSystem.ClassLoaderResourceId
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SCHEMA
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copy(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds)
Copies aList
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 givenFileSystem
.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 theFileSystem
.protected java.util.List<MatchResult>
match(java.util.List<java.lang.String> specs)
This is the entry point to convert user-provided specs toResourceIds
.protected ClassLoaderFileSystem.ClassLoaderResourceId
matchNewResource(java.lang.String path, boolean isDirectory)
Returns a newResourceId
for this filesystem that represents the named resource.protected java.nio.channels.ReadableByteChannel
open(ClassLoaderFileSystem.ClassLoaderResourceId resourceId)
Returns a read channel for the givenFileSystem
.protected void
rename(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds, MoveOptions... moveOptions)
Renames aList
of file-like resources from one location to another.
-
-
-
Field Detail
-
SCHEMA
public static final java.lang.String SCHEMA
- See Also:
- Constant Field Values
-
-
Method Detail
-
match
protected java.util.List<MatchResult> match(java.util.List<java.lang.String> specs) throws java.io.IOException
Description copied from class:FileSystem
This is the entry point to convert user-provided specs toResourceIds
. Callers should useFileSystem.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.- The user-provided
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"
. TheFileSystem
should be able to recognize a directory with the trailing/
omitted, but should always return a correctFileSystem
(e.g.,"/tmp/dir/"
inside the returnedMatchResult
.
All
FileSystem
implementations should support glob in the final hierarchical path component ofFileSystem
. This allows SDK libraries to construct file system agnostic spec.FileSystems
can support additional patterns for user-provided specs.- Specified by:
match
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Returns:
List<MatchResult>
in the same order of the input specs.- Throws:
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 withMatchResult.metadata()
.
-
create
protected java.nio.channels.WritableByteChannel create(ClassLoaderFileSystem.ClassLoaderResourceId resourceId, CreateOptions createOptions) throws java.io.IOException
Description copied from class:FileSystem
Returns a write channel for the givenFileSystem
.The resource is not expanded; it is used verbatim.
- Specified by:
create
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Parameters:
resourceId
- the reference of the file-like resource to createcreateOptions
- the configuration of the create operation- Throws:
java.io.IOException
-
open
protected java.nio.channels.ReadableByteChannel open(ClassLoaderFileSystem.ClassLoaderResourceId resourceId) throws java.io.IOException
Description copied from class:FileSystem
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
.- Specified by:
open
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Parameters:
resourceId
- the reference of the file-like resource to open- Throws:
java.io.IOException
-
copy
protected void copy(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds) throws java.io.IOException
Description copied from class:FileSystem
Copies aList
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.
- Specified by:
copy
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Parameters:
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resources- Throws:
java.io.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.java.io.IOException
-
rename
protected void rename(java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> srcResourceIds, java.util.List<ClassLoaderFileSystem.ClassLoaderResourceId> destResourceIds, MoveOptions... moveOptions) throws java.io.IOException
Description copied from class:FileSystem
Renames aList
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.
- Specified by:
rename
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Parameters:
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resourcesmoveOptions
- move options specifying handling of error conditions- Throws:
java.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 usematch()
to determine the state of the resource.java.io.IOException
-
delete
protected void delete(java.util.Collection<ClassLoaderFileSystem.ClassLoaderResourceId> resourceIds) throws java.io.IOException
Description copied from class:FileSystem
Deletes a collection of resources.- Specified by:
delete
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- Parameters:
resourceIds
- the references of the resources to delete.- Throws:
java.io.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.java.io.IOException
-
matchNewResource
protected ClassLoaderFileSystem.ClassLoaderResourceId matchNewResource(java.lang.String path, boolean isDirectory)
Description copied from class:FileSystem
Returns a newResourceId
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 thisFileSystem
.This function may throw an
IllegalArgumentException
if given an invalid argument, such as when the specifiedsingleResourceSpec
is not a valid resource name.- Specified by:
matchNewResource
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
-
getScheme
protected java.lang.String getScheme()
Description copied from class:FileSystem
Get the URI scheme which defines the namespace of theFileSystem
.- Specified by:
getScheme
in classFileSystem<ClassLoaderFileSystem.ClassLoaderResourceId>
- See Also:
- RFC 2396
-
-