Skip to content

Commit 2ec885e

Browse files
committed
---
yaml --- r: 6347 b: refs/heads/tswast-patch-1 c: 75d9065 h: refs/heads/master i: 6345: 2135a21 6343: 5b36928
1 parent f208674 commit 2ec885e

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 0dd3d971bafc2d724787a76e69fdde6dedba51df
60+
refs/heads/tswast-patch-1: 75d90658261a380c1573ecf2a5f533dc3ed986ed
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121

22+
import com.google.common.base.MoreObjects;
2223
import com.google.gcloud.storage.Storage.BlobSourceOption;
2324
import com.google.gcloud.storage.Storage.BlobTargetOption;
25+
import com.google.gcloud.storage.Storage.BlobWriteOption;
2426
import com.google.gcloud.storage.Storage.BucketSourceOption;
2527
import com.google.gcloud.storage.Storage.BucketTargetOption;
28+
import java.io.InputStream;
2629

2730
import java.util.ArrayList;
2831
import java.util.Collections;
@@ -172,17 +175,22 @@ public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
172175
}
173176

174177
/**
175-
* Creates a new blob in this bucket.
178+
* Creates a new blob in this bucket. Direct upload is used to upload {@code content}.
179+
* For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)}
180+
* is recommended as it uses resumable upload. MD5 and CRC32C hashes of {@code content} are
181+
* computed and used for validating transferred data.
176182
*
177183
* @param blob a blob name
178184
* @param content the blob content
185+
* @param contentType the blob content type
179186
* @param options options for blob creation
180187
* @return a complete blob information.
181188
* @throws StorageException upon failure
182189
*/
183-
Blob create(String blob, byte[] content, BlobTargetOption... options) {
184-
BlobId blobId = BlobId.of(info.name(), blob);
185-
return new Blob(storage, storage.create(BlobInfo.builder(blobId).build(), content, options));
190+
public Blob create(String blob, byte[] content, String contentType, BlobTargetOption... options) {
191+
BlobInfo blobInfo = BlobInfo.builder(BlobId.of(info.name(), blob))
192+
.contentType(MoreObjects.firstNonNull(contentType, Storage.DEFAULT_CONTENT_TYPE)).build();
193+
return new Blob(storage, storage.create(blobInfo, content, options));
186194
}
187195

188196
/**

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
*/
4747
public interface Storage extends Service<StorageOptions> {
4848

49+
public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
50+
4951
enum PredefinedAcl {
5052
AUTHENTICATED_READ("authenticatedRead"),
5153
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers"),

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class BucketTest {
4545
BlobInfo.builder("b", "n1").build(),
4646
BlobInfo.builder("b", "n2").build(),
4747
BlobInfo.builder("b", "n3").build());
48+
private static final String CONTENT_TYPE = "text/plain";
4849

4950
private Storage storage;
5051
private Bucket bucket;
@@ -161,11 +162,21 @@ public void testGetAll() throws Exception {
161162

162163
@Test
163164
public void testCreate() throws Exception {
164-
BlobInfo info = BlobInfo.builder("b", "n").build();
165+
BlobInfo info = BlobInfo.builder("b", "n").contentType(CONTENT_TYPE).build();
166+
byte[] content = {0xD, 0xE, 0xA, 0xD};
167+
expect(storage.create(info, content)).andReturn(info);
168+
replay(storage);
169+
Blob blob = bucket.create("n", content, CONTENT_TYPE);
170+
assertEquals(info, blob.info());
171+
}
172+
173+
@Test
174+
public void testCreateNullContentType() throws Exception {
175+
BlobInfo info = BlobInfo.builder("b", "n").contentType(Storage.DEFAULT_CONTENT_TYPE).build();
165176
byte[] content = {0xD, 0xE, 0xA, 0xD};
166177
expect(storage.create(info, content)).andReturn(info);
167178
replay(storage);
168-
Blob blob = bucket.create("n", content);
179+
Blob blob = bucket.create("n", content, null);
169180
assertEquals(info, blob.info());
170181
}
171182

0 commit comments

Comments
 (0)