public class FileSystems
extends java.lang.Object
FileSystem
utility.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SCHEME |
Constructor and Description |
---|
FileSystems() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(java.util.List<ResourceId> srcResourceIds,
java.util.List<ResourceId> destResourceIds,
MoveOptions... moveOptions)
Copies a
List of file-like resources from one location to another. |
static java.nio.channels.WritableByteChannel |
create(ResourceId resourceId,
CreateOptions createOptions)
Returns a write channel for the given
ResourceId with CreateOptions . |
static java.nio.channels.WritableByteChannel |
create(ResourceId resourceId,
java.lang.String mimeType)
Returns a write channel for the given
ResourceId . |
static void |
delete(java.util.Collection<ResourceId> resourceIds,
MoveOptions... moveOptions)
Deletes a collection of resources.
|
static boolean |
hasGlobWildcard(java.lang.String spec)
Checks whether the given spec contains a glob wildcard character.
|
static java.util.List<MatchResult> |
match(java.util.List<java.lang.String> specs)
This is the entry point to convert user-provided specs to
ResourceIds . |
static java.util.List<MatchResult> |
match(java.util.List<java.lang.String> specs,
EmptyMatchTreatment emptyMatchTreatment)
Like
match(List) , but with a configurable EmptyMatchTreatment . |
static MatchResult |
match(java.lang.String spec)
Like
match(List) , but for a single resource specification. |
static MatchResult |
match(java.lang.String spec,
EmptyMatchTreatment emptyMatchTreatment)
Like
match(String) , but with a configurable EmptyMatchTreatment . |
static ResourceId |
matchNewDirectory(java.lang.String singleResourceSpec,
java.lang.String... baseNames)
Returns a new
ResourceId that represents the named directory resource. |
static ResourceId |
matchNewResource(java.lang.String singleResourceSpec,
boolean isDirectory)
Returns a new
ResourceId that represents the named resource of a type corresponding to
the resource type. |
static java.util.List<MatchResult> |
matchResources(java.util.List<ResourceId> resourceIds)
Returns
MatchResults for the given resourceIds . |
static MatchResult.Metadata |
matchSingleFileSpec(java.lang.String spec)
Returns the
MatchResult.Metadata for a single file resource. |
static java.nio.channels.ReadableByteChannel |
open(ResourceId resourceId)
Returns a read channel for the given
ResourceId . |
static void |
rename(java.util.List<ResourceId> srcResourceIds,
java.util.List<ResourceId> destResourceIds,
MoveOptions... moveOptions)
Renames a
List of file-like resources from one location to another. |
static void |
reportSinkLineage(ResourceId resourceId)
Report sink
Lineage metrics for resource id. |
static void |
reportSourceLineage(ResourceId resourceId)
Report source
Lineage metrics for resource id. |
static void |
setDefaultPipelineOptions(PipelineOptions options)
Sets the default configuration in workers.
|
public static final java.lang.String DEFAULT_SCHEME
public static boolean hasGlobWildcard(java.lang.String spec)
public static java.util.List<MatchResult> match(java.util.List<java.lang.String> specs) throws java.io.IOException
ResourceIds
.
Callers should use match(java.util.List<java.lang.String>)
to resolve users specs ambiguities before calling other
methods.
Implementation handles the following ambiguities of a user-provided spec:
spec
could be a glob or a uri. 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 path delimiter, such as
"/tmp/dir"
in Linux. The FileSystem
should be able to recognize a
directory with the trailing path delimiter omitted, but should always return a correct
ResourceId
(e.g., "/tmp/dir/"
inside the returned MatchResult
.
All FileSystem
implementations should support glob in the final hierarchical path
component of ResourceId
. This allows SDK libraries to construct file system agnostic
spec. FileSystems
can support additional patterns for user-provided specs.
In case the spec schemes don't match any known FileSystem
implementations,
FileSystems will attempt to use LocalFileSystem
to resolve a path.
Specs that do not match any resources are treated according to EmptyMatchTreatment.DISALLOW
.
List<MatchResult>
in the same order of the input specs.java.lang.IllegalArgumentException
- if specs are invalid -- empty or have different schemes.java.io.IOException
- if all specs failed to match due to issues like: network connection,
authorization. Exception for individual spec is deferred until callers retrieve metadata
with MatchResult.metadata()
.public static java.util.List<MatchResult> match(java.util.List<java.lang.String> specs, EmptyMatchTreatment emptyMatchTreatment) throws java.io.IOException
match(List)
, but with a configurable EmptyMatchTreatment
.java.io.IOException
public static MatchResult match(java.lang.String spec) throws java.io.IOException
match(List)
, but for a single resource specification.
The function match(List)
is preferred when matching multiple patterns, as it allows
for bulk API calls to remote filesystems.
java.io.IOException
public static MatchResult match(java.lang.String spec, EmptyMatchTreatment emptyMatchTreatment) throws java.io.IOException
match(String)
, but with a configurable EmptyMatchTreatment
.java.io.IOException
public static MatchResult.Metadata matchSingleFileSpec(java.lang.String spec) throws java.io.IOException
MatchResult.Metadata
for a single file resource. Expects a resource specification
spec
that matches a single result.spec
- a resource specification that matches exactly one result.MatchResult.Metadata
for the specified resource.java.io.FileNotFoundException
- if the file resource is not found.java.io.IOException
- in the event of an error in the inner call to match(java.util.List<java.lang.String>)
, or if the
given spec does not match exactly 1 result.public static java.util.List<MatchResult> matchResources(java.util.List<ResourceId> resourceIds) throws java.io.IOException
MatchResults
for the given resourceIds
.resourceIds
- resourceIds
that might be derived from match(java.util.List<java.lang.String>)
,
ResourceId.resolve(java.lang.String, org.apache.beam.sdk.io.fs.ResolveOptions)
, or ResourceId.getCurrentDirectory()
.java.io.IOException
- if all resourceIds
failed to match due to issues like: network
connection, authorization. Exception for individual ResourceId
need to be deferred
until callers retrieve metadata with MatchResult.metadata()
.public static java.nio.channels.WritableByteChannel create(ResourceId resourceId, java.lang.String mimeType) throws java.io.IOException
ResourceId
.
The resource is not expanded; it is used verbatim.
resourceId
- the reference of the file-like resource to createmimeType
- the mine type of the file-like resource to createjava.io.IOException
public static java.nio.channels.WritableByteChannel create(ResourceId resourceId, CreateOptions createOptions) throws java.io.IOException
ResourceId
with CreateOptions
.
The resource is not expanded; it is used verbatim.
resourceId
- the reference of the file-like resource to createcreateOptions
- the configuration of the create operationjava.io.IOException
public static java.nio.channels.ReadableByteChannel open(ResourceId resourceId) throws java.io.IOException
ResourceId
.
The resource is not expanded; it is used verbatim.
If seeking is supported, then this returns a SeekableByteChannel
.
resourceId
- the reference of the file-like resource to openjava.io.IOException
public static void copy(java.util.List<ResourceId> srcResourceIds, java.util.List<ResourceId> destResourceIds, MoveOptions... moveOptions) throws java.io.IOException
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.
srcResourceIds
and destResourceIds
must have the same scheme.
It doesn't support copying globs.
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resourcesjava.io.IOException
public static void rename(java.util.List<ResourceId> srcResourceIds, java.util.List<ResourceId> destResourceIds, MoveOptions... moveOptions) throws java.io.IOException
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.
srcResourceIds
and destResourceIds
must have the same scheme.
It doesn't support renaming globs.
Src files will be removed, even if the copy is skipped due to specified move options.
srcResourceIds
- the references of the source resourcesdestResourceIds
- the references of the destination resourcesjava.io.IOException
public static void delete(java.util.Collection<ResourceId> resourceIds, MoveOptions... moveOptions) throws java.io.IOException
resourceIds
must have the same scheme.
resourceIds
- the references of the resources to delete.java.io.IOException
public static void reportSourceLineage(ResourceId resourceId)
Lineage
metrics for resource id.public static void reportSinkLineage(ResourceId resourceId)
Lineage
metrics for resource id.@Internal public static void setDefaultPipelineOptions(PipelineOptions options)
It will be used in FileSystemRegistrars
for all schemes.
This is expected only to be used by runners after Pipeline.run
, or in tests.
public static ResourceId matchNewResource(java.lang.String singleResourceSpec, boolean isDirectory)
ResourceId
that represents the named resource of a type corresponding to
the resource type.
The supplied singleResourceSpec
is expected to be in a proper format, including any
necessary escaping, for the underlying FileSystem
.
This function may throw an IllegalArgumentException
if given an invalid argument,
such as when the specified singleResourceSpec
is not a valid resource name.
public static ResourceId matchNewDirectory(java.lang.String singleResourceSpec, java.lang.String... baseNames)
ResourceId
that represents the named directory resource.singleResourceSpec
- the root directory, for example "/abc"baseNames
- a list of named directory, for example ["d", "e", "f"]