2828import com .google .gcloud .storage .Storage .SignUrlOption ;
2929
3030import java .net .URL ;
31- import java .util .Arrays ;
3231import java .util .Collections ;
3332import java .util .List ;
3433import java .util .Objects ;
@@ -119,7 +118,19 @@ public Blob(Storage storage, BlobInfo info) {
119118 */
120119 public Blob (Storage storage , String bucket , String blob ) {
121120 this .storage = checkNotNull (storage );
122- this .info = BlobInfo .of (checkNotNull (bucket ), checkNotNull (blob ));
121+ this .info = BlobInfo .builder (BlobId .of (bucket , blob )).build ();
122+ }
123+
124+ /**
125+ * Constructs a {@code Blob} object for the provided {@code BlobId}. The storage service is used
126+ * to issue requests.
127+ *
128+ * @param storage the storage service used for issuing requests
129+ * @param blobId blob's identifier
130+ */
131+ public Blob (Storage storage , BlobId blobId ) {
132+ this .storage = checkNotNull (storage );
133+ this .info = BlobInfo .builder (blobId ).build ();
123134 }
124135
125136 /**
@@ -129,6 +140,13 @@ public BlobInfo info() {
129140 return info ;
130141 }
131142
143+ /**
144+ * Returns the blob's id.
145+ */
146+ public BlobId id () {
147+ return info .blobId ();
148+ }
149+
132150 /**
133151 * Checks if this blob exists.
134152 *
@@ -214,7 +232,7 @@ public Blob copyTo(String targetBucket, BlobSourceOption... options) {
214232 * @throws StorageException upon failure
215233 */
216234 public Blob copyTo (String targetBucket , String targetBlob , BlobSourceOption ... options ) {
217- BlobInfo updatedInfo = info .toBuilder ().bucket ( targetBucket ). name ( targetBlob ).build ();
235+ BlobInfo updatedInfo = info .toBuilder ().blobId ( BlobId . of ( targetBucket , targetBlob ) ).build ();
218236 CopyRequest copyRequest =
219237 CopyRequest .builder ().source (info .bucket (), info .name ())
220238 .sourceOptions (convert (info , options )).target (updatedInfo ).build ();
@@ -270,18 +288,18 @@ public Storage storage() {
270288 * {@code infos.length > 1} a batch request is used to fetch blobs.
271289 *
272290 * @param storage the storage service used to issue the request
273- * @param infos the blobs to get
291+ * @param blobs the blobs to get
274292 * @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has
275293 * been denied the corresponding item in the list is {@code null}.
276294 * @throws StorageException upon failure
277295 */
278- public static List <Blob > get (final Storage storage , BlobInfo ... infos ) {
296+ public static List <Blob > get (final Storage storage , BlobId ... blobs ) {
279297 checkNotNull (storage );
280- checkNotNull (infos );
281- if (infos .length == 0 ) {
298+ checkNotNull (blobs );
299+ if (blobs .length == 0 ) {
282300 return Collections .emptyList ();
283301 }
284- return Collections .unmodifiableList (Lists .transform (storage .get (infos ),
302+ return Collections .unmodifiableList (Lists .transform (storage .get (blobs ),
285303 new Function <BlobInfo , Blob >() {
286304 @ Override
287305 public Blob apply (BlobInfo f ) {
@@ -320,18 +338,18 @@ public Blob apply(BlobInfo f) {
320338 * {@code infos.length > 1} a batch request is used to delete blobs.
321339 *
322340 * @param storage the storage service used to issue the request
323- * @param infos the blobs to delete
341+ * @param blobs the blobs to delete
324342 * @return an immutable list of booleans. If a blob has been deleted the corresponding item in the
325343 * list is {@code true}. If deletion failed or access to the resource was denied the item is
326344 * {@code false}.
327345 * @throws StorageException upon failure
328346 */
329- public static List <Boolean > delete (Storage storage , BlobInfo ... infos ) {
347+ public static List <Boolean > delete (Storage storage , BlobId ... blobs ) {
330348 checkNotNull (storage );
331- checkNotNull (infos );
332- if (infos .length == 0 ) {
349+ checkNotNull (blobs );
350+ if (blobs .length == 0 ) {
333351 return Collections .emptyList ();
334352 }
335- return storage .delete (infos );
353+ return storage .delete (blobs );
336354 }
337355}
0 commit comments