Skip to content

Commit a353f43

Browse files
committed
---
yaml --- r: 6335 b: refs/heads/tswast-patch-1 c: cebb0bb h: refs/heads/master i: 6333: ab92aaa 6331: f4e67a7 6327: ba182e4 6319: de1ece8 6303: 2358851 6271: acae946
1 parent 63cfcc1 commit a353f43

9 files changed

Lines changed: 206 additions & 52 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: 2665ab5441cdbcbf1bcc1178dd0df53d0c8bc0fb
60+
refs/heads/tswast-patch-1: cebb0bb0f1877a05da0cba09b778b5984b264448
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -260,67 +260,67 @@ public boolean equals(Object obj) {
260260
&& Objects.equals(value, other.value);
261261
}
262262

263-
public static PropertyFilter lt(String property, Value<?> value) {
263+
public static PropertyFilter le(String property, Value<?> value) {
264264
return new PropertyFilter(property, Operator.LESS_THAN, value);
265265
}
266266

267-
public static PropertyFilter lt(String property, String value) {
267+
public static PropertyFilter le(String property, String value) {
268268
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
269269
}
270270

271-
public static PropertyFilter lt(String property, long value) {
271+
public static PropertyFilter le(String property, long value) {
272272
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
273273
}
274274

275-
public static PropertyFilter lt(String property, double value) {
275+
public static PropertyFilter le(String property, double value) {
276276
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
277277
}
278278

279-
public static PropertyFilter lt(String property, boolean value) {
279+
public static PropertyFilter le(String property, boolean value) {
280280
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
281281
}
282282

283-
public static PropertyFilter lt(String property, DateTime value) {
283+
public static PropertyFilter le(String property, DateTime value) {
284284
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
285285
}
286286

287-
public static PropertyFilter lt(String property, Key value) {
287+
public static PropertyFilter le(String property, Key value) {
288288
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
289289
}
290290

291-
public static PropertyFilter lt(String property, Blob value) {
291+
public static PropertyFilter le(String property, Blob value) {
292292
return new PropertyFilter(property, Operator.LESS_THAN, of(value));
293293
}
294294

295-
public static PropertyFilter le(String property, Value<?> value) {
295+
public static PropertyFilter lte(String property, Value<?> value) {
296296
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, value);
297297
}
298298

299-
public static PropertyFilter le(String property, String value) {
299+
public static PropertyFilter lte(String property, String value) {
300300
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
301301
}
302302

303-
public static PropertyFilter le(String property, long value) {
303+
public static PropertyFilter lte(String property, long value) {
304304
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
305305
}
306306

307-
public static PropertyFilter le(String property, double value) {
307+
public static PropertyFilter lte(String property, double value) {
308308
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
309309
}
310310

311-
public static PropertyFilter le(String property, boolean value) {
311+
public static PropertyFilter lte(String property, boolean value) {
312312
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
313313
}
314314

315-
public static PropertyFilter le(String property, DateTime value) {
315+
public static PropertyFilter lte(String property, DateTime value) {
316316
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
317317
}
318318

319-
public static PropertyFilter le(String property, Key value) {
319+
public static PropertyFilter lte(String property, Key value) {
320320
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
321321
}
322322

323-
public static PropertyFilter le(String property, Blob value) {
323+
public static PropertyFilter lte(String property, Blob value) {
324324
return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value));
325325
}
326326

@@ -356,35 +356,35 @@ public static PropertyFilter gt(String property, Blob value) {
356356
return new PropertyFilter(property, Operator.GREATER_THAN, of(value));
357357
}
358358

359-
public static PropertyFilter ge(String property, Value<?> value) {
359+
public static PropertyFilter gte(String property, Value<?> value) {
360360
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, value);
361361
}
362362

363-
public static PropertyFilter ge(String property, String value) {
363+
public static PropertyFilter gte(String property, String value) {
364364
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
365365
}
366366

367-
public static PropertyFilter ge(String property, long value) {
367+
public static PropertyFilter gte(String property, long value) {
368368
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
369369
}
370370

371-
public static PropertyFilter ge(String property, double value) {
371+
public static PropertyFilter gte(String property, double value) {
372372
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
373373
}
374374

375-
public static PropertyFilter ge(String property, boolean value) {
375+
public static PropertyFilter gte(String property, boolean value) {
376376
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
377377
}
378378

379-
public static PropertyFilter ge(String property, DateTime value) {
379+
public static PropertyFilter gte(String property, DateTime value) {
380380
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
381381
}
382382

383-
public static PropertyFilter ge(String property, Key value) {
383+
public static PropertyFilter gte(String property, Key value) {
384384
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
385385
}
386386

387-
public static PropertyFilter ge(String property, Blob value) {
387+
public static PropertyFilter gte(String property, Blob value) {
388388
return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value));
389389
}
390390

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_GENERATION_NOT_MATCH;
2424
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_METAGENERATION_MATCH;
2525
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_METAGENERATION_NOT_MATCH;
26+
import static com.google.gcloud.spi.StorageRpc.Option.IF_MD5_MATCH;
27+
import static com.google.gcloud.spi.StorageRpc.Option.IF_CRC32C_MATCH;
2628
import static com.google.gcloud.spi.StorageRpc.Option.MAX_RESULTS;
2729
import static com.google.gcloud.spi.StorageRpc.Option.PAGE_TOKEN;
2830
import static com.google.gcloud.spi.StorageRpc.Option.PREDEFINED_ACL;
@@ -106,6 +108,15 @@ private static StorageException translate(GoogleJsonError exception) {
106108
return new StorageException(exception.getCode(), exception.getMessage(), retryable);
107109
}
108110

111+
private static void applyOptions(StorageObject storageObject, Map<Option, ?> options) {
112+
if (IF_MD5_MATCH.getBoolean(options) == null) {
113+
storageObject.setMd5Hash(null);
114+
}
115+
if (IF_CRC32C_MATCH.getBoolean(options) == null) {
116+
storageObject.setCrc32c(null);
117+
}
118+
}
119+
109120
@Override
110121
public Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageException {
111122
try {
@@ -123,6 +134,7 @@ public Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageExcept
123134
@Override
124135
public StorageObject create(StorageObject storageObject, final InputStream content,
125136
Map<Option, ?> options) throws StorageException {
137+
applyOptions(storageObject, options);
126138
try {
127139
Storage.Objects.Insert insert = storage.objects()
128140
.insert(storageObject.getBucket(), storageObject,
@@ -491,6 +503,7 @@ public void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObj
491503
@Override
492504
public String open(StorageObject object, Map<Option, ?> options)
493505
throws StorageException {
506+
applyOptions(object, options);
494507
try {
495508
Insert req = storage.objects().insert(object.getBucket(), object);
496509
GenericUrl url = req.buildHttpRequest().getUrl();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ enum Option {
4242
IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"),
4343
IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"),
4444
IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"),
45+
IF_MD5_MATCH("md5Hash"),
46+
IF_CRC32C_MATCH("crc32c"),
4547
PREFIX("prefix"),
4648
MAX_RESULTS("maxResults"),
4749
PAGE_TOKEN("pageToken"),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.collect.Lists;
2525
import com.google.gcloud.spi.StorageRpc;
2626
import com.google.gcloud.storage.Storage.BlobTargetOption;
27+
import com.google.gcloud.storage.Storage.BlobWriteOption;
2728
import com.google.gcloud.storage.Storage.CopyRequest;
2829
import com.google.gcloud.storage.Storage.SignUrlOption;
2930

@@ -274,7 +275,7 @@ public BlobReadChannel reader(BlobSourceOption... options) {
274275
* @param options target blob options
275276
* @throws StorageException upon failure
276277
*/
277-
public BlobWriteChannel writer(BlobTargetOption... options) {
278+
public BlobWriteChannel writer(BlobWriteOption... options) {
278279
return storage.writer(info, options);
279280
}
280281

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

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,67 @@ public static BlobTargetOption metagenerationMatch() {
145145
public static BlobTargetOption metagenerationNotMatch() {
146146
return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
147147
}
148+
149+
static BlobWriteOption[] convert(BlobTargetOption[] options, BlobWriteOption... optionsToAdd) {
150+
BlobWriteOption[] writeOptions = new BlobWriteOption[options.length + optionsToAdd.length];
151+
int index = 0;
152+
for (BlobTargetOption option : options) {
153+
writeOptions[index++] = new BlobWriteOption(option);
154+
}
155+
for (BlobWriteOption option : optionsToAdd) {
156+
writeOptions[index++] = option;
157+
}
158+
return writeOptions;
159+
}
160+
}
161+
162+
class BlobWriteOption extends Option {
163+
164+
private static final long serialVersionUID = -3880421670966224580L;
165+
166+
BlobWriteOption(BlobTargetOption option) {
167+
super(option.rpcOption(), option.value());
168+
}
169+
170+
private BlobWriteOption(StorageRpc.Option rpcOption, Object value) {
171+
super(rpcOption, value);
172+
}
173+
174+
private BlobWriteOption(StorageRpc.Option rpcOption) {
175+
this(rpcOption, null);
176+
}
177+
178+
public static BlobWriteOption predefinedAcl(PredefinedAcl acl) {
179+
return new BlobWriteOption(StorageRpc.Option.PREDEFINED_ACL, acl.entry());
180+
}
181+
182+
public static BlobWriteOption doesNotExist() {
183+
return new BlobWriteOption(StorageRpc.Option.IF_GENERATION_MATCH, 0L);
184+
}
185+
186+
public static BlobWriteOption generationMatch() {
187+
return new BlobWriteOption(StorageRpc.Option.IF_GENERATION_MATCH);
188+
}
189+
190+
public static BlobWriteOption generationNotMatch() {
191+
return new BlobWriteOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH);
192+
}
193+
194+
public static BlobWriteOption metagenerationMatch() {
195+
return new BlobWriteOption(StorageRpc.Option.IF_METAGENERATION_MATCH);
196+
}
197+
198+
public static BlobWriteOption metagenerationNotMatch() {
199+
return new BlobWriteOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
200+
}
201+
202+
public static BlobWriteOption md5Match() {
203+
return new BlobWriteOption(StorageRpc.Option.IF_MD5_MATCH, true);
204+
}
205+
206+
public static BlobWriteOption crc32cMatch() {
207+
return new BlobWriteOption(StorageRpc.Option.IF_CRC32C_MATCH, true);
208+
}
148209
}
149210

150211
class BlobSourceOption extends Option {
@@ -510,10 +571,12 @@ public static Builder builder() {
510571

511572
/**
512573
* Create a new blob. Direct upload is used to upload {@code content}. For large content,
513-
* {@link #writer} is recommended as it uses resumable upload.
574+
* {@link #writer} is recommended as it uses resumable upload. MD5 and CRC32C hashes of
575+
* {@code content} are computed and used for validating transferred data.
514576
*
515577
* @return a complete blob information.
516578
* @throws StorageException upon failure
579+
* @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a>
517580
*/
518581
BlobInfo create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options);
519582

@@ -524,7 +587,7 @@ public static Builder builder() {
524587
* @return a complete blob information.
525588
* @throws StorageException upon failure
526589
*/
527-
BlobInfo create(BlobInfo blobInfo, InputStream content, BlobTargetOption... options);
590+
BlobInfo create(BlobInfo blobInfo, InputStream content, BlobWriteOption... options);
528591

529592
/**
530593
* Return the requested bucket or {@code null} if not found.
@@ -683,7 +746,7 @@ public static Builder builder() {
683746
*
684747
* @throws StorageException upon failure
685748
*/
686-
BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options);
749+
BlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options);
687750

688751
/**
689752
* Generates a signed URL for a blob.

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.google.common.collect.Lists;
4141
import com.google.common.collect.Maps;
4242
import com.google.common.collect.Sets;
43+
import com.google.common.hash.Hashing;
4344
import com.google.common.io.BaseEncoding;
4445
import com.google.common.primitives.Ints;
4546
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
@@ -93,13 +94,14 @@ public RetryResult beforeEval(Exception exception) {
9394
static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler.builder()
9495
.abortOn(RuntimeException.class).interceptor(EXCEPTION_HANDLER_INTERCEPTOR).build();
9596
private static final byte[] EMPTY_BYTE_ARRAY = {};
97+
private static final String EMPTY_BYTE_ARRAY_MD5 = "1B2M2Y8AsgTpgAmY7PhCfg==";
98+
private static final String EMPTY_BYTE_ARRAY_CRC32C = "AAAAAA==";
9699

97100
private final StorageRpc storageRpc;
98101

99102
StorageImpl(StorageOptions options) {
100103
super(options);
101104
storageRpc = options.storageRpc();
102-
// todo: configure timeouts - https://developers.google.com/api-client-library/java/google-api-java-client/errors
103105
// todo: provide rewrite - https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite
104106
// todo: check if we need to expose https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/insert vs using bucket update/patch
105107
}
@@ -123,18 +125,29 @@ public com.google.api.services.storage.model.Bucket call() {
123125

124126
@Override
125127
public BlobInfo create(BlobInfo blobInfo, BlobTargetOption... options) {
126-
return create(blobInfo, new ByteArrayInputStream(EMPTY_BYTE_ARRAY), options);
128+
BlobInfo updatedInfo = blobInfo.toBuilder()
129+
.md5(EMPTY_BYTE_ARRAY_MD5)
130+
.crc32c(EMPTY_BYTE_ARRAY_CRC32C)
131+
.build();
132+
return create(updatedInfo, new ByteArrayInputStream(EMPTY_BYTE_ARRAY),
133+
BlobTargetOption.convert(
134+
options, BlobWriteOption.md5Match(), BlobWriteOption.crc32cMatch()));
127135
}
128136

129137
@Override
130-
public BlobInfo create(BlobInfo blobInfo, final byte[] content, BlobTargetOption... options) {
131-
return create(blobInfo,
132-
new ByteArrayInputStream(firstNonNull(content, EMPTY_BYTE_ARRAY)), options);
138+
public BlobInfo create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) {
139+
content = firstNonNull(content, EMPTY_BYTE_ARRAY);
140+
BlobInfo updatedInfo = blobInfo.toBuilder()
141+
.md5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes()))
142+
.crc32c(BaseEncoding.base64().encode(
143+
Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
144+
.build();
145+
return create(updatedInfo, new ByteArrayInputStream(content), BlobTargetOption.convert(
146+
options, BlobWriteOption.md5Match(), BlobWriteOption.crc32cMatch()));
133147
}
134148

135149
@Override
136-
public BlobInfo create(BlobInfo blobInfo, final InputStream content,
137-
BlobTargetOption... options) {
150+
public BlobInfo create(BlobInfo blobInfo, final InputStream content, BlobWriteOption... options) {
138151
final StorageObject blobPb = blobInfo.toPb();
139152
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
140153
try {
@@ -544,7 +557,7 @@ public BlobReadChannel reader(BlobId blob, BlobSourceOption... options) {
544557
}
545558

546559
@Override
547-
public BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) {
560+
public BlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options) {
548561
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
549562
return new BlobWriteChannelImpl(options(), blobInfo, optionsMap);
550563
}

0 commit comments

Comments
 (0)