2222import com .google .gcloud .spi .StorageRpc .Tuple ;
2323import com .google .gcloud .storage .BatchRequest ;
2424import com .google .gcloud .storage .BatchResponse ;
25+ import com .google .gcloud .storage .Blob ;
2526import com .google .gcloud .storage .BlobInfo ;
2627import com .google .gcloud .storage .BlobReadChannel ;
2728import com .google .gcloud .storage .BlobWriteChannel ;
29+ import com .google .gcloud .storage .Bucket ;
2830import com .google .gcloud .storage .BucketInfo ;
2931import com .google .gcloud .storage .Storage ;
3032import com .google .gcloud .storage .Storage .ComposeRequest ;
@@ -142,12 +144,12 @@ public void run(Storage storage, BlobInfo... blobInfos) {
142144 if (blobInfos .length == 1 ) {
143145 if (blobInfos [0 ].name ().isEmpty ()) {
144146 // get Bucket
145- BucketInfo bucketInfo = storage . get ( blobInfos [0 ].bucket ());
146- System .out .println ("Bucket info: " + bucketInfo );
147+ Bucket bucket = new Bucket ( storage , blobInfos [0 ].bucket ());
148+ System .out .println ("Bucket info: " + bucket . reload (). info () );
147149 } else {
148150 // get Blob
149- BlobInfo blobInfo = storage . get ( blobInfos [ 0 ]. bucket () , blobInfos [0 ]. name () );
150- System .out .println ("Blob info: " + blobInfo );
151+ Blob blob = new Blob ( storage , blobInfos [0 ]);
152+ System .out .println ("Blob info: " + blob . reload (). info () );
151153 }
152154 } else {
153155 // use batch to get multiple blobs.
@@ -187,7 +189,7 @@ private static class DeleteAction extends BlobsAction {
187189 @ Override
188190 public void run (Storage storage , BlobInfo ... blobInfos ) {
189191 if (blobInfos .length == 1 ) {
190- boolean wasDeleted = storage . delete ( blobInfos [ 0 ]. bucket () , blobInfos [0 ]. name () );
192+ boolean wasDeleted = new Blob ( storage , blobInfos [0 ]). delete ( );
191193 if (wasDeleted ) {
192194 System .out .println ("Blob " + blobInfos [0 ] + " was deleted" );
193195 }
@@ -237,8 +239,9 @@ public void run(Storage storage, String bucket) {
237239 }
238240 } else {
239241 // list a bucket's blobs
240- for (BlobInfo b : storage .list (bucket )) {
241- System .out .println (b );
242+ Bucket functionalBucket = new Bucket (storage , bucket );
243+ for (Blob b : functionalBucket .list ()) {
244+ System .out .println (b .info ());
242245 }
243246 }
244247 }
@@ -264,7 +267,8 @@ private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOE
264267 if (Files .size (uploadFrom ) > 1_000_000 ) {
265268 // When content is not available or large (1MB or more) it is recommended
266269 // to write it in chunks via the blob's channel writer.
267- try (BlobWriteChannel writer = storage .writer (blobInfo )) {
270+ Blob blob = new Blob (storage , blobInfo );
271+ try (BlobWriteChannel writer = blob .writer ()) {
268272 byte [] buffer = new byte [1024 ];
269273 try (InputStream input = Files .newInputStream (uploadFrom )) {
270274 int limit ;
@@ -318,8 +322,9 @@ public void run(Storage storage, Tuple<BlobInfo, Path> tuple) throws IOException
318322
319323 private void run (Storage storage , String bucket , String blobName , Path downloadTo )
320324 throws IOException {
325+ Blob blob = new Blob (storage , bucket , blobName );
321326 BlobInfo blobInfo = storage .get (bucket , blobName );
322- if (blobInfo == null ) {
327+ if (! blob . exists () ) {
323328 System .out .println ("No such object" );
324329 return ;
325330 }
@@ -329,11 +334,11 @@ private void run(Storage storage, String bucket, String blobName, Path downloadT
329334 }
330335 if (blobInfo .size () < 1_000_000 ) {
331336 // Blob is small read all its content in one request
332- byte [] content = storage . readAllBytes ( blobInfo . bucket (), blobInfo . name () );
337+ byte [] content = blob . content ( );
333338 writeTo .write (content );
334339 } else {
335340 // When Blob size is big or unknown use the blob's channel reader.
336- try (BlobReadChannel reader = storage .reader (blobInfo . bucket (), blobInfo . name () )) {
341+ try (BlobReadChannel reader = blob .reader ()) {
337342 WritableByteChannel channel = Channels .newChannel (writeTo );
338343 ByteBuffer bytes = ByteBuffer .allocate (64 * 1024 );
339344 while (reader .read (bytes ) > 0 ) {
@@ -435,7 +440,8 @@ public String params() {
435440 *
436441 * @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/update">Objects: update</a>
437442 */
438- private static class UpdateMetadataAction extends StorageAction <Tuple <BlobInfo , Map <String , String >>> {
443+ private static class UpdateMetadataAction extends
444+ StorageAction <Tuple <BlobInfo , Map <String , String >>> {
439445
440446 @ Override
441447 public void run (Storage storage , Tuple <BlobInfo , Map <String , String >> tuple )
@@ -445,13 +451,13 @@ public void run(Storage storage, Tuple<BlobInfo, Map<String, String>> tuple)
445451
446452 private void run (Storage storage , String bucket , String blobName ,
447453 Map <String , String > metadata ) {
448- BlobInfo blobInfo = storage . get ( bucket , blobName );
449- if (blobInfo == null ) {
454+ Blob blob = new Blob ( storage , bucket , blobName ). reload ( );
455+ if (! blob . exists () ) {
450456 System .out .println ("No such object" );
451457 return ;
452458 }
453- blobInfo = storage .update (blobInfo .toBuilder ().metadata (metadata ).build ());
454- System .out .println ("Updated " + blobInfo );
459+ Blob updateBlob = blob .update (blob . info () .toBuilder ().metadata (metadata ).build ());
460+ System .out .println ("Updated " + updateBlob . info () );
455461 }
456462
457463 @ Override
@@ -487,7 +493,7 @@ public String params() {
487493 private static class SignUrlAction extends
488494 StorageAction <Tuple <ServiceAccountAuthCredentials , BlobInfo >> {
489495
490- private static final char [] PASSWORD = "notasecret" .toCharArray ();
496+ private static final char [] PASSWORD = "notasecret" .toCharArray ();
491497
492498 @ Override
493499 public void run (Storage storage , Tuple <ServiceAccountAuthCredentials , BlobInfo > tuple )
@@ -501,7 +507,7 @@ private void run(Storage storage, ServiceAccountAuthCredentials cred, BlobInfo b
501507 cal .add (Calendar .DATE , 1 );
502508 long expiration = cal .getTimeInMillis () / 1000 ;
503509 System .out .println ("Signed URL: " +
504- storage .signUrl (blobInfo , expiration , SignUrlOption .serviceAccount (cred )));
510+ new Blob ( storage , blobInfo ) .signUrl (expiration , SignUrlOption .serviceAccount (cred )));
505511 }
506512
507513 @ Override
0 commit comments