@@ -322,6 +322,17 @@ public Blob build() {
322322 /**
323323 * Checks if this blob exists.
324324 *
325+ * <p>Example of checking if the blob exists (see {@code exists()} in
326+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
327+ * BlobSnippets.java</a>):
328+ * <pre> {@code
329+ * boolean exists = blob.exists();
330+ * if (exists) {
331+ * // the blob exists
332+ * } else {
333+ * // the blob was not found
334+ * }}</pre>
335+ *
325336 * @param options blob read options
326337 * @return true if this blob exists, false otherwise
327338 * @throws StorageException upon failure
@@ -336,16 +347,36 @@ public boolean exists(BlobSourceOption... options) {
336347 /**
337348 * Returns this blob's content.
338349 *
350+ * <p>Example of reading all bytes of the blob, if its generation matches the
351+ * {@link Blob#generation()} value, otherwise a {@link StorageException} is thrown (see
352+ * {@code content()} in
353+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
354+ * BlobSnippets.java</a>):
355+ * <pre> {@code
356+ * byte[] content = blob.content(BlobSourceOption.generationMatch());
357+ * }</pre>
358+ *
339359 * @param options blob read options
340360 * @throws StorageException upon failure
341361 */
342- public byte [] content (Storage . BlobSourceOption ... options ) {
343- return storage .readAllBytes (blobId (), options );
362+ public byte [] content (BlobSourceOption ... options ) {
363+ return storage .readAllBytes (blobId (), toSourceOptions ( this , options ) );
344364 }
345365
346366 /**
347367 * Fetches current blob's latest information. Returns {@code null} if the blob does not exist.
348368 *
369+ * <p>Example of getting the blob's latest information, if its generation does not match the
370+ * {@link Blob#generation()} value, otherwise a {@link StorageException} is thrown (see
371+ * {@code reload()} in
372+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
373+ * BlobSnippets.java</a>):
374+ * <pre> {@code
375+ * Blob latestBlob = blob.reload(BlobSourceOption.generationNotMatch());
376+ * if (latestBlob == null) {
377+ * // the blob was not found
378+ * }}</pre>
379+ *
349380 * @param options blob read options
350381 * @return a {@code Blob} object with latest information or {@code null} if not found
351382 * @throws StorageException upon failure
@@ -367,12 +398,15 @@ public Blob reload(BlobSourceOption... options) {
367398 * {@code blob}'s metadata to {@code null}.
368399 * </p>
369400 *
370- * <p>Example usage of replacing blob's metadata:
401+ * <p>Example of replacing blob's metadata (see {@code update()} in
402+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
403+ * BlobSnippets.java</a>):
371404 * <pre> {@code
405+ * Map<String, String> newMetadata = new HashMap<>();
406+ * newMetadata.put("key", "value");
372407 * blob.toBuilder().metadata(null).build().update();
373408 * blob.toBuilder().metadata(newMetadata).build().update();
374- * }
375- * </pre>
409+ * }</pre>
376410 *
377411 * @param options update options
378412 * @return a {@code Blob} object with updated information
@@ -385,6 +419,18 @@ public Blob update(BlobTargetOption... options) {
385419 /**
386420 * Deletes this blob.
387421 *
422+ * <p>Example of deleting the blob, if its generation matches the {@link Blob#generation()} value,
423+ * otherwise a {@link StorageException} is thrown (see {@code delete()} in
424+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
425+ * BlobSnippets.java</a>):
426+ * <pre> {@code
427+ * boolean deleted = blob.delete(BlobSourceOption.generationMatch());
428+ * if (deleted) {
429+ * // the blob was deleted
430+ * } else {
431+ * // the blob was not found
432+ * }}</pre>
433+ *
388434 * @param options blob delete options
389435 * @return {@code true} if blob was deleted, {@code false} if it was not found
390436 * @throws StorageException upon failure
@@ -397,6 +443,15 @@ public boolean delete(BlobSourceOption... options) {
397443 * Sends a copy request for the current blob to the target blob. Possibly also some of the
398444 * metadata are copied (e.g. content-type).
399445 *
446+ * <p>Example of copying the blob to a different bucket with a different name (see
447+ * {@code copyToId()} in
448+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
449+ * BlobSnippets.java</a>):
450+ * <pre> {@code
451+ * CopyWriter copyWriter = blob.copyTo(BlobId.of("my_other_unique_bucket", "copy_blob_name"));
452+ * Blob copiedBlob = copyWriter.result();
453+ * }</pre>
454+ *
400455 * @param targetBlob target blob's id
401456 * @param options source blob options
402457 * @return a {@link CopyWriter} object that can be used to get information on the newly created
@@ -416,6 +471,15 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
416471 * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
417472 * copying also some of the metadata (e.g. content-type).
418473 *
474+ * <p>Example of copying the blob to a different bucket, keeping the original name (see
475+ * {@code copyToBucket()} in
476+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
477+ * BlobSnippets.java</a>):
478+ * <pre> {@code
479+ * CopyWriter copyWriter = blob.copyTo("my_other_unique_bucket");
480+ * Blob copiedBlob = copyWriter.result();
481+ * }</pre>
482+ *
419483 * @param targetBucket target bucket's name
420484 * @param options source blob options
421485 * @return a {@link CopyWriter} object that can be used to get information on the newly created
@@ -430,6 +494,15 @@ public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
430494 * Sends a copy request for the current blob to the target blob. Possibly also some of the
431495 * metadata are copied (e.g. content-type).
432496 *
497+ * <p>Example of copying the blob to a different bucket with a different name (see
498+ * {@code copyToStrings()} in
499+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
500+ * BlobSnippets.java</a>):
501+ * <pre> {@code
502+ * CopyWriter copyWriter = blob.copyTo("my_other_unique_bucket");
503+ * Blob copiedBlob = copyWriter.result();
504+ * }</pre>
505+ *
433506 * @param targetBucket target bucket's name
434507 * @param targetBlob target blob's name
435508 * @param options source blob options
@@ -444,6 +517,19 @@ public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOptio
444517 /**
445518 * Returns a {@code ReadChannel} object for reading this blob's content.
446519 *
520+ * <p>Example of reading the blob's content through a reader (see {@code reader()} in
521+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
522+ * BlobSnippets.java</a>):
523+ * <pre> {@code
524+ * try (ReadChannel reader = blob.reader()) {
525+ * ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
526+ * while (reader.read(bytes) > 0) {
527+ * bytes.flip();
528+ * // do something with bytes
529+ * bytes.clear();
530+ * }
531+ * }}</pre>
532+ *
447533 * @param options blob read options
448534 * @throws StorageException upon failure
449535 */
@@ -456,6 +542,19 @@ public ReadChannel reader(BlobSourceOption... options) {
456542 * crc32c values in the current blob are ignored unless requested via the
457543 * {@code BlobWriteOption.md5Match} and {@code BlobWriteOption.crc32cMatch} options.
458544 *
545+ * <p>Example of writing the blob's content through a writer (see {@code writer()} in
546+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
547+ * BlobSnippets.java</a>):
548+ * <pre> {@code
549+ * byte[] content = "Hello, World!".getBytes(UTF_8);
550+ * try (WriteChannel writer = blob.writer()) {
551+ * try {
552+ * writer.write(ByteBuffer.wrap(content, 0, content.length));
553+ * } catch (Exception ex) {
554+ * // handle exception
555+ * }
556+ * }}</pre>
557+ *
459558 * @param options target blob options
460559 * @throws StorageException upon failure
461560 */
@@ -485,15 +584,19 @@ public WriteChannel writer(BlobWriteOption... options) {
485584 * <li>The default credentials, if no credentials were passed to {@link StorageOptions}
486585 * </ol>
487586 *
488- * <p>Example usage of creating a signed URL that is valid for 2 weeks, using the default
489- * credentials for signing the URL:
587+ * <p>Example of creating a signed URL for the blob that is valid for 2 weeks, using the default
588+ * credentials for signing the URL (see {@code signUrl()} in
589+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
590+ * BlobSnippets.java</a>):
490591 * <pre> {@code
491592 * blob.signUrl(14, TimeUnit.DAYS);
492593 * }</pre>
493594 *
494- * <p>Example usage of creating a signed URL passing the
495- * {@link SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used for signing the
496- * URL:
595+ * <p>Example of creating a signed URL for the blob passing the
596+ * {@link SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used to sign the URL
597+ * (see {@code signUrlWithSigner()} in
598+ * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java">
599+ * BlobSnippets.java</a>):
497600 * <pre> {@code
498601 * blob.signUrl(14, TimeUnit.DAYS, SignUrlOption.signWith(
499602 * AuthCredentials.createForJson(new FileInputStream("/path/to/key.json"))));
0 commit comments