Skip to content

Commit 30193bb

Browse files
committed
---
yaml --- r: 1823 b: refs/heads/pubsub-alpha c: deecc14 h: refs/heads/master i: 1821: a51252e 1819: e8d788d 1815: 2e9f9eb 1807: 6dcee22 1791: 25b23bb
1 parent ecbbac2 commit 30193bb

13 files changed

Lines changed: 520 additions & 32 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: cb64ccd8c83d534937c0f61a322df36b2081a159
6+
refs/heads/pubsub-alpha: deecc14fe1015d7f3e62323da57471f9d7dd8ec1
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.gcloud.spi;
1616

1717
import static com.google.gcloud.spi.StorageRpc.Option.DELIMITER;
18+
import static com.google.gcloud.spi.StorageRpc.Option.FIELDS;
1819
import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_MATCH;
1920
import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_NOT_MATCH;
2021
import static com.google.gcloud.spi.StorageRpc.Option.IF_METAGENERATION_MATCH;
@@ -168,6 +169,7 @@ public Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?>
168169
.setPrefix(PREFIX.getString(options))
169170
.setMaxResults(MAX_RESULTS.getLong(options))
170171
.setPageToken(PAGE_TOKEN.getString(options))
172+
.setFields(FIELDS.getString(options))
171173
.execute();
172174
return Tuple.<String, Iterable<StorageObject>>of(
173175
objects.getNextPageToken(), objects.getItems());
@@ -207,7 +209,8 @@ private Storage.Objects.Get getRequest(StorageObject object, Map<Option, ?> opti
207209
.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
208210
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
209211
.setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options))
210-
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options));
212+
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options))
213+
.setFields(FIELDS.getString(options));
211214
}
212215

