Skip to content

Commit 8b89ba3

Browse files
committed
Use blobId in Blob whenever possible
1 parent fd333a9 commit 8b89ba3

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

  • gcloud-java-storage/src

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public BlobId id() {
154154
* @throws StorageException upon failure
155155
*/
156156
public boolean exists() {
157-
return storage.get(info.bucket(), info.name()) != null;
157+
return storage.get(info.blobId()) != null;
158158
}
159159

160160
/**
@@ -164,7 +164,7 @@ public boolean exists() {
164164
* @throws StorageException upon failure
165165
*/
166166
public byte[] content(Storage.BlobSourceOption... options) {
167-
return storage.readAllBytes(info.bucket(), info.name(), options);
167+
return storage.readAllBytes(info.blobId(), options);
168168
}
169169

170170
/**
@@ -175,7 +175,7 @@ public byte[] content(Storage.BlobSourceOption... options) {
175175
* @throws StorageException upon failure
176176
*/
177177
public Blob reload(BlobSourceOption... options) {
178-
return new Blob(storage, storage.get(info.bucket(), info.name(), convert(info, options)));
178+
return new Blob(storage, storage.get(info.blobId(), convert(info, options)));
179179
}
180180

181181
/**
@@ -205,7 +205,7 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
205205
* @throws StorageException upon failure
206206
*/
207207
public boolean delete(BlobSourceOption... options) {
208-
return storage.delete(info.bucket(), info.name(), convert(info, options));
208+
return storage.delete(info.blobId(), convert(info, options));
209209
}
210210

211211
/**
@@ -246,7 +246,7 @@ public Blob copyTo(String targetBucket, String targetBlob, BlobSourceOption... o
246246
* @throws StorageException upon failure
247247
*/
248248
public BlobReadChannel reader(BlobSourceOption... options) {
249-
return storage.reader(info.bucket(), info.name(), convert(info, options));
249+
return storage.reader(info.blobId(), convert(info, options));
250250
}
251251

252252
/**

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,30 @@ public void testInfo() throws Exception {
7070

7171
@Test
7272
public void testExists_True() throws Exception {
73-
expect(storage.get(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(BLOB_INFO);
73+
expect(storage.get(BLOB_INFO.blobId())).andReturn(BLOB_INFO);
7474
replay(storage);
7575
assertTrue(blob.exists());
7676
}
7777

7878
@Test
7979
public void testExists_False() throws Exception {
80-
expect(storage.get(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(null);
80+
expect(storage.get(BLOB_INFO.blobId())).andReturn(null);
8181
replay(storage);
8282
assertFalse(blob.exists());
8383
}
8484

8585
@Test
8686
public void testContent() throws Exception {
8787
byte[] content = {1, 2};
88-
expect(storage.readAllBytes(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(content);
88+
expect(storage.readAllBytes(BLOB_INFO.blobId())).andReturn(content);
8989
replay(storage);
9090
assertArrayEquals(content, blob.content());
9191
}
9292

9393
@Test
9494
public void testReload() throws Exception {
9595
BlobInfo updatedInfo = BLOB_INFO.toBuilder().cacheControl("c").build();
96-
expect(storage.get(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(updatedInfo);
96+
expect(storage.get(BLOB_INFO.blobId(), new Storage.BlobSourceOption[0])).andReturn(updatedInfo);
9797
replay(storage);
9898
Blob updatedBlob = blob.reload();
9999
assertSame(storage, blob.storage());
@@ -112,7 +112,7 @@ public void testUpdate() throws Exception {
112112

113113
@Test
114114
public void testDelete() throws Exception {
115-
expect(storage.delete(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(true);
115+
expect(storage.delete(BLOB_INFO.blobId(), new Storage.BlobSourceOption[0])).andReturn(true);
116116
replay(storage);
117117
assertTrue(blob.delete());
118118
}
@@ -146,7 +146,7 @@ public void testCopyTo() throws Exception {
146146
@Test
147147
public void testReader() throws Exception {
148148
BlobReadChannel channel = createMock(BlobReadChannel.class);
149-
expect(storage.reader(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(channel);
149+
expect(storage.reader(BLOB_INFO.blobId())).andReturn(channel);
150150
replay(storage);
151151
assertSame(channel, blob.reader());
152152
}

0 commit comments

Comments
 (0)