public interface GoogleCloudStorage
Please read the following document to get familiarity with basic GCS concepts: https://developers.google.com/storage/docs/concepts-techniques
| Modifier and Type | Interface and Description |
|---|---|
static class |
GoogleCloudStorage.ListPage<T>
Paged list request response
|
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_COMPOSE_OBJECTS
The maximum number of objects that can be composed in one operation.
|
static long |
MAX_RESULTS_UNLIMITED
Value indicating all objects should be returned from GCS, no limit.
|
static java.lang.String |
PATH_DELIMITER |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases resources used by this instance.
|
void |
compose(java.lang.String bucketName,
java.util.List<java.lang.String> sources,
java.lang.String destination,
java.lang.String contentType)
Composes inputs into a single GCS object.
|
GoogleCloudStorageItemInfo |
composeObjects(java.util.List<StorageResourceId> sources,
StorageResourceId destination,
CreateObjectOptions options)
Composes inputs into a single GCS object.
|
void |
copy(java.lang.String srcBucketName,
java.util.List<java.lang.String> srcObjectNames,
java.lang.String dstBucketName,
java.util.List<java.lang.String> dstObjectNames)
Copies metadata of the given objects.
|
java.nio.channels.WritableByteChannel |
create(StorageResourceId resourceId)
Creates and opens an object for writing.
|
java.nio.channels.WritableByteChannel |
create(StorageResourceId resourceId,
CreateObjectOptions options)
Creates and opens an object for writing.
|
void |
create(java.lang.String bucketName)
Creates a bucket.
|
void |
create(java.lang.String bucketName,
CreateBucketOptions options)
Creates a bucket.
|
void |
createEmptyObject(StorageResourceId resourceId)
Creates an empty object, useful for placeholders representing, for example, directories.
|
void |
createEmptyObject(StorageResourceId resourceId,
CreateObjectOptions options)
Creates an empty object, useful for placeholders representing, for example, directories.
|
void |
createEmptyObjects(java.util.List<StorageResourceId> resourceIds)
Creates a list of empty objects; see
createEmptyObject(StorageResourceId) for
the single-item version of this method. |
void |
createEmptyObjects(java.util.List<StorageResourceId> resourceIds,
CreateObjectOptions options)
Creates a list of empty objects; see
createEmptyObject(StorageResourceId) for
the single-item version of this method. |
void |
deleteBuckets(java.util.List<java.lang.String> bucketNames)
Deletes a list of buckets.
|
void |
deleteObjects(java.util.List<StorageResourceId> fullObjectNames)
Deletes the given objects.
|
GoogleCloudStorageItemInfo |
getItemInfo(StorageResourceId resourceId)
Gets information about an object or a bucket.
|
java.util.List<GoogleCloudStorageItemInfo> |
getItemInfos(java.util.List<StorageResourceId> resourceIds)
Gets information about multiple objects and/or buckets.
|
GoogleCloudStorageOptions |
getOptions()
Retrieve the options that were used to create this GoogleCloudStorage.
|
java.util.List<GoogleCloudStorageItemInfo> |
listBucketInfo()
Gets a list of GoogleCloudStorageItemInfo for all buckets of this project.
|
java.util.List<java.lang.String> |
listBucketNames()
Gets a list of names of buckets in this project.
|
java.util.List<GoogleCloudStorageItemInfo> |
listObjectInfo(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter)
Same name-matching semantics as
listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well. |
java.util.List<GoogleCloudStorageItemInfo> |
listObjectInfo(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter,
long maxResults)
Same name-matching semantics as
listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well. |
GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> |
listObjectInfoPage(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter,
java.lang.String pageToken)
The same semantics as
listObjectInfo(java.lang.String, java.lang.String, java.lang.String), but returns only result of single list request
(1 page). |
java.util.List<java.lang.String> |
listObjectNames(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter)
Gets names of objects contained in the given bucket and whose names begin with
the given prefix.
|
java.util.List<java.lang.String> |
listObjectNames(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter,
long maxResults)
Gets names of objects contained in the given bucket and whose names begin with
the given prefix.
|
java.nio.channels.SeekableByteChannel |
open(StorageResourceId resourceId)
Opens an object for reading.
|
java.nio.channels.SeekableByteChannel |
open(StorageResourceId resourceId,
GoogleCloudStorageReadOptions readOptions)
Opens an object for reading.
|
java.util.List<GoogleCloudStorageItemInfo> |
updateItems(java.util.List<UpdatableItemInfo> itemInfoList)
Attempt to update metadata of the objects referenced within the passed itemInfo objects.
|
void |
waitForBucketEmpty(java.lang.String bucketName)
Waits for the given bucket to be empty.
|
static final java.lang.String PATH_DELIMITER
static final long MAX_RESULTS_UNLIMITED
static final int MAX_COMPOSE_OBJECTS
GoogleCloudStorageOptions getOptions()
java.nio.channels.WritableByteChannel create(StorageResourceId resourceId) throws java.io.IOException
resourceId doesn't have a explicit generationId set,
it is deleted. If a generationId is provided in resourceId, that is used in place
of normal overwrite semantics (overwrite will only succeed if the provided generationId
matches the existing object, where a generationId of 0 indicates no existing object expected).resourceId - identifies a StorageObjectjava.io.IOException - on IO errorjava.nio.channels.WritableByteChannel create(StorageResourceId resourceId, CreateObjectOptions options) throws java.io.IOException
resourceId
contains a known generationId or a generationId of 0, it is used instead of any "overwrite"
settings in the provided CreateObjectOptions (overwrite will only succeed if the
provided generationId matches the existing object, where a generationId of 0 indicates no
existing object expected).resourceId - identifies a StorageObjectoptions - Options to use when creating the objectjava.io.IOException - on IO errorvoid createEmptyObject(StorageResourceId resourceId) throws java.io.IOException
create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId()
is explicitly set.resourceId - identifies a StorageObjectjava.io.IOException - on IO errorvoid createEmptyObject(StorageResourceId resourceId, CreateObjectOptions options) throws java.io.IOException
create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId()
is explicitly set.resourceId - identifies a StorageObjectoptions - options to use when creating the objectjava.io.IOException - on IO errorvoid createEmptyObjects(java.util.List<StorageResourceId> resourceIds) throws java.io.IOException
createEmptyObject(StorageResourceId) for
the single-item version of this method. Implementations may use different flow than the
single-item version for greater efficiency.
See create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId()
is explicitly set.java.io.IOExceptionvoid createEmptyObjects(java.util.List<StorageResourceId> resourceIds, CreateObjectOptions options) throws java.io.IOException
createEmptyObject(StorageResourceId) for
the single-item version of this method. Implementations may use different flow than the
single-item version for greater efficiency.
See create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId()
is explicitly set.java.io.IOExceptionjava.nio.channels.SeekableByteChannel open(StorageResourceId resourceId) throws java.io.IOException
resourceId - identifies a StorageObjectjava.io.FileNotFoundException - if the given object does not existjava.io.IOException - if object exists but cannot be openedjava.nio.channels.SeekableByteChannel open(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws java.io.IOException
resourceId - identifies a StorageObjectreadOptions - Fine-grained options for behaviors of retries, buffering, etc.java.io.FileNotFoundException - if the given object does not existjava.io.IOException - if object exists but cannot be openedvoid create(java.lang.String bucketName)
throws java.io.IOException
bucketName - name of the bucket to createjava.io.IOException - on IO errorvoid create(java.lang.String bucketName,
CreateBucketOptions options)
throws java.io.IOException
bucketName - name of the bucket to createoptions - options to use when creating bucketjava.io.IOException - on IO errorvoid deleteBuckets(java.util.List<java.lang.String> bucketNames)
throws java.io.IOException
bucketNames - name of the buckets to deletejava.io.FileNotFoundException - if the given bucket does not existjava.io.IOException - on IO errorvoid deleteObjects(java.util.List<StorageResourceId> fullObjectNames) throws java.io.IOException
fullObjectNames - names of objects to delete with their respective bucketNames.java.io.FileNotFoundException - if the given object does not existjava.io.IOException - if object exists but cannot be deletedvoid copy(java.lang.String srcBucketName,
java.util.List<java.lang.String> srcObjectNames,
java.lang.String dstBucketName,
java.util.List<java.lang.String> dstObjectNames)
throws java.io.IOException
srcBucketName - name of the bucket containing the objects to copysrcObjectNames - names of the objects to copydstBucketName - name of the bucket to copy todstObjectNames - names of the objects after copyjava.io.FileNotFoundException - if the source object or the destination bucket does not
existjava.io.IOException - in all other error casesjava.util.List<java.lang.String> listBucketNames()
throws java.io.IOException
java.io.IOExceptionjava.util.List<GoogleCloudStorageItemInfo> listBucketInfo() throws java.io.IOException
java.io.IOExceptionjava.util.List<java.lang.String> listObjectNames(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter)
throws java.io.IOException
Note: Although GCS does not implement a file system, it treats objects that contain a delimiter as different from other objects when listing objects. This will be clearer with an example.
Consider a bucket with objects: o1, d1/, d1/o1, d1/o2 With prefix == null and delimiter == /, we get: d1/, o1 With prefix == null and delimiter == null, we get: o1, d1/, d1/o1, d1/o2
Thus when delimiter is null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.
The default implementation of this method should turn around and call
the version that takes maxResults so that inheriting classes
need only implement that version.
bucketName - bucket nameobjectNamePrefix - object name prefix or null if all objects in the bucket are desireddelimiter - delimiter to use (typically "/"), otherwise nulljava.io.IOException - on IO errorjava.util.List<java.lang.String> listObjectNames(java.lang.String bucketName,
java.lang.String objectNamePrefix,
java.lang.String delimiter,
long maxResults)
throws java.io.IOException
Note: Although GCS does not implement a file system, it treats objects that contain a delimiter as different from other objects when listing objects. This will be clearer with an example.
Consider a bucket with objects: o1, d1/, d1/o1, d1/o2 With prefix == null and delimiter == /, we get: d1/, o1 With prefix == null and delimiter == null, we get: o1, d1/, d1/o1, d1/o2
Thus when delimiter is null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.
bucketName - bucket nameobjectNamePrefix - object name prefix or null if all objects in the bucket are desireddelimiter - delimiter to use (typically "/"), otherwise nullmaxResults - maximum number of results to return,
unlimited if negative or zerojava.io.IOException - on IO errorjava.util.List<GoogleCloudStorageItemInfo> listObjectInfo(java.lang.String bucketName, java.lang.String objectNamePrefix, java.lang.String delimiter) throws java.io.IOException
listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well.
Generally the info is already available from the same "list()" calls, so the only additional cost is dispatching an extra batch request to retrieve object metadata for all listed directories, since these are originally listed as String prefixes without attached metadata.
The default implementation of this method should turn around and call the version that takes
maxResults so that inheriting classes need only implement that version.
bucketName - bucket nameobjectNamePrefix - object name prefix or null if all objects in the bucket are desireddelimiter - delimiter to use (typically "/"), otherwise nulljava.io.IOException - on IO errorjava.util.List<GoogleCloudStorageItemInfo> listObjectInfo(java.lang.String bucketName, java.lang.String objectNamePrefix, java.lang.String delimiter, long maxResults) throws java.io.IOException
listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well.
Generally the info is already available from the same "list()" calls, so the only additional cost is dispatching an extra batch request to retrieve object metadata for all listed directories, since these are originally listed as String prefixes without attached metadata.
bucketName - bucket nameobjectNamePrefix - object name prefix or null if all objects in the bucket are desireddelimiter - delimiter to use (typically "/"), otherwise nullmaxResults - maximum number of results to return, unlimited if negative or zerojava.io.IOException - on IO errorGoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(java.lang.String bucketName, java.lang.String objectNamePrefix, java.lang.String delimiter, java.lang.String pageToken) throws java.io.IOException
listObjectInfo(java.lang.String, java.lang.String, java.lang.String), but returns only result of single list request
(1 page).bucketName - bucket nameobjectNamePrefix - object name prefix or null if all objects in the bucket are desireddelimiter - delimiter to use (typically "/"), otherwise nullpageToken - the page tokenGoogleCloudStorage.ListPage object with listed GoogleCloudStorageItemInfos and next page
token if anyjava.io.IOException - on IO errorGoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws java.io.IOException
resourceId - identifies either root, a Bucket, or a StorageObjectjava.io.IOException - on IO errorjava.util.List<GoogleCloudStorageItemInfo> getItemInfos(java.util.List<StorageResourceId> resourceIds) throws java.io.IOException
resourceIds - names of the GCS StorageObjects or Buckets for which to retrieve info.java.io.IOException - on IO errorjava.util.List<GoogleCloudStorageItemInfo> updateItems(java.util.List<UpdatableItemInfo> itemInfoList) throws java.io.IOException
java.io.IOException - on IO errorvoid close()
void waitForBucketEmpty(java.lang.String bucketName)
throws java.io.IOException
java.io.IOExceptionvoid compose(java.lang.String bucketName,
java.util.List<java.lang.String> sources,
java.lang.String destination,
java.lang.String contentType)
throws java.io.IOException
bucketName - name of the bucket containing the sources and the destinationsources - names of the objects to be composeddestination - name of the resulting objectcontentType - content-type of composed objectjava.io.IOException - if the Compose operation was unsuccessfulGoogleCloudStorageItemInfo composeObjects(java.util.List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options) throws java.io.IOException
options. Overwrite semantics for the destination object will follow the
same semantics as create(StorageResourceId, CreateObjectOptions).
See create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId()
is explicitly set. The bucket must be the same for all sources and the destination.java.io.IOExceptionCopyright © 2019. All rights reserved.