2222import static com .google .gcloud .storage .Bucket .BucketSourceOption .toSourceOptions ;
2323
2424import com .google .common .base .Function ;
25- import com .google .common .base .MoreObjects ;
2625import com .google .common .collect .Lists ;
2726import com .google .common .collect .Sets ;
2827import com .google .gcloud .Page ;
@@ -633,15 +632,13 @@ public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
633632 *
634633 * @param blob a blob name
635634 * @param content the blob content
636- * @param contentType the blob content type. If {@code null} then
637- * {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used.
635+ * @param contentType the blob content type
638636 * @param options options for blob creation
639637 * @return a complete blob information
640638 * @throws StorageException upon failure
641639 */
642640 public Blob create (String blob , byte [] content , String contentType , BlobTargetOption ... options ) {
643- BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob ))
644- .contentType (MoreObjects .firstNonNull (contentType , Storage .DEFAULT_CONTENT_TYPE )).build ();
641+ BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob )).contentType (contentType ).build ();
645642 StorageRpc .Tuple <BlobInfo , Storage .BlobTargetOption []> target =
646643 BlobTargetOption .toTargetOptions (blobInfo , options );
647644 return storage .create (target .x (), content , target .y ());
@@ -654,16 +651,51 @@ public Blob create(String blob, byte[] content, String contentType, BlobTargetOp
654651 *
655652 * @param blob a blob name
656653 * @param content the blob content as a stream
657- * @param contentType the blob content type. If {@code null} then
658- * {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used.
654+ * @param contentType the blob content type
659655 * @param options options for blob creation
660656 * @return a complete blob information
661657 * @throws StorageException upon failure
662658 */
663659 public Blob create (String blob , InputStream content , String contentType ,
664660 BlobWriteOption ... options ) {
665- BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob ))
666- .contentType (MoreObjects .firstNonNull (contentType , Storage .DEFAULT_CONTENT_TYPE )).build ();
661+ BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob )).contentType (contentType ).build ();
662+ StorageRpc .Tuple <BlobInfo , Storage .BlobWriteOption []> write =
663+ BlobWriteOption .toWriteOptions (blobInfo , options );
664+ return storage .create (write .x (), content , write .y ());
665+ }
666+
667+ /**
668+ * Creates a new blob in this bucket. Direct upload is used to upload {@code content}.
669+ * For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)}
670+ * is recommended as it uses resumable upload. MD5 and CRC32C hashes of {@code content} are
671+ * computed and used for validating transferred data.
672+ *
673+ * @param blob a blob name
674+ * @param content the blob content
675+ * @param options options for blob creation
676+ * @return a complete blob information
677+ * @throws StorageException upon failure
678+ */
679+ public Blob create (String blob , byte [] content , BlobTargetOption ... options ) {
680+ BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob )).build ();
681+ StorageRpc .Tuple <BlobInfo , Storage .BlobTargetOption []> target =
682+ BlobTargetOption .toTargetOptions (blobInfo , options );
683+ return storage .create (target .x (), content , target .y ());
684+ }
685+
686+ /**
687+ * Creates a new blob in this bucket. Direct upload is used to upload {@code content}.
688+ * For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)}
689+ * is recommended as it uses resumable upload.
690+ *
691+ * @param blob a blob name
692+ * @param content the blob content as a stream
693+ * @param options options for blob creation
694+ * @return a complete blob information
695+ * @throws StorageException upon failure
696+ */
697+ public Blob create (String blob , InputStream content , BlobWriteOption ... options ) {
698+ BlobInfo blobInfo = BlobInfo .builder (BlobId .of (name (), blob )).build ();
667699 StorageRpc .Tuple <BlobInfo , Storage .BlobWriteOption []> write =
668700 BlobWriteOption .toWriteOptions (blobInfo , options );
669701 return storage .create (write .x (), content , write .y ());
0 commit comments