Class GcsUtil
java.lang.Object
org.apache.beam.sdk.extensions.gcp.util.GcsUtil
Provides operations on GCS.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
static class
This is aDefaultValueFactory
able to create aGcsUtil
using any transport flags specified on thePipelineOptions
.static class
A class that holds either aStorageObject
or anIOException
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Deprecated.Deprecated.Usecreate(GcsPath, CreateOptions)
instead.create
(GcsPath path, GcsUtil.CreateOptions options) Creates an object in GCS and prepares for uploading its contents.void
createBucket
(String projectId, Bucket bucket) Creates aBucket
under the specified project in Cloud Storage or propagates an exception.Expands a pattern into matched paths.long
Returns the file size from GCS or throwsFileNotFoundException
if the resource does not exist.Get theBucket
from Cloud Storage path or propagates an exception.static String
getNonWildcardPrefix
(String globExp) Returns the prefix portion of the glob that doesn't contain wildcards.Returns theStorageObject
for the givenGcsPath
.getObjects
(List<GcsPath> gcsPaths) ReturnsStorageObjectOrIOExceptions
for the givenGcsPaths
.static boolean
isWildcard
(GcsPath spec) Returns true if the givenspec
contains wildcard.listObjects
(String bucket, String prefix, @Nullable String pageToken) Opens an object in GCS.void
remove
(Collection<String> filenames) void
removeBucket
(Bucket bucket) Remove an emptyBucket
in Cloud Storage or propagates an exception.void
protected void
setBatchRequestSupplier
(Supplier<org.apache.beam.sdk.extensions.gcp.util.GcsUtil.BatchInterface> supplier) protected void
setStorageClient
(Storage storageClient) void
Checks whether the GCS bucket exists.
-
Method Details
-
getNonWildcardPrefix
Returns the prefix portion of the glob that doesn't contain wildcards. -
isWildcard
Returns true if the givenspec
contains wildcard. -
setStorageClient
-
setBatchRequestSupplier
protected void setBatchRequestSupplier(Supplier<org.apache.beam.sdk.extensions.gcp.util.GcsUtil.BatchInterface> supplier) -
expand
Expands a pattern into matched paths. The pattern path may contain globs, which are expanded in the result. For patterns that only match a single object, we ensure that the object exists.- Throws:
IOException
-
fileSize
Returns the file size from GCS or throwsFileNotFoundException
if the resource does not exist.- Throws:
IOException
-
getObject
Returns theStorageObject
for the givenGcsPath
.- Throws:
IOException
-
getObjects
public List<GcsUtil.StorageObjectOrIOException> getObjects(List<GcsPath> gcsPaths) throws IOException ReturnsStorageObjectOrIOExceptions
for the givenGcsPaths
.- Throws:
IOException
-
listObjects
public Objects listObjects(String bucket, String prefix, @Nullable String pageToken) throws IOException - Throws:
IOException
-
listObjects
public Objects listObjects(String bucket, String prefix, @Nullable String pageToken, @Nullable String delimiter) throws IOException ListsObjects
given thebucket
,prefix
,pageToken
.For more details, see https://cloud.google.com/storage/docs/json_api/v1/objects/list.
- Throws:
IOException
-
open
Opens an object in GCS.Returns a SeekableByteChannel that provides access to data in the bucket.
- Parameters:
path
- the GCS filename to read from- Returns:
- a SeekableByteChannel that can read the object data
- Throws:
IOException
-
create
Deprecated.Usecreate(GcsPath, CreateOptions)
instead.- Throws:
IOException
-
create
@Deprecated public WritableByteChannel create(GcsPath path, String type, Integer uploadBufferSizeBytes) throws IOException Deprecated.Usecreate(GcsPath, CreateOptions)
instead.- Throws:
IOException
-
create
Creates an object in GCS and prepares for uploading its contents.- Parameters:
path
- the GCS file to write tooptions
- to be used for creating and configuring file upload- Returns:
- a WritableByteChannel that can be used to write data to the object.
- Throws:
IOException
-
verifyBucketAccessible
Checks whether the GCS bucket exists. Similar tobucketAccessible(GcsPath)
, but throws exception if the bucket is inaccessible due to permissions or does not exist.- Throws:
IOException
-
bucketAccessible
Returns whether the GCS bucket exists and is accessible.- Throws:
IOException
-
bucketOwner
Returns the project number of the project which owns this bucket. If the bucket exists, it must be accessible otherwise the permissions exception will be propagated. If the bucket does not exist, an exception will be thrown.- Throws:
IOException
-
createBucket
Creates aBucket
under the specified project in Cloud Storage or propagates an exception.- Throws:
IOException
-
getBucket
Get theBucket
from Cloud Storage path or propagates an exception.- Throws:
IOException
-
removeBucket
Remove an emptyBucket
in Cloud Storage or propagates an exception.- Throws:
IOException
-
copy
- Throws:
IOException
-
rename
public void rename(Iterable<String> srcFilenames, Iterable<String> destFilenames, MoveOptions... moveOptions) throws IOException - Throws:
IOException
-
remove
- Throws:
IOException
-
create(GcsPath, CreateOptions)
instead.