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 String |
PATH_DELIMITER
Pseudo path delimiter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases resources used by this instance.
|
void |
compose(String bucketName,
List<String> sources,
String destination,
String contentType)
Composes inputs into a single GCS object.
|
GoogleCloudStorageItemInfo |
composeObjects(List<StorageResourceId> sources,
StorageResourceId destination,
CreateObjectOptions options)
Composes inputs into a single GCS object.
|
default void |
copy(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap)
Copies metadata of the given objects.
|
void |
copy(String srcBucketName,
List<String> srcObjectNames,
String dstBucketName,
List<String> dstObjectNames)
Copies metadata of the given objects.
|
default WritableByteChannel |
create(StorageResourceId resourceId)
Creates and opens an object for writing.
|
WritableByteChannel |
create(StorageResourceId resourceId,
CreateObjectOptions options)
Creates and opens an object for writing.
|
default void |
createBucket(String bucketName)
Creates a bucket.
|
void |
createBucket(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(List<StorageResourceId> resourceIds)
Creates a list of empty objects; see
createEmptyObject(StorageResourceId) for the
single-item version of this method. |
void |
createEmptyObjects(List<StorageResourceId> resourceIds,
CreateObjectOptions options)
Creates a list of empty objects; see
createEmptyObject(StorageResourceId) for the
single-item version of this method. |
void |
deleteBuckets(List<String> bucketNames)
Deletes a list of buckets.
|
void |
deleteFolders(List<FolderInfo> folders)
Deletes the given folder resources.
|
void |
deleteObjects(List<StorageResourceId> fullObjectNames)
Deletes the given objects.
|
GoogleCloudStorageItemInfo |
getItemInfo(StorageResourceId resourceId)
Gets information about an object or a bucket.
|
List<GoogleCloudStorageItemInfo> |
getItemInfos(List<StorageResourceId> resourceIds)
Gets information about multiple objects and/or buckets.
|
GoogleCloudStorageOptions |
getOptions()
Retrieve the options that were used to create this GoogleCloudStorage.
|
boolean |
isHnBucket(URI path)
Checks if
resourceId belongs to a Hierarchical namespace enabled bucket. |
List<GoogleCloudStorageItemInfo> |
listBucketInfo()
Gets a list of GoogleCloudStorageItemInfo for all buckets of this project.
|
List<String> |
listBucketNames()
Gets a list of names of buckets in this project.
|
GoogleCloudStorage.ListPage<FolderInfo> |
listFolderInfoForPrefixPage(String bucketName,
String folderNamePrefix,
ListFolderOptions listFolderOptions,
String pageToken)
Returns the list of folder resources.
|
default List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix)
Lists
GoogleCloudStorageItemInfo of objects contained in the given bucket and whose
names begin with the given prefix. |
List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix,
ListObjectOptions listOptions)
Lists
GoogleCloudStorageItemInfo of objects contained in the given bucket and whose
names begin with the given prefix. |
GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> |
listObjectInfoPage(String bucketName,
String objectNamePrefix,
ListObjectOptions listOptions,
String pageToken)
The same semantics as
listObjectInfo(java.lang.String, java.lang.String), but returns only result of single list request
(1 page). |
default GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> |
listObjectInfoPage(String bucketName,
String objectNamePrefix,
String pageToken)
The same semantics as
listObjectInfo(java.lang.String, java.lang.String), but returns only result of single list request
(1 page). |
default SeekableByteChannel |
open(StorageResourceId resourceId)
Opens an object for reading.
|
SeekableByteChannel |
open(StorageResourceId resourceId,
GoogleCloudStorageReadOptions readOptions)
Opens an object for reading.
|
void |
renameHnFolder(URI src,
URI dst)
Renames
src to dst using the rename LRO API. |
List<GoogleCloudStorageItemInfo> |
updateItems(List<UpdatableItemInfo> itemInfoList)
Attempt to update metadata of the objects referenced within the passed itemInfo objects.
|
static final String PATH_DELIMITER
GCS does not implement full concept of file system paths but it does expose some notion of a delimiter that can be used with ${code Storage.Objects.List} to control which items are listed.
static final long MAX_RESULTS_UNLIMITED
static final int MAX_COMPOSE_OBJECTS
GoogleCloudStorageOptions getOptions()
default WritableByteChannel create(StorageResourceId resourceId) throws 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 StorageObjectIOException - on IO errorWritableByteChannel create(StorageResourceId resourceId, CreateObjectOptions options) throws 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 objectIOException - on IO errordefault void createBucket(String bucketName) throws IOException
bucketName - name of the bucket to createIOException - on IO errorvoid createBucket(String bucketName, CreateBucketOptions options) throws IOException
bucketName - name of the bucket to createoptions - options to use when creating bucketIOException - on IO errorvoid createEmptyObject(StorageResourceId resourceId) throws IOException
create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId() is
explicitly set.resourceId - identifies a StorageObjectIOException - on IO errorvoid createEmptyObject(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
create(StorageResourceId) for the behavior if StorageResourceId.getGenerationId() is
explicitly set.resourceId - identifies a StorageObjectoptions - options to use when creating the objectIOException - on IO errorvoid createEmptyObjects(List<StorageResourceId> resourceIds) throws 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.IOExceptionvoid createEmptyObjects(List<StorageResourceId> resourceIds, CreateObjectOptions options) throws 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.IOExceptiondefault SeekableByteChannel open(StorageResourceId resourceId) throws IOException
resourceId - identifies a StorageObjectFileNotFoundException - if the given object does not existIOException - if object exists but cannot be openedSeekableByteChannel open(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws IOException
resourceId - identifies a StorageObjectreadOptions - Fine-grained options for behaviors of retries, buffering, etc.FileNotFoundException - if the given object does not existIOException - if object exists but cannot be openedvoid deleteBuckets(List<String> bucketNames) throws IOException
bucketNames - name of the buckets to deleteFileNotFoundException - if the given bucket does not existIOException - on IO errorvoid deleteObjects(List<StorageResourceId> fullObjectNames) throws IOException
fullObjectNames - names of objects to delete with their respective bucketNames.FileNotFoundException - if the given object does not existIOException - if object exists but cannot be deletedvoid deleteFolders(List<FolderInfo> folders) throws IOException
folders - names of folder resources to deleteIOException - if folder exists but cannot be deletedvoid copy(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames) throws 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 copyFileNotFoundException - if the source object or the destination bucket does not
existIOException - in all other error casesdefault void copy(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap) throws IOException
sourceToDestinationObjectsMap - map of destination objects to be copied, keyed by sourceFileNotFoundException - if the source object or the destination bucket does not
existIOException - in all other error casesboolean isHnBucket(URI path) throws IOException
resourceId belongs to a Hierarchical namespace enabled bucket. This takes a
path and not the bucket name since the caller may not have permission to query the bucket.path - Path for which the check need to be performedIOExceptionList<String> listBucketNames() throws IOException
IOExceptionvoid renameHnFolder(URI src, URI dst) throws IOException
src to dst using the rename LRO API. This should be called only on an
Hierarchical namespace enabled bucket.src - source pathdst - destination pathIOExceptionList<GoogleCloudStorageItemInfo> listBucketInfo() throws IOException
IOExceptiondefault List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix) throws IOException
GoogleCloudStorageItemInfo of objects contained in the given bucket and whose
names begin with the given prefix.
Note: Although GCS does not implement a file system, it treats objects that contain a
delimiter (ListObjectOptions.getDelimiter()) 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
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 desiredIOException - on IO errorList<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, ListObjectOptions listOptions) throws IOException
GoogleCloudStorageItemInfo of objects contained in the given bucket and whose
names begin with the given prefix.
Note: Although GCS does not implement a file system, it treats objects that contain a
delimiter (ListObjectOptions.getDelimiter()) 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
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 desiredlistOptions - options to use when listing objectsIOException - on IO errordefault GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, String pageToken) throws IOException
listObjectInfo(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 desiredpageToken - the page tokenGoogleCloudStorage.ListPage object with listed GoogleCloudStorageItemInfos and next page
token if anyIOException - on IO errorGoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, ListObjectOptions listOptions, String pageToken) throws IOException
listObjectInfo(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 desiredlistOptions - options to use when listing objectspageToken - the page tokenGoogleCloudStorage.ListPage object with listed GoogleCloudStorageItemInfos and next page
token if anyIOException - on IO errorGoogleCloudStorage.ListPage<FolderInfo> listFolderInfoForPrefixPage(String bucketName, String folderNamePrefix, ListFolderOptions listFolderOptions, String pageToken) throws IOException
bucketName - bucket namefolderNamePrefix - folder resource name prefixlistFolderOptions - options to use when listing folder resourcespageToken - the page tokenGoogleCloudStorage.ListPage folder resources with listed FoldersIOException - on IO errorGoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws IOException
resourceId - identifies either root, a Bucket, or a StorageObjectIOException - on IO errorList<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds) throws IOException
resourceIds - names of the GCS StorageObjects or Buckets for which to retrieve info.IOException - on IO errorList<GoogleCloudStorageItemInfo> updateItems(List<UpdatableItemInfo> itemInfoList) throws IOException
IOException - on IO errorvoid compose(String bucketName, List<String> sources, String destination, String contentType) throws 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 objectIOException - if the Compose operation was unsuccessfulGoogleCloudStorageItemInfo composeObjects(List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options) throws 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.IOExceptionvoid close()
Copyright © 2024. All rights reserved.