2525import com .google .gcloud .storage .BlobId ;
2626import com .google .gcloud .storage .BlobInfo ;
2727import com .google .gcloud .storage .Bucket ;
28- import com .google .gcloud .storage .BucketInfo ;
2928import com .google .gcloud .storage .CopyWriter ;
3029import com .google .gcloud .storage .Storage ;
3130import com .google .gcloud .storage .Storage .ComposeRequest ;
@@ -133,27 +132,27 @@ public void run(Storage storage, BlobId... blobIds) {
133132 if (blobIds .length == 1 ) {
134133 if (blobIds [0 ].name ().isEmpty ()) {
135134 // get Bucket
136- Bucket bucket = Bucket .get (storage , blobIds [0 ].bucket ());
135+ Bucket bucket = storage .get (blobIds [0 ].bucket ());
137136 if (bucket == null ) {
138137 System .out .println ("No such bucket" );
139138 return ;
140139 }
141- System .out .println ("Bucket info: " + bucket . info () );
140+ System .out .println ("Bucket info: " + bucket );
142141 } else {
143142 // get Blob
144- Blob blob = Blob .get (storage , blobIds [0 ]);
143+ Blob blob = storage .get (blobIds [0 ]);
145144 if (blob == null ) {
146145 System .out .println ("No such object" );
147146 return ;
148147 }
149- System .out .println ("Blob info: " + blob . info () );
148+ System .out .println ("Blob info: " + blob );
150149 }
151150 } else {
152151 // use batch to get multiple blobs.
153- List <Blob > blobs = Blob .get (storage , Arrays . asList ( blobIds ) );
152+ List <Blob > blobs = storage .get (blobIds );
154153 for (Blob blob : blobs ) {
155154 if (blob != null ) {
156- System .out .println (blob . info () );
155+ System .out .println (blob );
157156 }
158157 }
159158 }
@@ -184,7 +183,7 @@ private static class DeleteAction extends BlobsAction {
184183 @ Override
185184 public void run (Storage storage , BlobId ... blobIds ) {
186185 // use batch operation
187- List <Boolean > deleteResults = Blob .delete (storage , blobIds );
186+ List <Boolean > deleteResults = storage .delete (blobIds );
188187 int index = 0 ;
189188 for (Boolean deleted : deleteResults ) {
190189 if (deleted ) {
@@ -218,20 +217,20 @@ String parse(String... args) {
218217 public void run (Storage storage , String bucketName ) {
219218 if (bucketName == null ) {
220219 // list buckets
221- Iterator <BucketInfo > bucketInfoIterator = storage .list ().iterateAll ();
222- while (bucketInfoIterator .hasNext ()) {
223- System .out .println (bucketInfoIterator .next ());
220+ Iterator <Bucket > bucketIterator = storage .list ().iterateAll ();
221+ while (bucketIterator .hasNext ()) {
222+ System .out .println (bucketIterator .next ());
224223 }
225224 } else {
226225 // list a bucket's blobs
227- Bucket bucket = Bucket .get (storage , bucketName );
226+ Bucket bucket = storage .get (bucketName );
228227 if (bucket == null ) {
229228 System .out .println ("No such bucket" );
230229 return ;
231230 }
232231 Iterator <Blob > blobIterator = bucket .list ().iterateAll ();
233232 while (blobIterator .hasNext ()) {
234- System .out .println (blobIterator .next (). info () );
233+ System .out .println (blobIterator .next ());
235234 }
236235 }
237236 }
@@ -257,8 +256,7 @@ private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOE
257256 if (Files .size (uploadFrom ) > 1_000_000 ) {
258257 // When content is not available or large (1MB or more) it is recommended
259258 // to write it in chunks via the blob's channel writer.
260- Blob blob = new Blob (storage , blobInfo );
261- try (WriteChannel writer = blob .writer ()) {
259+ try (WriteChannel writer = storage .writer (blobInfo )) {
262260 byte [] buffer = new byte [1024 ];
263261 try (InputStream input = Files .newInputStream (uploadFrom )) {
264262 int limit ;
@@ -311,7 +309,7 @@ public void run(Storage storage, Tuple<BlobId, Path> tuple) throws IOException {
311309 }
312310
313311 private void run (Storage storage , BlobId blobId , Path downloadTo ) throws IOException {
314- Blob blob = Blob .get (storage , blobId );
312+ Blob blob = storage .get (blobId );
315313 if (blob == null ) {
316314 System .out .println ("No such object" );
317315 return ;
@@ -320,7 +318,7 @@ private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOExcep
320318 if (downloadTo != null ) {
321319 writeTo = new PrintStream (new FileOutputStream (downloadTo .toFile ()));
322320 }
323- if (blob .info (). size () < 1_000_000 ) {
321+ if (blob .size () < 1_000_000 ) {
324322 // Blob is small read all its content in one request
325323 byte [] content = blob .content ();
326324 writeTo .write (content );
@@ -438,13 +436,13 @@ public void run(Storage storage, Tuple<BlobId, Map<String, String>> tuple)
438436 }
439437
440438 private void run (Storage storage , BlobId blobId , Map <String , String > metadata ) {
441- Blob blob = Blob .get (storage , blobId );
439+ Blob blob = storage .get (blobId );
442440 if (blob == null ) {
443441 System .out .println ("No such object" );
444442 return ;
445443 }
446- Blob updateBlob = blob .update ( blob . info (). toBuilder ().metadata (metadata ).build ());
447- System .out .println ("Updated " + updateBlob . info () );
444+ Blob updateBlob = blob .toBuilder ().metadata (metadata ).build (). update ( );
445+ System .out .println ("Updated " + updateBlob );
448446 }
449447
450448 @ Override
@@ -488,9 +486,8 @@ public void run(Storage storage, Tuple<ServiceAccountAuthCredentials, BlobInfo>
488486 run (storage , tuple .x (), tuple .y ());
489487 }
490488
491- private void run (Storage storage , ServiceAccountAuthCredentials cred , BlobInfo blobInfo )
492- throws IOException {
493- Blob blob = new Blob (storage , blobInfo );
489+ private void run (Storage storage , ServiceAccountAuthCredentials cred , BlobInfo blobInfo ) {
490+ Blob blob = storage .get (blobInfo .blobId ());
494491 System .out .println ("Signed URL: "
495492 + blob .signUrl (1 , TimeUnit .DAYS , SignUrlOption .serviceAccount (cred )));
496493 }
0 commit comments