public class GcsUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
GcsUtil.CreateOptions |
static class |
GcsUtil.GcsUtilFactory
This is a
DefaultValueFactory able to create a GcsUtil using any transport
flags specified on the PipelineOptions . |
static class |
GcsUtil.StorageObjectOrIOException
A class that holds either a
StorageObject or an IOException . |
Modifier and Type | Method and Description |
---|---|
boolean |
bucketAccessible(GcsPath path)
Returns whether the GCS bucket exists and is accessible.
|
long |
bucketOwner(GcsPath path)
Returns the project number of the project which owns this bucket.
|
void |
copy(java.lang.Iterable<java.lang.String> srcFilenames,
java.lang.Iterable<java.lang.String> destFilenames) |
java.nio.channels.WritableByteChannel |
create(GcsPath path,
GcsUtil.CreateOptions options)
Creates an object in GCS and prepares for uploading its contents.
|
java.nio.channels.WritableByteChannel |
create(GcsPath path,
java.lang.String type)
Deprecated.
Use
create(GcsPath, CreateOptions) instead. |
java.nio.channels.WritableByteChannel |
create(GcsPath path,
java.lang.String type,
java.lang.Integer uploadBufferSizeBytes)
Deprecated.
Use
create(GcsPath, CreateOptions) instead. |
void |
createBucket(java.lang.String projectId,
Bucket bucket)
Creates a
Bucket under the specified project in Cloud Storage or propagates an
exception. |
java.util.List<GcsPath> |
expand(GcsPath gcsPattern)
Expands a pattern into matched paths.
|
long |
fileSize(GcsPath path)
Returns the file size from GCS or throws
FileNotFoundException if the resource does not
exist. |
static java.lang.String |
getNonWildcardPrefix(java.lang.String globExp)
Returns the prefix portion of the glob that doesn't contain wildcards.
|
StorageObject |
getObject(GcsPath gcsPath)
Returns the
StorageObject for the given GcsPath . |
java.util.List<GcsUtil.StorageObjectOrIOException> |
getObjects(java.util.List<GcsPath> gcsPaths)
Returns
StorageObjectOrIOExceptions for the given GcsPaths . |
static boolean |
isWildcard(GcsPath spec)
Returns true if the given
spec contains wildcard. |
Objects |
listObjects(java.lang.String bucket,
java.lang.String prefix,
@Nullable java.lang.String pageToken) |
Objects |
listObjects(java.lang.String bucket,
java.lang.String prefix,
@Nullable java.lang.String pageToken,
@Nullable java.lang.String delimiter)
|
java.nio.channels.SeekableByteChannel |
open(GcsPath path)
Opens an object in GCS.
|
void |
remove(java.util.Collection<java.lang.String> filenames) |
void |
rename(java.lang.Iterable<java.lang.String> srcFilenames,
java.lang.Iterable<java.lang.String> destFilenames,
MoveOptions... moveOptions) |
protected void |
setBatchRequestSupplier(java.util.function.Supplier<org.apache.beam.sdk.extensions.gcp.util.GcsUtil.BatchInterface> supplier) |
protected void |
setStorageClient(Storage storageClient) |
void |
verifyBucketAccessible(GcsPath path)
Checks whether the GCS bucket exists.
|
public static java.lang.String getNonWildcardPrefix(java.lang.String globExp)
public static boolean isWildcard(GcsPath spec)
spec
contains wildcard.protected void setStorageClient(Storage storageClient)
protected void setBatchRequestSupplier(java.util.function.Supplier<org.apache.beam.sdk.extensions.gcp.util.GcsUtil.BatchInterface> supplier)
public java.util.List<GcsPath> expand(GcsPath gcsPattern) throws java.io.IOException
java.io.IOException
public long fileSize(GcsPath path) throws java.io.IOException
FileNotFoundException
if the resource does not
exist.java.io.IOException
public StorageObject getObject(GcsPath gcsPath) throws java.io.IOException
StorageObject
for the given GcsPath
.java.io.IOException
public java.util.List<GcsUtil.StorageObjectOrIOException> getObjects(java.util.List<GcsPath> gcsPaths) throws java.io.IOException
StorageObjectOrIOExceptions
for the given GcsPaths
.java.io.IOException
public Objects listObjects(java.lang.String bucket, java.lang.String prefix, @Nullable java.lang.String pageToken) throws java.io.IOException
java.io.IOException
public Objects listObjects(java.lang.String bucket, java.lang.String prefix, @Nullable java.lang.String pageToken, @Nullable java.lang.String delimiter) throws java.io.IOException
Objects
given the bucket
, prefix
, pageToken
.
For more details, see https://cloud.google.com/storage/docs/json_api/v1/objects/list.
java.io.IOException
public java.nio.channels.SeekableByteChannel open(GcsPath path) throws java.io.IOException
Returns a SeekableByteChannel that provides access to data in the bucket.
path
- the GCS filename to read fromjava.io.IOException
@Deprecated public java.nio.channels.WritableByteChannel create(GcsPath path, java.lang.String type) throws java.io.IOException
create(GcsPath, CreateOptions)
instead.java.io.IOException
@Deprecated public java.nio.channels.WritableByteChannel create(GcsPath path, java.lang.String type, java.lang.Integer uploadBufferSizeBytes) throws java.io.IOException
create(GcsPath, CreateOptions)
instead.java.io.IOException
public java.nio.channels.WritableByteChannel create(GcsPath path, GcsUtil.CreateOptions options) throws java.io.IOException
path
- the GCS file to write tooptions
- to be used for creating and configuring file uploadjava.io.IOException
public void verifyBucketAccessible(GcsPath path) throws java.io.IOException
bucketAccessible(GcsPath)
, but throws
exception if the bucket is inaccessible due to permissions or does not exist.java.io.IOException
public boolean bucketAccessible(GcsPath path) throws java.io.IOException
java.io.IOException
public long bucketOwner(GcsPath path) throws java.io.IOException
java.io.IOException
public void createBucket(java.lang.String projectId, Bucket bucket) throws java.io.IOException
Bucket
under the specified project in Cloud Storage or propagates an
exception.java.io.IOException
public void copy(java.lang.Iterable<java.lang.String> srcFilenames, java.lang.Iterable<java.lang.String> destFilenames) throws java.io.IOException
java.io.IOException
public void rename(java.lang.Iterable<java.lang.String> srcFilenames, java.lang.Iterable<java.lang.String> destFilenames, MoveOptions... moveOptions) throws java.io.IOException
java.io.IOException
public void remove(java.util.Collection<java.lang.String> filenames) throws java.io.IOException
java.io.IOException