Skip to content

Commit 8ebf537

Browse files
committed
work in progress
1 parent 4612cf9 commit 8ebf537

8 files changed

Lines changed: 322 additions & 194 deletions

File tree

src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.gcloud.storage.BlobReadChannel;import com.google.gcloud.storage.BlobWriteChannel;import java.io.IOException;import java.nio.ByteBuffer;import java.util.Iterator;public interface StorageRpc { Bucket create(Bucket bucket) throws IOException; StorageObject create(StorageObject object, ByteBuffer content) throws IOException; Iterator<Bucket> list() throws IOException; Iterator<StorageObject> list(String bucket, String prefix, String delimiter, String cursor, boolean versions, int limit) throws IOException; Bucket get(String bucket) throws IOException; StorageObject get(String bucket, String object) throws IOException; Bucket patch(Bucket bucket) throws IOException; StorageObject patch(StorageObject storageObject) throws IOException; void delete(Bucket bucket) throws IOException; void delete(StorageObject object) throws IOException; StorageObject compose(String bucket, Iterable<String> src, StorageObject dest) throws IOException; StorageObject copy(StorageObject from, StorageObject to) throws IOException; BlobReadChannel reader(StorageObject from) throws IOException; BlobWriteChannel writer(StorageObject to) throws IOException;}
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.gcloud.storage.BlobReadChannel;import com.google.gcloud.storage.BlobWriteChannel;import com.google.gcloud.storage.Option;import java.io.IOException;import java.nio.ByteBuffer;import java.util.Iterator;import java.util.List;public interface StorageRpc { Bucket create(Bucket bucket, Option... options) throws IOException; StorageObject create(StorageObject object, ByteBuffer content, Option... options) throws IOException; Iterator<Bucket> list() throws IOException; Iterator<StorageObject> list(String bucket, String prefix, String delimiter, String cursor, boolean versions, int limit) throws IOException; Bucket get(String bucket, Option... options) throws IOException; StorageObject get(String bucket, String object, Option... options) throws IOException; Bucket patch(Bucket bucket, Option... options) throws IOException; StorageObject patch(StorageObject storageObject, Option... options) throws IOException; void delete(Bucket bucket, Option... options) throws IOException; void delete(StorageObject object, Option... options) throws IOException; StorageObject compose(Iterable<StorageObject> src, StorageObject destination, List<? extends Option> destinationOptions) throws IOException; StorageObject copy(StorageObject from, List<? extends Option> blobSourceOptions, StorageObject to, List<? extends Option> blobTargetOptions) throws IOException; BlobReadChannel reader(StorageObject from, Option... options) throws IOException; BlobWriteChannel writer(StorageObject to, Option... options) throws IOException;}

