use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method copyBlob.
/**
* Example of copying a blob.
*/
// [TARGET copy(CopyRequest)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "copy_blob_name"]
public Blob copyBlob(String bucketName, String blobName, String copyBlobName) {
// [START copyBlob]
CopyRequest request = CopyRequest.newBuilder().setSource(BlobId.of(bucketName, blobName)).setTarget(BlobId.of(bucketName, copyBlobName)).build();
Blob blob = storage.copy(request).getResult();
// [END copyBlob]
return blob;
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method copyBlobInChunks.
/**
* Example of copying a blob in chunks.
*/
// [TARGET copy(CopyRequest)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "copy_blob_name"]
public Blob copyBlobInChunks(String bucketName, String blobName, String copyBlobName) {
// [START copyBlobInChunks]
CopyRequest request = CopyRequest.newBuilder().setSource(BlobId.of(bucketName, blobName)).setTarget(BlobId.of(bucketName, copyBlobName)).build();
CopyWriter copyWriter = storage.copy(request);
while (!copyWriter.isDone()) {
copyWriter.copyChunk();
}
Blob blob = copyWriter.getResult();
// [END copyBlobInChunks]
return blob;
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopyWithOptionsFromBlobId.
@Test
public void testCopyWithOptionsFromBlobId() {
CopyRequest request = Storage.CopyRequest.newBuilder().setSource(BLOB_INFO1.getBlobId()).setSourceOptions(BLOB_SOURCE_GENERATION_FROM_BLOB_ID, BLOB_SOURCE_METAGENERATION).setTarget(BLOB_INFO1, BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION).build();
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), BLOB_SOURCE_OPTIONS_COPY, true, request.getTarget().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopyWithEncryptionKey.
@Test
public void testCopyWithEncryptionKey() {
CopyRequest request = Storage.CopyRequest.newBuilder().setSource(BLOB_INFO2.getBlobId()).setSourceOptions(BlobSourceOption.decryptionKey(KEY)).setTarget(BLOB_INFO1, BlobTargetOption.encryptionKey(BASE64_KEY)).build();
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), ENCRYPTION_KEY_OPTIONS, true, request.getTarget().toPb(), ENCRYPTION_KEY_OPTIONS, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse).times(2);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
request = Storage.CopyRequest.newBuilder().setSource(BLOB_INFO2.getBlobId()).setSourceOptions(BlobSourceOption.decryptionKey(BASE64_KEY)).setTarget(BLOB_INFO1, BlobTargetOption.encryptionKey(KEY)).build();
writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopyWithOptions.
@Test
public void testCopyWithOptions() {
CopyRequest request = Storage.CopyRequest.newBuilder().setSource(BLOB_INFO2.getBlobId()).setSourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION).setTarget(BLOB_INFO1, BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION).build();
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), BLOB_SOURCE_OPTIONS_COPY, true, request.getTarget().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
}
Aggregations