public class GcsUtil extends 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(Iterable<String> srcFilenames,
Iterable<String> destFilenames) |
WritableByteChannel |
create(GcsPath path,
String type)
Creates an object in GCS.
|
void |
createBucket(String projectId,
com.google.api.services.storage.model.Bucket bucket)
Creates a
Bucket under the specified project in Cloud Storage or
propagates an exception. |
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 String |
getGlobPrefix(String globExp)
Returns the prefix portion of the glob that doesn't contain wildcards.
|
com.google.api.services.storage.model.StorageObject |
getObject(GcsPath gcsPath)
Returns the
StorageObject for the given GcsPath. |
List<GcsUtil.StorageObjectOrIOException> |
getObjects(List<GcsPath> gcsPaths)
Returns
StorageObjectOrIOExceptions for the given
GcsPaths. |
static String |
globToRegexp(String globExp)
Expands glob expressions to regular expressions.
|
static boolean |
isGcsPatternSupported(String gcsPattern)
Returns true if the given GCS pattern is supported otherwise fails with an
exception.
|
static boolean |
isGlob(GcsPath spec)
Returns true if the given
spec contains glob. |
com.google.api.services.storage.model.Objects |
listObjects(String bucket,
String prefix,
String pageToken)
Lists
Objects given the bucket, prefix, pageToken. |
SeekableByteChannel |
open(GcsPath path)
Opens an object in GCS.
|
void |
remove(Collection<String> filenames) |
protected void |
setStorageClient(com.google.api.services.storage.Storage storageClient) |
public static boolean isGcsPatternSupported(String gcsPattern)
public static String getGlobPrefix(String globExp)
public static String globToRegexp(String globExp)
globExp - the glob expression to expandpublic static boolean isGlob(GcsPath spec)
spec contains glob.protected void setStorageClient(com.google.api.services.storage.Storage storageClient)
public List<GcsPath> expand(GcsPath gcsPattern) throws IOException
IOExceptionpublic long fileSize(GcsPath path) throws IOException
FileNotFoundException
if the resource does not exist.IOExceptionpublic com.google.api.services.storage.model.StorageObject getObject(GcsPath gcsPath) throws IOException
StorageObject for the given GcsPath.IOExceptionpublic List<GcsUtil.StorageObjectOrIOException> getObjects(List<GcsPath> gcsPaths) throws IOException
StorageObjectOrIOExceptions for the given
GcsPaths.IOExceptionpublic com.google.api.services.storage.model.Objects listObjects(String bucket, String prefix, @Nullable String pageToken) throws IOException
Objects given the bucket, prefix, pageToken.IOExceptionpublic SeekableByteChannel open(GcsPath path) throws IOException
Returns a SeekableByteChannel that provides access to data in the bucket.
path - the GCS filename to read fromIOExceptionpublic WritableByteChannel create(GcsPath path, String type) throws 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".IOExceptionpublic boolean bucketAccessible(GcsPath path) throws IOException
IOExceptionpublic long bucketOwner(GcsPath path) throws IOException
IOExceptionpublic void createBucket(String projectId, com.google.api.services.storage.model.Bucket bucket) throws IOException
Bucket under the specified project in Cloud Storage or
propagates an exception.IOExceptionpublic void copy(Iterable<String> srcFilenames, Iterable<String> destFilenames) throws IOException
IOExceptionpublic void remove(Collection<String> filenames) throws IOException
IOExceptionCopyright © 2016–2017 The Apache Software Foundation. All rights reserved.