public class GcsUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
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,
java.lang.String type)
Creates an object in GCS.
|
java.nio.channels.WritableByteChannel |
create(GcsPath path,
java.lang.String type,
java.lang.Integer uploadBufferSizeBytes)
Same as
create(GcsPath, String) but allows overriding {code
uploadBufferSizeBytes}. |
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) |
protected void |
setStorageClient(Storage storageClient) |
public static java.lang.String getNonWildcardPrefix(java.lang.String globExp)
public static boolean isWildcard(GcsPath spec)
spec contains wildcard.protected void setStorageClient(Storage storageClient)
public java.util.List<GcsPath> expand(GcsPath gcsPattern) throws java.io.IOException
java.io.IOExceptionpublic long fileSize(GcsPath path) throws java.io.IOException
FileNotFoundException if the resource does not
exist.java.io.IOExceptionpublic StorageObject getObject(GcsPath gcsPath) throws java.io.IOException
StorageObject for the given GcsPath.java.io.IOExceptionpublic java.util.List<GcsUtil.StorageObjectOrIOException> getObjects(java.util.List<GcsPath> gcsPaths) throws java.io.IOException
StorageObjectOrIOExceptions for the given GcsPaths.java.io.IOExceptionpublic Objects listObjects(java.lang.String bucket, java.lang.String prefix, @Nullable java.lang.String pageToken) throws java.io.IOException
java.io.IOExceptionpublic 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.IOExceptionpublic 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.IOExceptionpublic java.nio.channels.WritableByteChannel create(GcsPath path, java.lang.String type) throws java.io.IOException
Returns a WritableByteChannel that can be used to write data to the object.
path - the GCS file to write totype - the type of object, eg "text/plain".java.io.IOExceptionpublic java.nio.channels.WritableByteChannel create(GcsPath path, java.lang.String type, java.lang.Integer uploadBufferSizeBytes) throws java.io.IOException
create(GcsPath, String) but allows overriding {code
uploadBufferSizeBytes}.java.io.IOExceptionpublic boolean bucketAccessible(GcsPath path) throws java.io.IOException
java.io.IOExceptionpublic long bucketOwner(GcsPath path) throws java.io.IOException
java.io.IOExceptionpublic 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.IOExceptionpublic void copy(java.lang.Iterable<java.lang.String> srcFilenames,
java.lang.Iterable<java.lang.String> destFilenames)
throws java.io.IOException
java.io.IOExceptionpublic void remove(java.util.Collection<java.lang.String> filenames)
throws java.io.IOException
java.io.IOException