src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ public class Blob implements Serializable {
5454
private final String name;
5555
private final String selfLink;
5656
private final String cacheControl;
57-
private final ImmutableList<Acl> acl;
57+
private final List<Acl> acl;
5858
private final Acl.Entity owner;
59-
private final long size;
59+
private final Long size;
6060
private final String etag;
6161
private final String md5;
6262
private final String crc32c;
6363
private final String mediaLink;
64-
private final ImmutableMap<String, String> metadata;
65-
private final long generation;
66-
private final long metageneration;
67-
private final long deleteTime;
68-
private final long updateTime;
64+
private final Map<String, String> metadata;
65+
private final Long generation;
66+
private final Long metageneration;
67+
private final Long deleteTime;
68+
private final Long updateTime;
6969
private final String contentType;
7070
private final String contentEncoding;
7171
private final String contentDisposition;
7272
private final String contentLanguage;
73-
private final int componentCount;
73+
private final Integer componentCount;
7474

7575
public static final class Builder {
7676

@@ -80,22 +80,22 @@ public static final class Builder {
8080
private String contentType;
8181
private String contentEncoding;
8282
private String contentDisposition;
83-
private String contentLanguage;
84-
private int componentCount;
83+
private String contentLanguage;
84+
private Integer componentCount;
8585
private String cacheControl;
8686
private ImmutableList<Acl> acl;
8787
private Acl.Entity owner;
88-
private long size;
88+
private Long size;
8989
private String etag;
9090
private String selfLink;
9191
private String md5;
9292
private String crc32c;
9393
private String mediaLink;
9494
private ImmutableMap<String, String> metadata;
95-
private long generation;
96-
private long metageneration;
97-
private long deleteTime;
98-
private long updateTime;
95+
private Long generation;
96+
private Long metageneration;
97+
private Long deleteTime;
98+
private Long updateTime;
9999

100100
private Builder() {
101101
}
@@ -135,7 +135,7 @@ public Builder contentEncoding(String contentEncoding) {
135135
return this;
136136
}
137137

138-
Builder componentCount(int componentCount) {
138+
Builder componentCount(Integer componentCount) {
139139
this.componentCount = componentCount;
140140
return this;
141141
}
@@ -155,7 +155,7 @@ public Builder owner(Acl.Entity owner) {
155155
return this;
156156
}
157157

158-
public Builder size(long size) {
158+
public Builder size(Long size) {
159159
this.size = size;
160160
return this;
161161
}
@@ -190,34 +190,36 @@ public Builder metadata(Map<String, String> metadata) {
190190
return this;
191191
}
192192

193-
public Builder generation(long generation) {
193+
public Builder generation(Long generation) {
194194
this.generation = generation;
195195
return this;
196196
}
197197

198-
public Builder metageneration(long metageneration) {
198+
public Builder metageneration(Long metageneration) {
199199
this.metageneration = metageneration;
200200
return this;
201201
}
202202

203-
public Builder deleteTime(long deleteTime) {
203+
public Builder deleteTime(Long deleteTime) {
204204
this.deleteTime = deleteTime;
205205
return this;
206206
}
207207

208-
public Builder updateTime(long updateTime) {
208+
public Builder updateTime(Long updateTime) {
209209
this.updateTime = updateTime;
210210
return this;
211211
}
212212

213213
public Blob build() {
214+
checkNotNull(bucket);
215+
checkNotNull(name);
214216
return new Blob(this);
215217
}
216218
}
217219

218220
private Blob(Builder builder) {
219-
bucket = checkNotNull(builder.bucket);
220-
name = checkNotNull(builder.name);
221+
bucket = builder.bucket;
222+
name = builder.name;
221223
id = builder.id;
222224
cacheControl = builder.cacheControl;
223225
contentEncoding = builder.contentEncoding;
@@ -264,7 +266,7 @@ public Acl.Entity owner() {
264266
return owner;
265267
}
266268

267-
public long size() {
269+
public Long size() {
268270
return size;
269271
}
270272

@@ -284,7 +286,7 @@ public String contentLanguage() {
284286
return contentEncoding;
285287
}
286288

287-
public int componentCount() {
289+
public Integer componentCount() {
288290
return componentCount;
289291
}
290292

@@ -312,19 +314,19 @@ public Map<String, String> metadata() {
312314
return metadata;
313315
}
314316

315-
public long generation() {
317+
public Long generation() {
316318
return generation;
317319
}
318320

319-
public long metageneration() {
321+
public Long metageneration() {
320322
return metageneration;
321323
}
322324

323-
public long deleteTime() {
325+
public Long deleteTime() {
324326
return deleteTime;
325327
}
326328

327-
public long updateTime() {
329+
public Long updateTime() {
328330
return updateTime;
329331
}
330332

@@ -364,27 +366,36 @@ public static Builder builder(String bucket, String name) {
364366

365367
StorageObject toPb() {
366368
StorageObject storageObject = new StorageObject();
367-
storageObject.setAcl(Lists.transform(acl,
368-
new Function<Acl, ObjectAccessControl>() {
369-
@Override public ObjectAccessControl apply(Acl acl) {
370-
return acl.toObjectPb();
371-
}
372-
}));
369+
if (acl != null) {
370+
storageObject.setAcl(Lists.transform(acl, new Function<Acl, ObjectAccessControl>() {
371+
@Override public ObjectAccessControl apply(Acl acl) {
372+
return acl.toObjectPb();
373+
}
374+
}));
375+
}
376+
if (deleteTime != null) {
377+
storageObject.setTimeDeleted(new DateTime(deleteTime));
378+
}
379+
if (updateTime != null) {
380+
storageObject.setUpdated(new DateTime(updateTime));
381+
}
382+
if (size != null) {
383+
storageObject.setSize(BigInteger.valueOf(size));
384+
}
385+
if (owner != null) {
386+
storageObject.setOwner(new Owner().setEntity(owner.toPb()));
387+
}
373388
storageObject.setBucket(bucket);
374389
storageObject.setCacheControl(cacheControl);
375390
storageObject.setContentEncoding(contentEncoding);
376391
storageObject.setCrc32c(crc32c);
377392
storageObject.setContentType(contentType);
378-
storageObject.setTimeDeleted(new DateTime(deleteTime));
379393
storageObject.setGeneration(generation);
380394
storageObject.setMd5Hash(md5);
381395
storageObject.setMediaLink(mediaLink);
382396
storageObject.setMetadata(metadata);
383397
storageObject.setMetageneration(metageneration);
384398
storageObject.setName(name);
385-
storageObject.setOwner(new Owner().setEntity(owner.toPb()));
386-
storageObject.setUpdated(new DateTime(updateTime));
387-
storageObject.setSize(BigInteger.valueOf(size));
388399
storageObject.setContentDisposition(contentDisposition);
389400
storageObject.setComponentCount(componentCount);
390401
storageObject.setContentLanguage(contentLanguage);
@@ -395,34 +406,44 @@ StorageObject toPb() {
395406
}
396407

397408
static Blob fromPb(StorageObject storageObject) {
398-
return new Builder()
399-
.acl(Lists.transform(storageObject.getAcl(),
400-
new Function<ObjectAccessControl, Acl>() {
401-
@Override public Acl apply(ObjectAccessControl objectAccessControl) {
402-
return Acl.fromPb(objectAccessControl);
403-
}
404-
}))
409+
Builder builder = new Builder()
405410
.bucket(storageObject.getBucket())
406411
.cacheControl(storageObject.getCacheControl())
407412
.contentEncoding(storageObject.getContentEncoding())
408413
.crc32c(storageObject.getCrc32c())
409414
.contentType(storageObject.getContentType())
410-
.deleteTime(storageObject.getTimeDeleted().getValue())
411415
.generation(storageObject.getGeneration())
412416
.md5(storageObject.getMd5Hash())
413417
.mediaLink(storageObject.getMediaLink())
414418
.metadata(storageObject.getMetadata())
415419
.metageneration(storageObject.getMetageneration())
416420
.name(storageObject.getName())
417-
.owner(Acl.Entity.fromPb(storageObject.getOwner().getEntity()))
418-
.updateTime(storageObject.getUpdated().getValue())
419-
.size(storageObject.getSize().longValue())
420421
.contentDisposition(storageObject.getContentDisposition())
421422
.componentCount(storageObject.getComponentCount())
422423
.contentLanguage(storageObject.getContentLanguage())
423424
.etag(storageObject.getEtag())
424425
.id(storageObject.getId())
425-
.selfLink(storageObject.getSelfLink())
426-
.build();
426+
.selfLink(storageObject.getSelfLink());
427+
if (storageObject.getTimeDeleted() != null) {
428+
builder.deleteTime(storageObject.getTimeDeleted().getValue());
429+
}
430+
if (storageObject.getUpdated() != null) {
431+
builder.updateTime(storageObject.getUpdated().getValue());
432+
}
433+
if (storageObject.getSize() != null) {
434+
builder.size(storageObject.getSize().longValue());
435+
}
436+
if (storageObject.getOwner() != null) {
437+
builder.owner(Acl.Entity.fromPb(storageObject.getOwner().getEntity()));
438+
}
439+
if (storageObject.getAcl() != null) {
440+
builder.acl(Lists.transform(storageObject.getAcl(), new Function<ObjectAccessControl, Acl>() {
441+
@Override
442+
public Acl apply(ObjectAccessControl objectAccessControl) {
443+
return Acl.fromPb(objectAccessControl);
444+
}
445+
}));
446+
}
447+
return builder.build();
427448
}
428449
}

0 commit comments

Comments
 (0)