Skip to content

Commit 3b91741

Browse files
committed
Document patch behaviour in Blob and Storage javadoc
1 parent 333a3bb commit 3b91741

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ public Blob reload(BlobSourceOption... options) {
190190
* made on the metadata generation of the current blob. If you want to update the information only
191191
* if the current blob metadata are at their latest version use the {@code metagenerationMatch}
192192
* option: {@code blob.update(newInfo, BlobTargetOption.metagenerationMatch())}.
193+
* <p>
194+
* Original metadata are merged with metadata in the provided {@code blobInfo}. To replace
195+
* metadata instead you first have to unset them. Unsetting metadata can be done by setting the
196+
* provided {@code blobInfo}'s metadata to {@code null}.
197+
* </p>
198+
* <p>
199+
* Example usage of replacing blob's metadata:
200+
* <pre> {@code blob.update(blob.info().toBuilder().metadata(null).build());}
201+
* {@code blob.update(blob.info().toBuilder().metadata(newMetadata).build());}
202+
* </pre>
193203
*
194204
* @param blobInfo new blob's information. Bucket and blob names must match the current ones
195205
* @param options update options
@@ -306,8 +316,7 @@ public Storage storage() {
306316
}
307317

308318
/**
309-
* Gets the requested blobs. If {@code infos.length == 0} an empty list is returned. If
310-
* {@code infos.length > 1} a batch request is used to fetch blobs.
319+
* Gets the requested blobs. A batch request is used to fetch blobs.
311320
*
312321
* @param storage the storage service used to issue the request
313322
* @param blobs the blobs to get
@@ -331,8 +340,12 @@ public Blob apply(BlobInfo f) {
331340
}
332341

333342
/**
334-
* Updates the requested blobs. If {@code infos.length == 0} an empty list is returned. If
335-
* {@code infos.length > 1} a batch request is used to update blobs.
343+
* Updates the requested blobs. A batch request is used to update blobs. Original metadata are
344+
* merged with metadata in the provided {@code BlobInfo} objects. To replace metadata instead
345+
* you first have to unset them. Unsetting metadata can be done by setting the provided
346+
* {@code BlobInfo} objects metadata to {@code null}. See
347+
* {@link #update(com.google.gcloud.storage.BlobInfo,
348+
* com.google.gcloud.storage.Storage.BlobTargetOption...) } for a code example.
336349
*
337350
* @param storage the storage service used to issue the request
338351
* @param infos the blobs to update
@@ -356,8 +369,7 @@ public Blob apply(BlobInfo f) {
356369
}
357370

358371
/**
359-
* Deletes the requested blobs. If {@code infos.length == 0} an empty list is returned. If
360-
* {@code infos.length > 1} a batch request is used to delete blobs.
372+
* Deletes the requested blobs. A batch request is used to delete blobs.
361373
*
362374
* @param storage the storage service used to issue the request
363375
* @param blobs the blobs to delete

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,29 @@ public static Builder builder() {
683683
BucketInfo update(BucketInfo bucketInfo, BucketTargetOption... options);
684684

685685
/**
686-
* Update blob information.
686+
* Update blob information. Original metadata are merged with metadata in the provided
687+
* {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata
688+
* can be done by setting the provided {@code blobInfo}'s metadata to {@code null}.
689+
* <p>
690+
* Example usage of replacing blob's metadata:
691+
* <pre> {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
692+
* {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
693+
* </pre>
687694
*
688695
* @return the updated blob
689696
* @throws StorageException upon failure
690697
*/
691698
BlobInfo update(BlobInfo blobInfo, BlobTargetOption... options);
692699

693700
/**
694-
* Update blob information.
701+
* Update blob information. Original metadata are merged with metadata in the provided
702+
* {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata
703+
* can be done by setting the provided {@code blobInfo}'s metadata to {@code null}.
704+
* <p>
705+
* Example usage of replacing blob's metadata:
706+
* <pre> {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
707+
* {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
708+
* </pre>
695709
*
696710
* @return the updated blob
697711
* @throws StorageException upon failure
@@ -826,7 +840,11 @@ public static Builder builder() {
826840
List<BlobInfo> get(BlobId... blobIds);
827841

828842
/**
829-
* Updates the requested blobs. A batch request is used to perform this call.
843+
* Updates the requested blobs. A batch request is used to perform this call. Original metadata
844+
* are merged with metadata in the provided {@code BlobInfo} objects. To replace metadata instead
845+
* you first have to unset them. Unsetting metadata can be done by setting the provided
846+
* {@code BlobInfo} objects metadata to {@code null}. See
847+
* {@link #update(com.google.gcloud.storage.BlobInfo)} for a code example.
830848
*
831849
* @param blobInfos blobs to update
832850
* @return an immutable list of {@code BlobInfo} objects. If a blob does not exist or access to it

0 commit comments

Comments
 (0)