Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa64fa5

Browse files
committed
Merge pull request#762 from mziccard/remove-compose-content-type
Remove default contentType from Storage.compose and Bucket.create
2 parents353d2db +5dd0292 commitfa64fa5

File tree

12 files changed

+311
-132
lines changed

12 files changed

+311
-132
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
importstaticcom.google.gcloud.storage.Bucket.BucketSourceOption.toSourceOptions;
2323

2424
importcom.google.common.base.Function;
25-
importcom.google.common.base.MoreObjects;
2625
importcom.google.common.collect.Lists;
2726
importcom.google.common.collect.Sets;
2827
importcom.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
publicBlobcreate(Stringblob,byte[]content,StringcontentType,BlobTargetOption...options) {
643-
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob))
644-
.contentType(MoreObjects.firstNonNull(contentType,Storage.DEFAULT_CONTENT_TYPE)).build();
641+
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob)).contentType(contentType).build();
645642
StorageRpc.Tuple<BlobInfo,Storage.BlobTargetOption[]>target =
646643
BlobTargetOption.toTargetOptions(blobInfo,options);
647644
returnstorage.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
publicBlobcreate(Stringblob,InputStreamcontent,StringcontentType,
664660
BlobWriteOption...options) {
665-
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob))
666-
.contentType(MoreObjects.firstNonNull(contentType,Storage.DEFAULT_CONTENT_TYPE)).build();
661+
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob)).contentType(contentType).build();
662+
StorageRpc.Tuple<BlobInfo,Storage.BlobWriteOption[]>write =
663+
BlobWriteOption.toWriteOptions(blobInfo,options);
664+
returnstorage.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+
publicBlobcreate(Stringblob,byte[]content,BlobTargetOption...options) {
680+
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob)).build();
681+
StorageRpc.Tuple<BlobInfo,Storage.BlobTargetOption[]>target =
682+
BlobTargetOption.toTargetOptions(blobInfo,options);
683+
returnstorage.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+
publicBlobcreate(Stringblob,InputStreamcontent,BlobWriteOption...options) {
698+
BlobInfoblobInfo =BlobInfo.builder(BlobId.of(name(),blob)).build();
667699
StorageRpc.Tuple<BlobInfo,Storage.BlobWriteOption[]>write =
668700
BlobWriteOption.toWriteOptions(blobInfo,options);
669701
returnstorage.create(write.x(),content,write.y());

‎gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java‎

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
importjava.util.concurrent.Callable;
3333

3434
/**
35-
* Google Storage blob copy writer. This class holds the result of a copy request. If source and
35+
* Google Storage blob copy writer. A {@code CopyWriter} object allows to copy both blob's data and
36+
* information. To override source blob's information supply a {@code BlobInfo} to the
37+
* {@code CopyRequest} using either
38+
* {@link Storage.CopyRequest.Builder#target(BlobInfo, Storage.BlobTargetOption...)} or
39+
* {@link Storage.CopyRequest.Builder#target(BlobInfo, Iterable)}.
40+
*
41+
* <p>This class holds the result of a copy request. If source and
3642
* destination blobs share the same location and storage class the copy is completed in one RPC call
3743
* otherwise one or more {@link #copyChunk} calls are necessary to complete the copy. In addition,
3844
* {@link CopyWriter#result()} can be used to automatically complete the copy and return information
@@ -65,11 +71,11 @@ public class CopyWriter implements Restorable<CopyWriter> {
6571
*
6672
* @throws StorageException upon failure
6773
*/
68-
publicBlobInforesult() {
74+
publicBlobresult() {
6975
while (!isDone()) {
7076
copyChunk();
7177
}
72-
returnBlobInfo.fromPb(rewriteResponse.result);
78+
returnBlob.fromPb(serviceOptions.service(),rewriteResponse.result);
7379
}
7480

7581
/**
@@ -120,8 +126,10 @@ public RestorableState<CopyWriter> capture() {
120126
serviceOptions,
121127
BlobId.fromPb(rewriteResponse.rewriteRequest.source),
122128
rewriteResponse.rewriteRequest.sourceOptions,
129+
rewriteResponse.rewriteRequest.overrideInfo,
123130
BlobInfo.fromPb(rewriteResponse.rewriteRequest.target),
124131
rewriteResponse.rewriteRequest.targetOptions)
132+
.result(rewriteResponse.result !=null ?BlobInfo.fromPb(rewriteResponse.result) :null)
125133
.blobSize(blobSize())
126134
.isDone(isDone())
127135
.megabytesCopiedPerChunk(rewriteResponse.rewriteRequest.megabytesRewrittenPerCall)
@@ -132,11 +140,12 @@ public RestorableState<CopyWriter> capture() {
132140

133141
staticclassStateImplimplementsRestorableState<CopyWriter>,Serializable {
134142

135-
privatestaticfinallongserialVersionUID =8279287678903181701L;
143+
privatestaticfinallongserialVersionUID =1693964441435822700L;
136144

137145
privatefinalStorageOptionsserviceOptions;
138146
privatefinalBlobIdsource;
139147
privatefinalMap<StorageRpc.Option, ?>sourceOptions;
148+
privatefinalbooleanoverrideInfo;
140149
privatefinalBlobInfotarget;
141150
privatefinalMap<StorageRpc.Option, ?>targetOptions;
142151
privatefinalBlobInforesult;
@@ -150,6 +159,7 @@ static class StateImpl implements RestorableState<CopyWriter>, Serializable {
150159
this.serviceOptions =builder.serviceOptions;
151160
this.source =builder.source;
152161
this.sourceOptions =builder.sourceOptions;
162+
this.overrideInfo =builder.overrideInfo;
153163
this.target =builder.target;
154164
this.targetOptions =builder.targetOptions;
155165
this.result =builder.result;
@@ -165,6 +175,7 @@ static class Builder {
165175
privatefinalStorageOptionsserviceOptions;
166176
privatefinalBlobIdsource;
167177
privatefinalMap<StorageRpc.Option, ?>sourceOptions;
178+
privatefinalbooleanoverrideInfo;
168179
privatefinalBlobInfotarget;
169180
privatefinalMap<StorageRpc.Option, ?>targetOptions;
170181
privateBlobInforesult;
@@ -175,11 +186,12 @@ static class Builder {
175186
privateLongmegabytesCopiedPerChunk;
176187

177188
privateBuilder(StorageOptionsoptions,BlobIdsource,
178-
Map<StorageRpc.Option, ?>sourceOptions,
179-
BlobInfotarget,Map<StorageRpc.Option, ?>targetOptions) {
189+
Map<StorageRpc.Option, ?>sourceOptions,booleanoverrideInfo,BlobInfotarget,
190+
Map<StorageRpc.Option, ?>targetOptions) {
180191
this.serviceOptions =options;
181192
this.source =source;
182193
this.sourceOptions =sourceOptions;
194+
this.overrideInfo =overrideInfo;
183195
this.target =target;
184196
this.targetOptions =targetOptions;
185197
}
@@ -220,15 +232,15 @@ RestorableState<CopyWriter> build() {
220232
}
221233

222234
staticBuilderbuilder(StorageOptionsoptions,BlobIdsource,
223-
Map<StorageRpc.Option, ?>sourceOptions,BlobInfotarget,
235+
Map<StorageRpc.Option, ?>sourceOptions,booleanoverrideInfo,BlobInfotarget,
224236
Map<StorageRpc.Option, ?>targetOptions) {
225-
returnnewBuilder(options,source,sourceOptions,target,targetOptions);
237+
returnnewBuilder(options,source,sourceOptions,overrideInfo,target,targetOptions);
226238
}
227239

228240
@Override
229241
publicCopyWriterrestore() {
230-
RewriteRequestrewriteRequest =newRewriteRequest(
231-
source.toPb(),sourceOptions,target.toPb(),targetOptions,megabytesCopiedPerChunk);
242+
RewriteRequestrewriteRequest =newRewriteRequest(source.toPb(),sourceOptions,
243+
overrideInfo,target.toPb(),targetOptions,megabytesCopiedPerChunk);
232244
RewriteResponserewriteResponse =newRewriteResponse(rewriteRequest,
233245
result !=null ?result.toPb() :null,blobSize,isDone,rewriteToken,
234246
totalBytesCopied);
@@ -237,8 +249,9 @@ public CopyWriter restore() {
237249

238250
@Override
239251
publicinthashCode() {
240-
returnObjects.hash(serviceOptions,source,sourceOptions,target,targetOptions,result,
241-
blobSize,isDone,megabytesCopiedPerChunk,rewriteToken,totalBytesCopied);
252+
returnObjects.hash(serviceOptions,source,sourceOptions,overrideInfo,target,
253+
targetOptions,result,blobSize,isDone,megabytesCopiedPerChunk,rewriteToken,
254+
totalBytesCopied);
242255
}
243256

244257
@Override
@@ -253,6 +266,7 @@ public boolean equals(Object obj) {
253266
returnObjects.equals(this.serviceOptions,other.serviceOptions)
254267
&&Objects.equals(this.source,other.source)
255268
&&Objects.equals(this.sourceOptions,other.sourceOptions)
269+
&&Objects.equals(this.overrideInfo,other.overrideInfo)
256270
&&Objects.equals(this.target,other.target)
257271
&&Objects.equals(this.targetOptions,other.targetOptions)
258272
&&Objects.equals(this.result,other.result)
@@ -267,10 +281,14 @@ public boolean equals(Object obj) {
267281
publicStringtoString() {
268282
returnMoreObjects.toStringHelper(this)
269283
.add("source",source)
284+
.add("overrideInfo",overrideInfo)
270285
.add("target",target)
271-
.add("isDone",isDone)
272-
.add("totalBytesRewritten",totalBytesCopied)
286+
.add("result",result)
273287
.add("blobSize",blobSize)
288+
.add("isDone",isDone)
289+
.add("rewriteToken",rewriteToken)
290+
.add("totalBytesCopied",totalBytesCopied)
291+
.add("megabytesCopiedPerChunk",megabytesCopiedPerChunk)
274292
.toString();
275293
}
276294
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp