Interface GoogleCloudStorage
-
- All Known Implementing Classes:
ForwardingGoogleCloudStorage,GoogleCloudStorageClientImpl,GoogleCloudStorageImpl,InMemoryGoogleCloudStorage,PerformanceCachingGoogleCloudStorage
public interface GoogleCloudStorageInterface for exposing the Google Cloud Storage API behavior in a way more amenable to writing filesystem semantics on top of it, without having to deal with API-specific considerations such as HttpTransports, credentials, network errors, batching, etc.Please read the following document to get familiarity with basic GCS concepts: https://developers.google.com/storage/docs/concepts-techniques
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classGoogleCloudStorage.ListPage<T>Paged list request response
-
Field Summary
Fields Modifier and Type Field Description static longLIST_MAX_RESULTSValue indicates the maxResult returned by gcs List API.static intMAX_COMPOSE_OBJECTSThe maximum number of objects that can be composed in one operation.static longMAX_RESULTS_UNLIMITEDValue indicating all objects should be returned from GCSFileSystem.static StringPATH_DELIMITERPseudo path delimiter.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Releases resources used by this instance.voidcompose(String bucketName, List<String> sources, String destination, String contentType)Composes inputs into a single GCS object.GoogleCloudStorageItemInfocomposeObjects(List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options)Composes inputs into a single GCS object.voidcopy(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames)Copies metadata of the given objects.default voidcopy(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap)Copies metadata of the given objects.default WritableByteChannelcreate(StorageResourceId resourceId)Creates and opens an object for writing.WritableByteChannelcreate(StorageResourceId resourceId, CreateObjectOptions options)Creates and opens an object for writing.default voidcreateBucket(String bucketName)Creates a bucket.voidcreateBucket(String bucketName, CreateBucketOptions options)Creates a bucket.voidcreateEmptyObject(StorageResourceId resourceId)Creates an empty object, useful for placeholders representing, for example, directories.voidcreateEmptyObject(StorageResourceId resourceId, CreateObjectOptions options)Creates an empty object, useful for placeholders representing, for example, directories.voidcreateEmptyObjects(List<StorageResourceId> resourceIds)Creates a list of empty objects; seecreateEmptyObject(StorageResourceId)for the single-item version of this method.voidcreateEmptyObjects(List<StorageResourceId> resourceIds, CreateObjectOptions options)Creates a list of empty objects; seecreateEmptyObject(StorageResourceId)for the single-item version of this method.voidcreateFolder(StorageResourceId folderId, boolean recursive)Creates a native GCS folder resource.voiddeleteBuckets(List<String> bucketNames)Deletes a list of buckets.voiddeleteFolders(List<FolderInfo> folders)Deletes the given folder resources.voiddeleteObjects(List<StorageResourceId> fullObjectNames)Deletes the given objects.GoogleCloudStorageItemInfogetFolderInfo(StorageResourceId resourceId)Gets the metadata for a single folder.GoogleCloudStorageItemInfogetItemInfo(StorageResourceId resourceId)Gets information about an object or a bucket.List<GoogleCloudStorageItemInfo>getItemInfos(List<StorageResourceId> resourceIds)Gets information about multiple objects and/or buckets.GoogleCloudStorageOptionsgetOptions()Retrieve the options that were used to create this GoogleCloudStorage.Map<String,Long>getStatistics()Retrieves the statistics associated with theGoogleCloudStorageinstance.booleanisHnBucket(URI path)Checks ifresourceIdbelongs 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)ListsGoogleCloudStorageItemInfoof objects contained in the given bucket and whose names begin with the given prefix.List<GoogleCloudStorageItemInfo>listObjectInfo(String bucketName, String objectNamePrefix, ListObjectOptions listOptions)ListsGoogleCloudStorageItemInfoof 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 aslistObjectInfo(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 aslistObjectInfo(java.lang.String, java.lang.String), but returns only result of single list request (1 page).default List<GoogleCloudStorageItemInfo>listObjectInfoStartingFrom(String bucketName, String startOffset)ListsGoogleCloudStorageItemInfoof objects contained in the given bucket and their name is lexicographically greater than or equal the provided offset.List<GoogleCloudStorageItemInfo>listObjectInfoStartingFrom(String bucketName, String startOffset, ListObjectOptions listOptions)ListsGoogleCloudStorageItemInfoof objects contained in the given bucket and their name is lexicographically greater than or equal the provided offset.voidmove(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap)Moves objects within the same bucket.default SeekableByteChannelopen(GoogleCloudStorageItemInfo itemInfo)Opens an object for reading using GoogleCloudStorageItemInfo.SeekableByteChannelopen(GoogleCloudStorageItemInfo itemInfo, GoogleCloudStorageReadOptions readOptions)Opens an object for reading using GoogleCloudStorageItemInfo.default SeekableByteChannelopen(StorageResourceId resourceId)Opens an object for reading.SeekableByteChannelopen(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions)Opens an object for reading.voidrenameHnFolder(URI src, URI dst)Renamessrctodstusing the rename LRO API.List<GoogleCloudStorageItemInfo>updateItems(List<UpdatableItemInfo> itemInfoList)Attempt to update metadata of the objects referenced within the passed itemInfo objects.
-
-
-
Field Detail
-
PATH_DELIMITER
static final String PATH_DELIMITER
Pseudo 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.
- See Also:
- Constant Field Values
-
MAX_RESULTS_UNLIMITED
static final long MAX_RESULTS_UNLIMITED
Value indicating all objects should be returned from GCSFileSystem. No limit i.e. get all possible items. Used while listing all files in a directory- See Also:
- Constant Field Values
-
LIST_MAX_RESULTS
static final long LIST_MAX_RESULTS
Value indicates the maxResult returned by gcs List API.- See Also:
- Constant Field Values
-
MAX_COMPOSE_OBJECTS
static final int MAX_COMPOSE_OBJECTS
The maximum number of objects that can be composed in one operation.- See Also:
- Constant Field Values
-
-
Method Detail
-
getOptions
GoogleCloudStorageOptions getOptions()
Retrieve the options that were used to create this GoogleCloudStorage.
-
create
default WritableByteChannel create(StorageResourceId resourceId) throws IOException
Creates and opens an object for writing. The bucket must already exist. If the object already exists andresourceIddoesn't have a explicit generationId set, it is deleted. If a generationId is provided inresourceId, 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).- Parameters:
resourceId- identifies a StorageObject- Returns:
- a channel for writing to the given object
- Throws:
IOException- on IO error
-
create
WritableByteChannel create(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
Creates and opens an object for writing. The bucket must already exist. IfresourceIdcontains a known generationId or a generationId of 0, it is used instead of any "overwrite" settings in the providedCreateObjectOptions(overwrite will only succeed if the provided generationId matches the existing object, where a generationId of 0 indicates no existing object expected).- Parameters:
resourceId- identifies a StorageObjectoptions- Options to use when creating the object- Returns:
- a channel for writing to the given object
- Throws:
IOException- on IO error
-
createBucket
default void createBucket(String bucketName) throws IOException
Creates a bucket.- Parameters:
bucketName- name of the bucket to create- Throws:
IOException- on IO error
-
createBucket
void createBucket(String bucketName, CreateBucketOptions options) throws IOException
Creates a bucket.- Parameters:
bucketName- name of the bucket to createoptions- options to use when creating bucket- Throws:
IOException- on IO error
-
createEmptyObject
void createEmptyObject(StorageResourceId resourceId) throws IOException
Creates an empty object, useful for placeholders representing, for example, directories. The bucket must already exist. If the object already exists, it is overwritten. Seecreate(StorageResourceId)for the behavior if StorageResourceId.getGenerationId() is explicitly set.- Parameters:
resourceId- identifies a StorageObject- Throws:
IOException- on IO error
-
createEmptyObject
void createEmptyObject(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
Creates an empty object, useful for placeholders representing, for example, directories. The bucket must already exist. If the object already exists, it is overwritten. Seecreate(StorageResourceId)for the behavior if StorageResourceId.getGenerationId() is explicitly set.- Parameters:
resourceId- identifies a StorageObjectoptions- options to use when creating the object- Throws:
IOException- on IO error
-
createEmptyObjects
void createEmptyObjects(List<StorageResourceId> resourceIds) throws IOException
Creates a list of empty objects; seecreateEmptyObject(StorageResourceId)for the single-item version of this method. Implementations may use different flow than the single-item version for greater efficiency. Seecreate(StorageResourceId)for the behavior if StorageResourceId.getGenerationId() is explicitly set.- Throws:
IOException
-
createEmptyObjects
void createEmptyObjects(List<StorageResourceId> resourceIds, CreateObjectOptions options) throws IOException
Creates a list of empty objects; seecreateEmptyObject(StorageResourceId)for the single-item version of this method. Implementations may use different flow than the single-item version for greater efficiency. Seecreate(StorageResourceId)for the behavior if StorageResourceId.getGenerationId() is explicitly set.- Throws:
IOException
-
open
default SeekableByteChannel open(StorageResourceId resourceId) throws IOException
Opens an object for reading.- Parameters:
resourceId- identifies a StorageObject- Returns:
- a channel for reading from the given object
- Throws:
FileNotFoundException- if the given object does not existIOException- if object exists but cannot be opened
-
open
SeekableByteChannel open(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws IOException
Opens an object for reading.- Parameters:
resourceId- identifies a StorageObjectreadOptions- Fine-grained options for behaviors of retries, buffering, etc.- Returns:
- a channel for reading from the given object
- Throws:
FileNotFoundException- if the given object does not existIOException- if object exists but cannot be opened
-
open
default SeekableByteChannel open(GoogleCloudStorageItemInfo itemInfo) throws IOException
Opens an object for reading using GoogleCloudStorageItemInfo.- Parameters:
itemInfo- identifies a StorageObject- Returns:
- a channel for reading from the given object
- Throws:
FileNotFoundException- if the given object does not existIOException- if object exists but cannot be opened
-
open
SeekableByteChannel open(GoogleCloudStorageItemInfo itemInfo, GoogleCloudStorageReadOptions readOptions) throws IOException
Opens an object for reading using GoogleCloudStorageItemInfo.- Parameters:
itemInfo- identifies a StorageObjectreadOptions- Fine-grained options for behaviors of retries, buffering, etc.- Returns:
- a channel for reading from the given object
- Throws:
FileNotFoundException- if the given object does not existIOException- if object exists but cannot be opened
-
deleteBuckets
void deleteBuckets(List<String> bucketNames) throws IOException
Deletes a list of buckets. Does not throw any exception for "bucket not found" errors.- Parameters:
bucketNames- name of the buckets to delete- Throws:
FileNotFoundException- if the given bucket does not existIOException- on IO error
-
deleteObjects
void deleteObjects(List<StorageResourceId> fullObjectNames) throws IOException
Deletes the given objects. Does not throw any exception for "object not found" errors.- Parameters:
fullObjectNames- names of objects to delete with their respective bucketNames.- Throws:
FileNotFoundException- if the given object does not existIOException- if object exists but cannot be deleted
-
getFolderInfo
GoogleCloudStorageItemInfo getFolderInfo(StorageResourceId resourceId) throws IOException
Gets the metadata for a single folder.- Parameters:
resourceId- The StorageResourceId of the folder.- Throws:
IOException- on IO error.
-
createFolder
void createFolder(StorageResourceId folderId, boolean recursive) throws IOException
Creates a native GCS folder resource. Applicable only for Hierarchical Namespace (HNS) enabled buckets.- Parameters:
folderId- The StorageResourceId of the folder to create.recursive- If true, creates all nonexistent parent folders in the path.- Throws:
IOException- if the folder cannot be created, or if it already exists and is not a folder.
-
deleteFolders
void deleteFolders(List<FolderInfo> folders) throws IOException
Deletes the given folder resources. Does not throw any exception for "folders not found" errors.- Parameters:
folders- names of folder resources to delete- Throws:
IOException- if folder exists but cannot be deleted
-
copy
void copy(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames) throws IOException
Copies metadata of the given objects. After the copy is successfully complete, each object blob is reachable by two different names. Copying between two different locations or between two different storage classes is not allowed.- Parameters:
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 copy- Throws:
FileNotFoundException- if the source object or the destination bucket does not existIOException- in all other error cases
-
copy
default void copy(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap) throws IOException
Copies metadata of the given objects. After the copy is successfully complete, each object blob is reachable by two different names. Copying between two different locations or between two different storage classes is not allowed.- Parameters:
sourceToDestinationObjectsMap- map of destination objects to be copied, keyed by source- Throws:
FileNotFoundException- if the source object or the destination bucket does not existIOException- in all other error cases
-
move
void move(Map<StorageResourceId,StorageResourceId> sourceToDestinationObjectsMap) throws IOException
Moves objects within the same bucket. Moving objects between different buckets is not allowed.- Parameters:
sourceToDestinationObjectsMap- map of destination objects to be moved, keyed by source- Throws:
FileNotFoundException- if the source object or the destination bucket does not existIOException- in all other error cases
-
isHnBucket
boolean isHnBucket(URI path) throws IOException
Checks ifresourceIdbelongs 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.- Parameters:
path- Path for which the check need to be performed- Returns:
- Throws:
IOException
-
listBucketNames
List<String> listBucketNames() throws IOException
Gets a list of names of buckets in this project.- Throws:
IOException
-
renameHnFolder
void renameHnFolder(URI src, URI dst) throws IOException
Renamessrctodstusing the rename LRO API. This should be called only on an Hierarchical namespace enabled bucket.- Parameters:
src- source pathdst- destination path- Throws:
IOException
-
listBucketInfo
List<GoogleCloudStorageItemInfo> listBucketInfo() throws IOException
Gets a list of GoogleCloudStorageItemInfo for all buckets of this project. This is no more expensive than calling listBucketNames(), since the list API for buckets already retrieves all the relevant bucket metadata.- Throws:
IOException
-
listObjectInfo
default List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix) throws IOException
ListsGoogleCloudStorageItemInfoof 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-
With
prefix == nullanddelimiter == /, we get:d1/,o1Withprefix == nullanddelimiter == null, we get:o1,d1/,d1/o1,d1/o2Thus when delimiter is
null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.- Parameters:
bucketName- bucket nameobjectNamePrefix- object name prefix or null if all objects in the bucket are desired- Returns:
- list of objects
- Throws:
IOException- on IO error
-
listObjectInfoStartingFrom
default List<GoogleCloudStorageItemInfo> listObjectInfoStartingFrom(String bucketName, String startOffset) throws IOException
ListsGoogleCloudStorageItemInfoof objects contained in the given bucket and their name is lexicographically greater than or equal the provided offset.Note: As GCS doesn't implement a file system, directory is also treated as an object (if it's been created). This APi filters out all those directory object and maintain the order of items. This APi strictly expects delimiter in listOptions to be not set.
Consider a bucket with objects:
o1,d1/,d1/o1,d1/o2-
With
startOffset == "o1", we get:o1WithstartOffset == "d1/", we get:d1/o1d1/o2WithstartOffset == "d1/"o1, we get:d1/o1d1/o2This is an experimental API and can change without notice.
- Parameters:
bucketName- bucket namestartOffset- offset sting, all object with name greater and equal will be listed.- Returns:
- list of objects
- Throws:
IOException- on IO error
-
listObjectInfo
List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, ListObjectOptions listOptions) throws IOException
ListsGoogleCloudStorageItemInfoof 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-
With
prefix == nullanddelimiter == /, we get:d1/,o1Withprefix == nullanddelimiter == null, we get:o1,d1/,d1/o1,d1/o2Thus when delimiter is
null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.- Parameters:
bucketName- bucket nameobjectNamePrefix- object name prefix or null if all objects in the bucket are desiredlistOptions- options to use when listing objects- Returns:
- list of objects
- Throws:
IOException- on IO error
-
listObjectInfoStartingFrom
List<GoogleCloudStorageItemInfo> listObjectInfoStartingFrom(String bucketName, String startOffset, ListObjectOptions listOptions) throws IOException
ListsGoogleCloudStorageItemInfoof objects contained in the given bucket and their name is lexicographically greater than or equal the provided offset.Note: As GCS doesn't implement a file system, directory is also treated as an object (if it's been created). This APi filters out all those directory object and maintain the order of items. This APi strictly expects delimiter in listOptions to be not set.
Consider a bucket with objects:
o1,d1/,d1/o1,d1/o2-
With
startOffset == "o1", we get:o1WithstartOffset == "d1/", we get:d1/o1d1/o2WithstartOffset == "d1/"o1, we get:d1/o1d1/o2This is an experimental API and can change without notice.
- Parameters:
bucketName- bucket namestartOffset- offset sting, all object with name greater and equal will be listed.listOptions- options to use when listing objects- Returns:
- list of objects
- Throws:
IOException- on IO error
-
listObjectInfoPage
default GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, String pageToken) throws IOException
The same semantics aslistObjectInfo(java.lang.String, java.lang.String), but returns only result of single list request (1 page).- Parameters:
bucketName- bucket nameobjectNamePrefix- object name prefix or null if all objects in the bucket are desiredpageToken- the page token- Returns:
GoogleCloudStorage.ListPageobject with listedGoogleCloudStorageItemInfos and next page token if any- Throws:
IOException- on IO error
-
listObjectInfoPage
GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, ListObjectOptions listOptions, String pageToken) throws IOException
The same semantics aslistObjectInfo(java.lang.String, java.lang.String), but returns only result of single list request (1 page).- Parameters:
bucketName- bucket nameobjectNamePrefix- object name prefix or null if all objects in the bucket are desiredlistOptions- options to use when listing objectspageToken- the page token- Returns:
GoogleCloudStorage.ListPageobject with listedGoogleCloudStorageItemInfos and next page token if any- Throws:
IOException- on IO error
-
listFolderInfoForPrefixPage
GoogleCloudStorage.ListPage<FolderInfo> listFolderInfoForPrefixPage(String bucketName, String folderNamePrefix, ListFolderOptions listFolderOptions, String pageToken) throws IOException
Returns the list of folder resources. Applicable only for HN enabled bucket- Parameters:
bucketName- bucket namefolderNamePrefix- folder resource name prefixlistFolderOptions- options to use when listing folder resourcespageToken- the page token- Returns:
GoogleCloudStorage.ListPagefolder resources with listedFolders- Throws:
IOException- on IO error
-
getItemInfo
GoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws IOException
Gets information about an object or a bucket.- Parameters:
resourceId- identifies either root, a Bucket, or a StorageObject- Returns:
- information about the given item
- Throws:
IOException- on IO error
-
getItemInfos
List<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds) throws IOException
Gets information about multiple objects and/or buckets. Items that are "not found" will still have an entry in the returned list; exists() will return false for these entries. The return list will have the same ordering as the input arguments.- Parameters:
resourceIds- names of the GCS StorageObjects or Buckets for which to retrieve info.- Returns:
- information about the given resourceIds.
- Throws:
IOException- on IO error
-
updateItems
List<GoogleCloudStorageItemInfo> updateItems(List<UpdatableItemInfo> itemInfoList) throws IOException
Attempt to update metadata of the objects referenced within the passed itemInfo objects.- Returns:
- Updated GoogleCloudStorageItemInfo objects for the referenced objects.
- Throws:
IOException- on IO error
-
compose
void compose(String bucketName, List<String> sources, String destination, String contentType) throws IOException
Composes inputs into a single GCS object. This performs a GCS Compose. Objects will be composed according to the order they appear in the input. The destination object, if already present, will be overwritten. Sources and destination are assumed to be in the same bucket.- Parameters:
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 object- Throws:
IOException- if the Compose operation was unsuccessful
-
composeObjects
GoogleCloudStorageItemInfo composeObjects(List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options) throws IOException
Composes inputs into a single GCS object. This performs a GCS Compose. Objects will be composed according to the order they appear in the input. The destination object will have metadata set according tooptions. Overwrite semantics for the destination object will follow the same semantics ascreate(StorageResourceId, CreateObjectOptions). Seecreate(StorageResourceId)for the behavior if StorageResourceId.getGenerationId() is explicitly set. The bucket must be the same for all sources and the destination.- Throws:
IOException
-
getStatistics
Map<String,Long> getStatistics()
Retrieves the statistics associated with theGoogleCloudStorageinstance.
-
close
void close()
Releases resources used by this instance.
-
-