Skip to content

Commit 142c75c

Browse files
committed
---
yaml --- r: 6291 b: refs/heads/tswast-patch-1 c: 41da3aa h: refs/heads/master i: 6289: 20002b1 6287: 6526604
1 parent b30cbbc commit 142c75c

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

  • branches/tswast-patch-1/gcloud-java-storage/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 8b89ba37f3fe7edb8e9b5bfee575513de8642909
60+
refs/heads/tswast-patch-1: 41da3aa4c4be58d11580401f882b2179f3f1a73c
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
197197
return new Blob(storage, storage.update(blobInfo, options));
198198
}
199199

200+
/**
201+
* Copies this blob to the specified target. Possibly copying also some of the metadata
202+
* (e.g. content-type).
203+
*
204+
* @param targetBlob target blob's id
205+
* @param options source blob options
206+
* @return the copied blob
207+
* @throws StorageException upon failure
208+
*/
209+
public Blob copyTo(BlobId targetBlob, BlobSourceOption... options) {
210+
BlobInfo updatedInfo = info.toBuilder().blobId(targetBlob).build();
211+
CopyRequest copyRequest =
212+
CopyRequest.builder().source(info.bucket(), info.name())
213+
.sourceOptions(convert(info, options)).target(updatedInfo).build();
214+
return new Blob(storage, storage.copy(copyRequest));
215+
}
216+
200217
/**
201218
* Deletes this blob.
202219
*

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ public void testCopyTo() throws Exception {
143143
assertSame(storage, targetBlob.storage());
144144
}
145145

146+
@Test
147+
public void testCopyToBlobId() throws Exception {
148+
BlobId targetId = BlobId.of("bt", "nt");
149+
BlobInfo target = BLOB_INFO.toBuilder().blobId(targetId).build();
150+
Capture<CopyRequest> capturedCopyRequest = Capture.newInstance();
151+
expect(storage.copy(capture(capturedCopyRequest))).andReturn(target);
152+
replay(storage);
153+
Blob targetBlob = blob.copyTo(targetId);
154+
assertEquals(target, targetBlob.info());
155+
assertEquals(capturedCopyRequest.getValue().source(), blob.id());
156+
assertEquals(capturedCopyRequest.getValue().target(), target);
157+
assertSame(storage, targetBlob.storage());
158+
}
159+
146160
@Test
147161
public void testReader() throws Exception {
148162
BlobReadChannel channel = createMock(BlobReadChannel.class);

0 commit comments

Comments
 (0)