Skip to content

Commit d3a49ea

Browse files
committed
Add createTime() to BlobInfo and Blob classes (#1034)
1 parent 11f4573 commit d3a49ea

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ Builder updateTime(Long updateTime) {
295295
return this;
296296
}
297297

298+
@Override
299+
Builder createTime(Long createTime) {
300+
infoBuilder.createTime(createTime);
301+
return this;
302+
}
303+
298304
@Override
299305
Builder isDirectory(boolean isDirectory) {
300306
infoBuilder.isDirectory(isDirectory);

gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobInfo.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public StorageObject apply(BlobInfo blobInfo) {
7373
private final Long metageneration;
7474
private final Long deleteTime;
7575
private final Long updateTime;
76+
private final Long createTime;
7677
private final String contentType;
7778
private final String contentEncoding;
7879
private final String contentDisposition;
@@ -188,6 +189,8 @@ public abstract static class Builder {
188189

189190
abstract Builder updateTime(Long updateTime);
190191

192+
abstract Builder createTime(Long createTime);
193+
191194
abstract Builder isDirectory(boolean isDirectory);
192195

193196
/**
@@ -218,6 +221,7 @@ static final class BuilderImpl extends Builder {
218221
private Long metageneration;
219222
private Long deleteTime;
220223
private Long updateTime;
224+
private Long createTime;
221225
private Boolean isDirectory;
222226

223227
BuilderImpl(BlobId blobId) {
@@ -245,6 +249,7 @@ static final class BuilderImpl extends Builder {
245249
metageneration = blobInfo.metageneration;
246250
deleteTime = blobInfo.deleteTime;
247251
updateTime = blobInfo.updateTime;
252+
createTime = blobInfo.createTime;
248253
isDirectory = blobInfo.isDirectory;
249254
}
250255

@@ -369,6 +374,12 @@ Builder updateTime(Long updateTime) {
369374
return this;
370375
}
371376

377+
@Override
378+
Builder createTime(Long createTime) {
379+
this.createTime = createTime;
380+
return this;
381+
}
382+
372383
@Override
373384
Builder isDirectory(boolean isDirectory) {
374385
this.isDirectory = isDirectory;
@@ -403,6 +414,7 @@ public BlobInfo build() {
403414
metageneration = builder.metageneration;
404415
deleteTime = builder.deleteTime;
405416
updateTime = builder.updateTime;
417+
createTime = builder.createTime;
406418
isDirectory = firstNonNull(builder.isDirectory, Boolean.FALSE);
407419
}
408420

@@ -600,6 +612,13 @@ public Long updateTime() {
600612
return updateTime;
601613
}
602614

615+
/**
616+
* Returns the creation time of the blob.
617+
*/
618+
public Long createTime() {
619+
return createTime;
620+
}
621+
603622
/**
604623
* Returns {@code true} if the current blob represents a directory. This can only happen if the
605624
* blob is returned by {@link Storage#list(String, Storage.BlobListOption...)} when the
@@ -660,6 +679,9 @@ public ObjectAccessControl apply(Acl acl) {
660679
if (updateTime != null) {
661680
storageObject.setUpdated(new DateTime(updateTime));
662681
}
682+
if (createTime != null) {
683+
storageObject.setTimeCreated(new DateTime(createTime));
684+
}
663685
if (size != null) {
664686
storageObject.setSize(BigInteger.valueOf(size));
665687
}
@@ -773,6 +795,9 @@ static BlobInfo fromPb(StorageObject storageObject) {
773795
if (storageObject.getUpdated() != null) {
774796
builder.updateTime(storageObject.getUpdated().getValue());
775797
}
798+
if (storageObject.getTimeCreated() != null) {
799+
builder.createTime(storageObject.getTimeCreated().getValue());
800+
}
776801
if (storageObject.getSize() != null) {
777802
builder.size(storageObject.getSize().longValue());
778803
}

gcloud-java-storage/src/test/java/com/google/cloud/storage/BlobInfoTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class BlobInfoTest {
6060
private static final String SELF_LINK = "http://storage/b/n";
6161
private static final Long SIZE = 1024L;
6262
private static final Long UPDATE_TIME = DELETE_TIME - 1L;
63+
private static final Long CREATE_TIME = UPDATE_TIME - 1L;
6364
private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n", GENERATION)
6465
.acl(ACL)
6566
.componentCount(COMPONENT_COUNT)
@@ -80,6 +81,7 @@ public class BlobInfoTest {
8081
.selfLink(SELF_LINK)
8182
.size(SIZE)
8283
.updateTime(UPDATE_TIME)
84+
.createTime(CREATE_TIME)
8385
.build();
8486
private static final BlobInfo DIRECTORY_INFO = BlobInfo.builder("b", "n/")
8587
.size(0L)
@@ -127,6 +129,7 @@ public void testBuilder() {
127129
assertEquals(SELF_LINK, BLOB_INFO.selfLink());
128130
assertEquals(SIZE, BLOB_INFO.size());
129131
assertEquals(UPDATE_TIME, BLOB_INFO.updateTime());
132+
assertEquals(CREATE_TIME, BLOB_INFO.createTime());
130133
assertFalse(BLOB_INFO.isDirectory());
131134
assertEquals("b", DIRECTORY_INFO.bucket());
132135
assertEquals("n/", DIRECTORY_INFO.name());
@@ -138,6 +141,7 @@ public void testBuilder() {
138141
assertNull(DIRECTORY_INFO.contentEncoding());
139142
assertNull(DIRECTORY_INFO.contentLanguage());
140143
assertNull(DIRECTORY_INFO.crc32c());
144+
assertNull(DIRECTORY_INFO.createTime());
141145
assertNull(DIRECTORY_INFO.deleteTime());
142146
assertNull(DIRECTORY_INFO.etag());
143147
assertNull(DIRECTORY_INFO.generation());
@@ -165,6 +169,7 @@ private void compareBlobs(BlobInfo expected, BlobInfo value) {
165169
assertEquals(expected.contentEncoding(), value.contentEncoding());
166170
assertEquals(expected.contentLanguage(), value.contentLanguage());
167171
assertEquals(expected.crc32c(), value.crc32c());
172+
assertEquals(expected.createTime(), value.createTime());
168173
assertEquals(expected.deleteTime(), value.deleteTime());
169174
assertEquals(expected.etag(), value.etag());
170175
assertEquals(expected.generation(), value.generation());
@@ -200,6 +205,7 @@ public void testToPbAndFromPb() {
200205
assertNull(blobInfo.contentEncoding());
201206
assertNull(blobInfo.contentLanguage());
202207
assertNull(blobInfo.crc32c());
208+
assertNull(blobInfo.createTime());
203209
assertNull(blobInfo.deleteTime());
204210
assertNull(blobInfo.etag());
205211
assertNull(blobInfo.generation());

gcloud-java-storage/src/test/java/com/google/cloud/storage/BlobTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class BlobTest {
7373
private static final String SELF_LINK = "http://storage/b/n";
7474
private static final Long SIZE = 1024L;
7575
private static final Long UPDATE_TIME = DELETE_TIME - 1L;
76+
private static final Long CREATE_TIME = UPDATE_TIME - 1L;
7677
private static final BlobInfo FULL_BLOB_INFO = BlobInfo.builder("b", "n", GENERATION)
7778
.acl(ACL)
7879
.componentCount(COMPONENT_COUNT)
@@ -93,6 +94,7 @@ public class BlobTest {
9394
.selfLink(SELF_LINK)
9495
.size(SIZE)
9596
.updateTime(UPDATE_TIME)
97+
.createTime(CREATE_TIME)
9698
.build();
9799
private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n").metageneration(42L).build();
98100
private static final BlobInfo DIRECTORY_INFO = BlobInfo.builder("b", "n/")
@@ -347,6 +349,7 @@ public void testBuilder() {
347349
.selfLink(SELF_LINK)
348350
.size(SIZE)
349351
.updateTime(UPDATE_TIME)
352+
.createTime(CREATE_TIME)
350353
.build();
351354
assertEquals("b", blob.bucket());
352355
assertEquals("n", blob.name());
@@ -358,6 +361,7 @@ public void testBuilder() {
358361
assertEquals(CONTENT_ENCODING, blob.contentEncoding());
359362
assertEquals(CONTENT_LANGUAGE, blob.contentLanguage());
360363
assertEquals(CRC32, blob.crc32c());
364+
assertEquals(CREATE_TIME, blob.createTime());
361365
assertEquals(DELETE_TIME, blob.deleteTime());
362366
assertEquals(ETAG, blob.etag());
363367
assertEquals(GENERATED_ID, blob.generatedId());
@@ -385,6 +389,7 @@ public void testBuilder() {
385389
assertNull(blob.contentEncoding());
386390
assertNull(blob.contentLanguage());
387391
assertNull(blob.crc32c());
392+
assertNull(blob.createTime());
388393
assertNull(blob.deleteTime());
389394
assertNull(blob.etag());
390395
assertNull(blob.generatedId());

0 commit comments

Comments
 (0)