Skip to content

Commit 8840b33

Browse files
committed
Remove default contentType from Bucket's create
1 parent 0a113cd commit 8840b33

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

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

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static com.google.gcloud.storage.Bucket.BucketSourceOption.toSourceOptions;
2323

2424
import com.google.common.base.Function;
25-
import com.google.common.base.MoreObjects;
2625
import com.google.common.collect.Lists;
2726
import com.google.common.collect.Sets;
2827
import 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());

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
*/
5454
public interface Storage extends Service<StorageOptions> {
5555

56-
String DEFAULT_CONTENT_TYPE = "application/octet-stream";
57-
5856
enum PredefinedAcl {
5957
AUTHENTICATED_READ("authenticatedRead"),
6058
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers"),

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,16 @@ public void testCreate() throws Exception {
293293
}
294294

295295
@Test
296-
public void testCreateNullContentType() throws Exception {
296+
public void testCreateNoContentType() throws Exception {
297297
initializeExpectedBucket(5);
298-
BlobInfo info = BlobInfo.builder("b", "n").contentType(Storage.DEFAULT_CONTENT_TYPE).build();
298+
BlobInfo info = BlobInfo.builder("b", "n").build();
299299
Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info));
300300
byte[] content = {0xD, 0xE, 0xA, 0xD};
301301
expect(storage.options()).andReturn(mockOptions);
302302
expect(storage.create(info, content)).andReturn(expectedBlob);
303303
replay(storage);
304304
initializeBucket();
305-
Blob blob = bucket.create("n", content, null);
305+
Blob blob = bucket.create("n", content);
306306
assertEquals(expectedBlob, blob);
307307
}
308308

@@ -388,17 +388,17 @@ public void testCreateFromStream() throws Exception {
388388
}
389389

390390
@Test
391-
public void testCreateFromStreamNullContentType() throws Exception {
391+
public void testCreateFromStreamNoContentType() throws Exception {
392392
initializeExpectedBucket(5);
393-
BlobInfo info = BlobInfo.builder("b", "n").contentType(Storage.DEFAULT_CONTENT_TYPE).build();
393+
BlobInfo info = BlobInfo.builder("b", "n").build();
394394
Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info));
395395
byte[] content = {0xD, 0xE, 0xA, 0xD};
396396
InputStream streamContent = new ByteArrayInputStream(content);
397397
expect(storage.options()).andReturn(mockOptions);
398398
expect(storage.create(info, streamContent)).andReturn(expectedBlob);
399399
replay(storage);
400400
initializeBucket();
401-
Blob blob = bucket.create("n", streamContent, null);
401+
Blob blob = bucket.create("n", streamContent);
402402
assertEquals(expectedBlob, blob);
403403
}
404404

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy