Package com.google.cloud.storage
Class StorageBatch
java.lang.Object
com.google.cloud.storage.StorageBatch
A batch of operations to be submitted to Google Cloud Storage using a single RPC request.
Example of using a batch request to delete, update and get a blob:
StorageBatch batch = storage.batch();
BlobId firstBlob = BlobId.of("bucket", "blob1"));
BlobId secondBlob = BlobId.of("bucket", "blob2"));
batch.delete(firstBlob).notify(new BatchResult.Callback<Boolean, StorageException>() {
public void success(Boolean result) {
// deleted successfully
}
public void error(StorageException exception) {
// delete failed
}
});
batch.update(BlobInfo.builder(secondBlob).contentType("text/plain").build());
StorageBatchResult<Blob> result = batch.get(secondBlob);
batch.submit();
Blob blob = result.get(); // returns get result or throws StorageException
-
Method Summary
Modifier and TypeMethodDescriptiondelete
(BlobId blob, Storage.BlobSourceOption... options) Adds a request representing the "delete blob" operation to this batch.delete
(String bucket, String blob, Storage.BlobSourceOption... options) Adds a request representing the "delete blob" operation to this batch.get
(BlobId blob, Storage.BlobGetOption... options) Adds a request representing the "get blob" operation to this batch.get
(String bucket, String blob, Storage.BlobGetOption... options) Adds a request representing the "get blob" operation to this batch.void
submit()
Submits this batch for processing using a single RPC request.update
(BlobInfo blobInfo, Storage.BlobTargetOption... options) Adds a request representing the "update blob" operation to this batch.
-
Method Details
-
delete
public StorageBatchResult<Boolean> delete(String bucket, String blob, Storage.BlobSourceOption... options) Adds a request representing the "delete blob" operation to this batch. CallingBatchResult.get()
on the return value yieldstrue
upon successful deletion,false
if the blob was not found, or throws aStorageException
if the operation failed. -
delete
Adds a request representing the "delete blob" operation to this batch. CallingBatchResult.get()
on the return value yieldstrue
upon successful deletion,false
if the blob was not found, or throws aStorageException
if the operation failed. -
update
Adds a request representing the "update blob" operation to this batch. Theoptions
can be used in the same way as forStorage.update(BlobInfo, BlobTargetOption...)
. CallingBatchResult.get()
on the return value yields the updatedBlob
if successful, or throws aStorageException
if the operation failed. -
get
Adds a request representing the "get blob" operation to this batch. Theoptions
can be used in the same way as forStorage.get(BlobId, BlobGetOption...)
. CallingBatchResult.get()
on the return value yields the requestedBlob
if successful,null
if no such blob exists, or throws aStorageException
if the operation failed. -
get
Adds a request representing the "get blob" operation to this batch. Theoptions
can be used in the same way as forStorage.get(BlobId, BlobGetOption...)
. CallingBatchResult.get()
on the return value yields the requestedBlob
if successful,null
if no such blob exists, or throws aStorageException
if the operation failed. -
submit
public void submit()Submits this batch for processing using a single RPC request.
-