Class GcsUtil
java.lang.Object
org.apache.beam.sdk.extensions.gcp.util.GcsUtil
Provides operations on GCS.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classThis is aDefaultValueFactoryable to create aGcsUtilusing any transport flags specified on thePipelineOptions.static classA class that holds either aStorageObjector anIOException. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbucketAccessible(GcsPath path) Returns whether the GCS bucket exists and is accessible.longbucketOwner(GcsPath path) Returns the project number of the project which owns this bucket.voidDeprecated.Deprecated.Usecreate(GcsPath, CreateOptions)instead.create(GcsPath path, GcsUtil.CreateOptions options) Creates an object in GCS and prepares for uploading its contents.voidcreateBucket(String projectId, Bucket bucket) Creates aBucketunder the specified project in Cloud Storage or propagates an exception.Expands a pattern into matched paths.longReturns the file size from GCS or throwsFileNotFoundExceptionif the resource does not exist.Get theBucketfrom Cloud Storage path or propagates an exception.static StringgetNonWildcardPrefix(String globExp) Returns the prefix portion of the glob that doesn't contain wildcards.Returns theStorageObjectfor the givenGcsPath.getObjects(List<GcsPath> gcsPaths) ReturnsStorageObjectOrIOExceptionsfor the givenGcsPaths.static booleanisWildcard(GcsPath spec) Returns true if the givenspeccontains wildcard.listObjects(String bucket, String prefix, @Nullable String pageToken) Opens an object in GCS.voidremove(Collection<String> filenames) voidremoveBucket(Bucket bucket) Remove an emptyBucketin Cloud Storage or propagates an exception.voidprotected voidsetBatchRequestSupplier(Supplier<org.apache.beam.sdk.extensions.gcp.util.GcsUtil.BatchInterface> supplier) protected voidsetStorageClient(Storage storageClient) voidChecks 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 givenspeccontains 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 throwsFileNotFoundExceptionif the resource does not exist.- Throws:
IOException
-
getObject
Returns theStorageObjectfor the givenGcsPath.- Throws:
IOException
-
getObjects
public List<GcsUtil.StorageObjectOrIOException> getObjects(List<GcsPath> gcsPaths) throws IOException ReturnsStorageObjectOrIOExceptionsfor 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 ListsObjectsgiven 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 aBucketunder the specified project in Cloud Storage or propagates an exception.- Throws:
IOException
-
getBucket
Get theBucketfrom Cloud Storage path or propagates an exception.- Throws:
IOException
-
removeBucket
Remove an emptyBucketin 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.