public class GoogleCloudStorageImpl extends Object implements GoogleCloudStorage
Modifier and Type | Class and Description |
---|---|
static interface |
GoogleCloudStorageImpl.BackOffFactory
A factory for producing BackOff objects.
|
GoogleCloudStorage.ListPage<T>
Modifier and Type | Field and Description |
---|---|
static int |
BUCKET_EMPTY_MAX_RETRIES |
static int |
BUCKET_EMPTY_WAIT_TIME_MS |
MAX_COMPOSE_OBJECTS, MAX_RESULTS_UNLIMITED, PATH_DELIMITER
Modifier | Constructor and Description |
---|---|
protected |
GoogleCloudStorageImpl() |
|
GoogleCloudStorageImpl(GoogleCloudStorageOptions options,
com.google.api.client.auth.oauth2.Credential credential)
Constructs an instance of GoogleCloudStorageImpl.
|
|
GoogleCloudStorageImpl(GoogleCloudStorageOptions options,
com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) |
|
GoogleCloudStorageImpl(GoogleCloudStorageOptions options,
com.google.api.services.storage.Storage gcs)
Constructs an instance of GoogleCloudStorageImpl.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
See
GoogleCloudStorage.close() for details about expected behavior. |
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.
|
void |
copy(String srcBucketName,
List<String> srcObjectNames,
String dstBucketName,
List<String> dstObjectNames)
See
GoogleCloudStorage.copy(String, List, String, List) for details about expected
behavior. |
WritableByteChannel |
create(StorageResourceId resourceId)
See
GoogleCloudStorage.create(StorageResourceId) for details about expected behavior. |
WritableByteChannel |
create(StorageResourceId resourceId,
CreateObjectOptions options)
Creates and opens an object for writing.
|
void |
create(String bucketName)
See
GoogleCloudStorage.create(String) for details about expected behavior. |
void |
create(String bucketName,
CreateBucketOptions options)
See
GoogleCloudStorage.create(String, CreateBucketOptions) for details about expected
behavior. |
void |
createEmptyObject(StorageResourceId resourceId)
See
GoogleCloudStorage.createEmptyObject(StorageResourceId) for details about expected
behavior. |
void |
createEmptyObject(StorageResourceId resourceId,
CreateObjectOptions options)
Creates an empty object, useful for placeholders representing, for example, directories.
|
void |
createEmptyObjects(List<StorageResourceId> resourceIds)
See
GoogleCloudStorage.createEmptyObjects(List) for details about
expected behavior. |
void |
createEmptyObjects(List<StorageResourceId> resourceIds,
CreateObjectOptions options)
Creates a list of empty objects; see
GoogleCloudStorage.createEmptyObject(StorageResourceId) for
the single-item version of this method. |
static GoogleCloudStorageItemInfo |
createItemInfoForBucket(StorageResourceId resourceId,
com.google.api.services.storage.model.Bucket bucket)
Helper for converting a StorageResourceId + Bucket into a GoogleCloudStorageItemInfo.
|
static GoogleCloudStorageItemInfo |
createItemInfoForStorageObject(StorageResourceId resourceId,
com.google.api.services.storage.model.StorageObject object)
Helper for converting a StorageResourceId + StorageObject into a GoogleCloudStorageItemInfo.
|
void |
deleteBuckets(List<String> bucketNames)
See
GoogleCloudStorage.deleteBuckets(List) for details about expected behavior. |
void |
deleteObject(StorageResourceId resourceId,
long metaGeneration) |
void |
deleteObjects(List<StorageResourceId> fullObjectNames)
See
GoogleCloudStorage.deleteObjects(List) for details about expected behavior. |
GoogleCloudStorageItemInfo |
getItemInfo(StorageResourceId resourceId)
See
GoogleCloudStorage.getItemInfo(StorageResourceId) for details about expected
behavior. |
List<GoogleCloudStorageItemInfo> |
getItemInfos(List<StorageResourceId> resourceIds)
See
GoogleCloudStorage.getItemInfos(List) for details about expected behavior. |
GoogleCloudStorageOptions |
getOptions()
Retrieve the options that were used to create this GoogleCloudStorage.
|
List<GoogleCloudStorageItemInfo> |
listBucketInfo()
See
GoogleCloudStorage.listBucketInfo() for details about expected behavior. |
List<String> |
listBucketNames()
See
GoogleCloudStorage.listBucketNames() for details about expected behavior. |
List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix,
String delimiter)
See
GoogleCloudStorage.listObjectInfo(String, String, String) for details about
expected behavior. |
List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix,
String delimiter,
long maxResults)
See
GoogleCloudStorage.listObjectInfo(String, String, String, long) for details about
expected behavior. |
GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> |
listObjectInfoPage(String bucketName,
String objectNamePrefix,
String delimiter,
String pageToken)
The same semantics as
GoogleCloudStorage.listObjectInfo(java.lang.String, java.lang.String, java.lang.String) , but returns only result of single list request
(1 page). |
List<String> |
listObjectNames(String bucketName,
String objectNamePrefix,
String delimiter)
See
GoogleCloudStorage.listObjectNames(String, String, String)
for details about expected behavior. |
List<String> |
listObjectNames(String bucketName,
String objectNamePrefix,
String delimiter,
long maxResults)
See
GoogleCloudStorage.listObjectNames(String, String, String, long) for details about
expected behavior. |
SeekableByteChannel |
open(StorageResourceId resourceId)
See
GoogleCloudStorage.open(StorageResourceId) for details about expected behavior. |
SeekableByteChannel |
open(StorageResourceId resourceId,
GoogleCloudStorageReadOptions readOptions)
See
GoogleCloudStorage.open(StorageResourceId) for details about expected behavior. |
List<GoogleCloudStorageItemInfo> |
updateItems(List<UpdatableItemInfo> itemInfoList)
Attempt to update metadata of the objects referenced within the passed itemInfo objects.
|
void |
updateMetadata(GoogleCloudStorageItemInfo itemInfo,
Map<String,byte[]> metadata) |
static void |
validateCopyArguments(String srcBucketName,
List<String> srcObjectNames,
String dstBucketName,
List<String> dstObjectNames,
GoogleCloudStorage gcsImpl)
Validates basic argument constraints like non-null, non-empty Strings, using
Preconditions in addition to checking for src/dst bucket existence and compatibility of bucket
properties such as location and storage-class. |
public static final int BUCKET_EMPTY_MAX_RETRIES
public static final int BUCKET_EMPTY_WAIT_TIME_MS
public GoogleCloudStorageImpl(GoogleCloudStorageOptions options, com.google.api.client.auth.oauth2.Credential credential) throws IOException
credential
- OAuth2 credential that allows access to GCSIOException
- on IO errorpublic GoogleCloudStorageImpl(GoogleCloudStorageOptions options, com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) throws IOException
IOException
public GoogleCloudStorageImpl(GoogleCloudStorageOptions options, com.google.api.services.storage.Storage gcs)
gcs
- Preconstructed Storage to use for I/O.protected GoogleCloudStorageImpl()
public GoogleCloudStorageOptions getOptions()
GoogleCloudStorage
getOptions
in interface GoogleCloudStorage
public WritableByteChannel create(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
GoogleCloudStorage
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).create
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectoptions
- Options to use when creating the objectIOException
- on IO errorpublic WritableByteChannel create(StorageResourceId resourceId) throws IOException
GoogleCloudStorage.create(StorageResourceId)
for details about expected behavior.create
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectIOException
- on IO errorpublic void create(String bucketName) throws IOException
GoogleCloudStorage.create(String)
for details about expected behavior.create
in interface GoogleCloudStorage
bucketName
- name of the bucket to createIOException
- on IO errorpublic void create(String bucketName, CreateBucketOptions options) throws IOException
GoogleCloudStorage.create(String, CreateBucketOptions)
for details about expected
behavior.create
in interface GoogleCloudStorage
bucketName
- name of the bucket to createoptions
- options to use when creating bucketIOException
- on IO errorpublic void createEmptyObject(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
GoogleCloudStorage
GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set.createEmptyObject
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectoptions
- options to use when creating the objectIOException
- on IO errorpublic void createEmptyObject(StorageResourceId resourceId) throws IOException
GoogleCloudStorage.createEmptyObject(StorageResourceId)
for details about expected
behavior.createEmptyObject
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectIOException
- on IO errorpublic void updateMetadata(GoogleCloudStorageItemInfo itemInfo, Map<String,byte[]> metadata) throws IOException
IOException
public void createEmptyObjects(List<StorageResourceId> resourceIds, CreateObjectOptions options) throws IOException
GoogleCloudStorage
GoogleCloudStorage.createEmptyObject(StorageResourceId)
for
the single-item version of this method. Implementations may use different flow than the
single-item version for greater efficiency.
See GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set.createEmptyObjects
in interface GoogleCloudStorage
IOException
public void createEmptyObjects(List<StorageResourceId> resourceIds) throws IOException
GoogleCloudStorage.createEmptyObjects(List)
for details about
expected behavior.createEmptyObjects
in interface GoogleCloudStorage
IOException
public SeekableByteChannel open(StorageResourceId resourceId) throws IOException
GoogleCloudStorage.open(StorageResourceId)
for details about expected behavior.open
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectFileNotFoundException
- if the given object does not existIOException
- if object exists but cannot be openedpublic SeekableByteChannel open(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws IOException
GoogleCloudStorage.open(StorageResourceId)
for details about expected behavior.open
in interface GoogleCloudStorage
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 openedpublic void deleteBuckets(List<String> bucketNames) throws IOException
GoogleCloudStorage.deleteBuckets(List)
for details about expected behavior.deleteBuckets
in interface GoogleCloudStorage
bucketNames
- name of the buckets to deleteFileNotFoundException
- if the given bucket does not existIOException
- on IO errorpublic void deleteObject(StorageResourceId resourceId, long metaGeneration) throws IOException
IOException
public void deleteObjects(List<StorageResourceId> fullObjectNames) throws IOException
GoogleCloudStorage.deleteObjects(List)
for details about expected behavior.deleteObjects
in interface GoogleCloudStorage
fullObjectNames
- names of objects to delete with their respective bucketNames.FileNotFoundException
- if the given object does not existIOException
- if object exists but cannot be deletedpublic static void validateCopyArguments(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames, GoogleCloudStorage gcsImpl) throws IOException
Preconditions
in addition to checking for src/dst bucket existence and compatibility of bucket
properties such as location and storage-class.gcsImpl
- A GoogleCloudStorage for retrieving bucket info via getItemInfo, but only if
srcBucketName != dstBucketName; passed as a parameter so that this static method can be
used by other implementations of GoogleCloudStorage that want to preserve the validation
behavior of GoogleCloudStorageImpl, including disallowing cross-location copies.IOException
public void copy(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames) throws IOException
GoogleCloudStorage.copy(String, List, String, List)
for details about expected
behavior.copy
in interface GoogleCloudStorage
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 casespublic List<String> listBucketNames() throws IOException
GoogleCloudStorage.listBucketNames()
for details about expected behavior.listBucketNames
in interface GoogleCloudStorage
IOException
public List<GoogleCloudStorageItemInfo> listBucketInfo() throws IOException
GoogleCloudStorage.listBucketInfo()
for details about expected behavior.listBucketInfo
in interface GoogleCloudStorage
IOException
public List<String> listObjectNames(String bucketName, String objectNamePrefix, String delimiter) throws IOException
GoogleCloudStorage.listObjectNames(String, String, String)
for details about expected behavior.listObjectNames
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullIOException
- on IO errorpublic List<String> listObjectNames(String bucketName, String objectNamePrefix, String delimiter, long maxResults) throws IOException
GoogleCloudStorage.listObjectNames(String, String, String, long)
for details about
expected behavior.listObjectNames
in interface GoogleCloudStorage
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 zeroIOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, String delimiter) throws IOException
GoogleCloudStorage.listObjectInfo(String, String, String)
for details about
expected behavior.listObjectInfo
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullIOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, String delimiter, long maxResults) throws IOException
GoogleCloudStorage.listObjectInfo(String, String, String, long)
for details about
expected behavior.listObjectInfo
in interface GoogleCloudStorage
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 zeroIOException
- on IO errorpublic GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, String delimiter, String pageToken) throws IOException
GoogleCloudStorage
GoogleCloudStorage.listObjectInfo(java.lang.String, java.lang.String, java.lang.String)
, but returns only result of single list request
(1 page).listObjectInfoPage
in interface GoogleCloudStorage
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 GoogleCloudStorageItemInfo
s and next page
token if anyIOException
- on IO errorpublic static GoogleCloudStorageItemInfo createItemInfoForBucket(StorageResourceId resourceId, com.google.api.services.storage.model.Bucket bucket)
public static GoogleCloudStorageItemInfo createItemInfoForStorageObject(StorageResourceId resourceId, com.google.api.services.storage.model.StorageObject object)
public List<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds) throws IOException
GoogleCloudStorage.getItemInfos(List)
for details about expected behavior.getItemInfos
in interface GoogleCloudStorage
resourceIds
- names of the GCS StorageObjects or Buckets for which to retrieve info.IOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> updateItems(List<UpdatableItemInfo> itemInfoList) throws IOException
GoogleCloudStorage
updateItems
in interface GoogleCloudStorage
IOException
- on IO errorpublic GoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws IOException
GoogleCloudStorage.getItemInfo(StorageResourceId)
for details about expected
behavior.getItemInfo
in interface GoogleCloudStorage
resourceId
- identifies either root, a Bucket, or a StorageObjectIOException
- on IO errorpublic void close()
GoogleCloudStorage.close()
for details about expected behavior.close
in interface GoogleCloudStorage
public void compose(String bucketName, List<String> sources, String destination, String contentType) throws IOException
GoogleCloudStorage
compose
in interface GoogleCloudStorage
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 unsuccessfulpublic GoogleCloudStorageItemInfo composeObjects(List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options) throws IOException
GoogleCloudStorage
options
. Overwrite semantics for the destination object will follow the
same semantics as GoogleCloudStorage.create(StorageResourceId, CreateObjectOptions)
.
See GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set. The bucket must be the same for all sources and the destination.composeObjects
in interface GoogleCloudStorage
IOException
Copyright © 2019. All rights reserved.