|
14 | 14 |
|
15 | 15 | package com.google.gcloud.spi; |
16 | 16 |
|
| 17 | +import static com.google.common.base.MoreObjects.firstNonNull; |
17 | 18 | import static com.google.gcloud.spi.StorageRpc.Option.DELIMITER; |
18 | 19 | import static com.google.gcloud.spi.StorageRpc.Option.FIELDS; |
19 | 20 | import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_MATCH; |
|
58 | 59 | import com.google.api.services.storage.model.Objects; |
59 | 60 | import com.google.api.services.storage.model.StorageObject; |
60 | 61 | import com.google.common.base.Function; |
61 | | -import com.google.common.base.MoreObjects; |
62 | 62 | import com.google.common.collect.ImmutableList; |
63 | 63 | import com.google.common.collect.Iterables; |
64 | 64 | import com.google.common.collect.Lists; |
@@ -167,24 +167,29 @@ public Tuple<String, Iterable<StorageObject>> list(final String bucket, Map<Opti |
167 | 167 | .setFields(FIELDS.getString(options)) |
168 | 168 | .execute(); |
169 | 169 | Iterable<StorageObject> storageObjects = Iterables.concat( |
170 | | - objects.getItems() != null ? objects.getItems() : ImmutableList.<StorageObject>of(), |
| 170 | + firstNonNull(objects.getItems(), ImmutableList.<StorageObject>of()), |
171 | 171 | objects.getPrefixes() != null |
172 | | - ? Lists.transform(objects.getPrefixes(), new Function<String, StorageObject>() { |
173 | | - @Override |
174 | | - public StorageObject apply(String prefix) { |
175 | | - return new StorageObject() |
176 | | - .set("isDirectory", true) |
177 | | - .setBucket(bucket) |
178 | | - .setName(prefix) |
179 | | - .setSize(BigInteger.ZERO); |
180 | | - } |
181 | | - }) : ImmutableList.<StorageObject>of()); |
| 172 | + ? Lists.transform(objects.getPrefixes(), objectFromPrefix(bucket)) |
| 173 | + : ImmutableList.<StorageObject>of()); |
182 | 174 | return Tuple.of(objects.getNextPageToken(), storageObjects); |
183 | 175 | } catch (IOException ex) { |
184 | 176 | throw translate(ex); |
185 | 177 | } |
186 | 178 | } |
187 | 179 |
|
| 180 | + private static Function<String, StorageObject> objectFromPrefix(final String bucket) { |
| 181 | + return new Function<String, StorageObject>() { |
| 182 | + @Override |
| 183 | + public StorageObject apply(String prefix) { |
| 184 | + return new StorageObject() |
| 185 | + .set("isDirectory", true) |
| 186 | + .setBucket(bucket) |
| 187 | + .setName(prefix) |
| 188 | + .setSize(BigInteger.ZERO); |
| 189 | + } |
| 190 | + }; |
| 191 | + } |
| 192 | + |
188 | 193 | @Override |
189 | 194 | public Bucket get(Bucket bucket, Map<Option, ?> options) { |
190 | 195 | try { |
@@ -549,7 +554,7 @@ public String open(StorageObject object, Map<Option, ?> options) { |
549 | 554 | HttpRequest httpRequest = |
550 | 555 | requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, object)); |
551 | 556 | httpRequest.getHeaders().set("X-Upload-Content-Type", |
552 | | - MoreObjects.firstNonNull(object.getContentType(), "application/octet-stream")); |
| 557 | + firstNonNull(object.getContentType(), "application/octet-stream")); |
553 | 558 | HttpResponse response = httpRequest.execute(); |
554 | 559 | if (response.getStatusCode() != 200) { |
555 | 560 | GoogleJsonError error = new GoogleJsonError(); |
|
0 commit comments