213216
@Override

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum Option {
4747
MAX_RESULTS("maxResults"),
4848
PAGE_TOKEN("pageToken"),
4949
DELIMITER("delimiter"),
50-
VERSIONS("versions");
50+
VERSIONS("versions"),
51+
FIELDS("fields");
5152

5253
private final String value;
5354

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.common.collect.Lists;
21+
import com.google.gcloud.storage.Storage.BlobGetOption;
2122
import com.google.gcloud.storage.Storage.BlobSourceOption;
2223
import com.google.gcloud.storage.Storage.BlobTargetOption;
2324

@@ -35,13 +36,13 @@ public final class BatchRequest implements Serializable {
3536

3637
private final Map<BlobId, Iterable<BlobSourceOption>> toDelete;
3738
private final Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate;
38-
private final Map<BlobId, Iterable<BlobSourceOption>> toGet;
39+
private final Map<BlobId, Iterable<BlobGetOption>> toGet;
3940

4041
public static class Builder {
4142

4243
private Map<BlobId, Iterable<BlobSourceOption>> toDelete = new LinkedHashMap<>();
4344
private Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate = new LinkedHashMap<>();
44-
private Map<BlobId, Iterable<BlobSourceOption>> toGet = new LinkedHashMap<>();
45+
private Map<BlobId, Iterable<BlobGetOption>> toGet = new LinkedHashMap<>();
4546

4647
private Builder() {}
4748

@@ -72,15 +73,15 @@ public Builder update(BlobInfo blobInfo, BlobTargetOption... options) {
7273
/**
7374
* Retrieve metadata for the given blob.
7475
*/
75-
public Builder get(String bucket, String blob, BlobSourceOption... options) {
76+
public Builder get(String bucket, String blob, BlobGetOption... options) {
7677
toGet.put(BlobId.of(bucket, blob), Lists.newArrayList(options));
7778
return this;
7879
}
7980

8081
/**
8182
* Retrieve metadata for the given blob.
8283
*/
83-
public Builder get(BlobId blob, BlobSourceOption... options) {
84+
public Builder get(BlobId blob, BlobGetOption... options) {
8485
toGet.put(blob, Lists.newArrayList(options));
8586
return this;
8687
}
@@ -120,7 +121,7 @@ public Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate() {
120121
return toUpdate;
121122
}
122123

123-
public Map<BlobId, Iterable<BlobSourceOption>> toGet() {
124+
public Map<BlobId, Iterable<BlobGetOption>> toGet() {
124125
return toGet;
125126
}
126127

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121
import static com.google.gcloud.storage.Blob.BlobSourceOption.convert;
22+
import static com.google.gcloud.storage.Blob.BlobSourceOption.toGetOptions;
2223

2324
import com.google.common.base.Function;
2425
import com.google.common.collect.Lists;
@@ -29,6 +30,7 @@
2930
import com.google.gcloud.storage.Storage.SignUrlOption;
3031

3132
import java.net.URL;
33+
import java.util.Arrays;
3234
import java.util.Collections;
3335
import java.util.List;
3436
import java.util.Objects;
@@ -71,6 +73,21 @@ private Storage.BlobSourceOption convert(BlobInfo blobInfo) {
7173
}
7274
}
7375

76+
private Storage.BlobGetOption toGetOption(BlobInfo blobInfo) {
77+
switch (rpcOption()) {
78+
case IF_GENERATION_MATCH:
79+
return Storage.BlobGetOption.generationMatch(blobInfo.generation());
80+
case IF_GENERATION_NOT_MATCH:
81+
return Storage.BlobGetOption.generationNotMatch(blobInfo.generation());
82+
case IF_METAGENERATION_MATCH:
83+
return Storage.BlobGetOption.metagenerationMatch(blobInfo.metageneration());
84+
case IF_METAGENERATION_NOT_MATCH:
85+
return Storage.BlobGetOption.metagenerationNotMatch(blobInfo.metageneration());
86+
default:
87+
throw new AssertionError("Unexpected enum value");
88+
}
89+
}
90+
7491
public static BlobSourceOption generationMatch() {
7592
return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH);
7693
}
@@ -95,6 +112,15 @@ static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption...
95112
}
96113
return convertedOptions;
97114
}
115+
116+
static Storage.BlobGetOption[] toGetOptions(BlobInfo blobInfo, BlobSourceOption... options) {
117+
Storage.BlobGetOption[] convertedOptions = new Storage.BlobGetOption[options.length];
118+
int index = 0;
119+
for (BlobSourceOption option : options) {
120+
convertedOptions[index++] = option.toGetOption(blobInfo);
121+
}
122+
return convertedOptions;
123+
}
98124
}
99125

100126
/**
@@ -159,7 +185,10 @@ public BlobId id() {
159185
* @throws StorageException upon failure
160186
*/
161187
public boolean exists(BlobSourceOption... options) {
162-
return storage.get(info.blobId(), convert(info, options)) != null;
188+
int length = options.length;
189+
Storage.BlobGetOption[] getOptions = Arrays.copyOf(toGetOptions(info, options), length + 1);
190+
getOptions[length] = Storage.BlobGetOption.fields();
191+
return storage.get(info.blobId(), getOptions) != null;
163192
}
164193

165194
/**
@@ -180,7 +209,7 @@ public byte[] content(Storage.BlobSourceOption... options) {
180209
* @throws StorageException upon failure
181210
*/
182211
public Blob reload(BlobSourceOption... options) {
183-
return new Blob(storage, storage.get(info.blobId(), convert(info, options)));
212+
return new Blob(storage, storage.get(info.blobId(), toGetOptions(info, options)));
184213
}
185214

186215
/**

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.google.common.collect.Iterators;
2525
import com.google.gcloud.PageImpl;
2626
import com.google.gcloud.Page;
27-
import com.google.gcloud.storage.Storage.BlobSourceOption;
27+
import com.google.gcloud.storage.Storage.BlobGetOption;
2828
import com.google.gcloud.storage.Storage.BlobTargetOption;
2929
import com.google.gcloud.storage.Storage.BlobWriteOption;
3030
import com.google.gcloud.storage.Storage.BucketSourceOption;
@@ -221,7 +221,7 @@ public Page<Blob> list(Storage.BlobListOption... options) {
221221
* @param options blob search options
222222
* @throws StorageException upon failure
223223
*/
224-
public Blob get(String blob, BlobSourceOption... options) {
224+
public Blob get(String blob, BlobGetOption... options) {
225225
return new Blob(storage, storage.get(BlobId.of(info.name(), blob), options));
226226
}
227227

0 commit comments

Comments
 (0)