22
22
import static com .google .gcloud .storage .Bucket .BucketSourceOption .toSourceOptions ;
23
23
24
24
import com .google .common .base .Function ;
25
- import com .google .common .base .MoreObjects ;
26
25
import com .google .common .collect .Lists ;
27
26
import com .google .common .collect .Sets ;
28
27
import com .google .gcloud .Page ;
@@ -633,15 +632,13 @@ public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
633
632
*
634
633
* @param blob a blob name
635
634
* @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
638
636
* @param options options for blob creation
639
637
* @return a complete blob information
640
638
* @throws StorageException upon failure
641
639
*/
642
640
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 ();
645
642
StorageRpc .Tuple <BlobInfo , Storage .BlobTargetOption []> target =
646
643
BlobTargetOption .toTargetOptions (blobInfo , options );
647
644
return storage .create (target .x (), content , target .y ());
@@ -654,16 +651,51 @@ public Blob create(String blob, byte[] content, String contentType, BlobTargetOp
654
651
*
655
652
* @param blob a blob name
656
653
* @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
659
655
* @param options options for blob creation
660
656
* @return a complete blob information
661
657
* @throws StorageException upon failure
662
658
*/
663
659
public Blob create (String blob , InputStream content , String contentType ,
664
660
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 ();
667
699
StorageRpc .Tuple <BlobInfo , Storage .BlobWriteOption []> write =
668
700
BlobWriteOption .toWriteOptions (blobInfo , options );
669
701
return storage .create (write .x (), content , write .y ());
0 commit comments