2323import com .google .gcloud .spi .StorageRpc .Tuple ;
2424import com .google .gcloud .storage .Blob ;
2525import com .google .gcloud .storage .BlobId ;
26- import com .google .gcloud .storage .BlobInfo ;
2726import com .google .gcloud .storage .Bucket ;
28- import com .google .gcloud .storage .BucketInfo ;
2927import com .google .gcloud .storage .CopyWriter ;
3028import com .google .gcloud .storage .Storage ;
3129import com .google .gcloud .storage .Storage .ComposeRequest ;
@@ -93,7 +91,7 @@ private abstract static class StorageAction<T> {
9391
9492 abstract void run (Storage storage , T request ) throws Exception ;
9593
96- abstract T parse (String ... args ) throws Exception ;
94+ abstract T parse (Storage storage , String ... args ) throws Exception ;
9795
9896 protected String params () {
9997 return "" ;
@@ -103,7 +101,7 @@ protected String params() {
103101 private abstract static class BlobsAction extends StorageAction <BlobId []> {
104102
105103 @ Override
106- BlobId [] parse (String ... args ) {
104+ BlobId [] parse (Storage storage , String ... args ) {
107105 if (args .length < 2 ) {
108106 throw new IllegalArgumentException ();
109107 }
@@ -138,33 +136,33 @@ public void run(Storage storage, BlobId... blobIds) {
138136 System .out .println ("No such bucket" );
139137 return ;
140138 }
141- System .out .println ("Bucket info: " + bucket . info () );
139+ System .out .println ("Bucket info: " + bucket );
142140 } else {
143141 // get Blob
144142 Blob blob = Blob .get (storage , blobIds [0 ]);
145143 if (blob == null ) {
146144 System .out .println ("No such object" );
147145 return ;
148146 }
149- System .out .println ("Blob info: " + blob . info () );
147+ System .out .println ("Blob info: " + blob );
150148 }
151149 } else {
152150 // use batch to get multiple blobs.
153151 List <Blob > blobs = Blob .get (storage , Arrays .asList (blobIds ));
154152 for (Blob blob : blobs ) {
155153 if (blob != null ) {
156- System .out .println (blob . info () );
154+ System .out .println (blob );
157155 }
158156 }
159157 }
160158 }
161159
162160 @ Override
163- BlobId [] parse (String ... args ) {
161+ BlobId [] parse (Storage storage , String ... args ) {
164162 if (args .length < 2 ) {
165163 return new BlobId [] {BlobId .of (args [0 ], "" )};
166164 }
167- return super .parse (args );
165+ return super .parse (storage , args );
168166 }
169167
170168 @ Override
@@ -204,7 +202,7 @@ public void run(Storage storage, BlobId... blobIds) {
204202 private static class ListAction extends StorageAction <String > {
205203
206204 @ Override
207- String parse (String ... args ) {
205+ String parse (Storage storage , String ... args ) {
208206 if (args .length == 0 ) {
209207 return null ;
210208 }
@@ -218,9 +216,9 @@ String parse(String... args) {
218216 public void run (Storage storage , String bucketName ) {
219217 if (bucketName == null ) {
220218 // list buckets
221- Iterator <BucketInfo > bucketInfoIterator = storage .list ().iterateAll ();
222- while (bucketInfoIterator .hasNext ()) {
223- System .out .println (bucketInfoIterator .next ());
219+ Iterator <Bucket > bucketIterator = storage .list ().iterateAll ();
220+ while (bucketIterator .hasNext ()) {
221+ System .out .println (bucketIterator .next ());
224222 }
225223 } else {
226224 // list a bucket's blobs
@@ -231,7 +229,7 @@ public void run(Storage storage, String bucketName) {
231229 }
232230 Iterator <Blob > blobIterator = bucket .list ().iterateAll ();
233231 while (blobIterator .hasNext ()) {
234- System .out .println (blobIterator .next (). info () );
232+ System .out .println (blobIterator .next ());
235233 }
236234 }
237235 }
@@ -247,17 +245,16 @@ public String params() {
247245 *
248246 * @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/insert">Objects: insert</a>
249247 */
250- private static class UploadAction extends StorageAction <Tuple <Path , BlobInfo >> {
248+ private static class UploadAction extends StorageAction <Tuple <Path , Blob >> {
251249 @ Override
252- public void run (Storage storage , Tuple <Path , BlobInfo > tuple ) throws Exception {
250+ public void run (Storage storage , Tuple <Path , Blob > tuple ) throws Exception {
253251 run (storage , tuple .x (), tuple .y ());
254252 }
255253
256- private void run (Storage storage , Path uploadFrom , BlobInfo blobInfo ) throws IOException {
254+ private void run (Storage storage , Path uploadFrom , Blob blob ) throws IOException {
257255 if (Files .size (uploadFrom ) > 1_000_000 ) {
258256 // When content is not available or large (1MB or more) it is recommended
259257 // to write it in chunks via the blob's channel writer.
260- Blob blob = new Blob (storage , blobInfo );
261258 try (WriteChannel writer = blob .writer ()) {
262259 byte [] buffer = new byte [1024 ];
263260 try (InputStream input = Files .newInputStream (uploadFrom )) {
@@ -274,20 +271,20 @@ private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOE
274271 } else {
275272 byte [] bytes = Files .readAllBytes (uploadFrom );
276273 // create the blob in one request.
277- storage .create (blobInfo , bytes );
274+ storage .create (blob , bytes );
278275 }
279276 System .out .println ("Blob was created" );
280277 }
281278
282279 @ Override
283- Tuple <Path , BlobInfo > parse (String ... args ) throws IOException {
280+ Tuple <Path , Blob > parse (Storage storage , String ... args ) throws IOException {
284281 if (args .length < 2 || args .length > 3 ) {
285282 throw new IllegalArgumentException ();
286283 }
287284 Path path = Paths .get (args [0 ]);
288285 String contentType = Files .probeContentType (path );
289286 String blob = args .length < 3 ? path .getFileName ().toString () : args [2 ];
290- return Tuple .of (path , BlobInfo .builder (args [1 ], blob ).contentType (contentType ).build ());
287+ return Tuple .of (path , Blob .builder (storage , args [1 ], blob ).contentType (contentType ).build ());
291288 }
292289
293290 @ Override
@@ -320,7 +317,7 @@ private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOExcep
320317 if (downloadTo != null ) {
321318 writeTo = new PrintStream (new FileOutputStream (downloadTo .toFile ()));
322319 }
323- if (blob .info (). size () < 1_000_000 ) {
320+ if (blob .size () < 1_000_000 ) {
324321 // Blob is small read all its content in one request
325322 byte [] content = blob .content ();
326323 writeTo .write (content );
@@ -344,7 +341,7 @@ private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOExcep
344341 }
345342
346343 @ Override
347- Tuple <BlobId , Path > parse (String ... args ) {
344+ Tuple <BlobId , Path > parse (Storage storage , String ... args ) {
348345 if (args .length < 2 || args .length > 3 ) {
349346 throw new IllegalArgumentException ();
350347 }
@@ -379,11 +376,11 @@ public void run(Storage storage, CopyRequest request) {
379376 }
380377
381378 @ Override
382- CopyRequest parse (String ... args ) {
379+ CopyRequest parse (Storage storage , String ... args ) {
383380 if (args .length != 4 ) {
384381 throw new IllegalArgumentException ();
385382 }
386- return CopyRequest .of (args [0 ], args [1 ], BlobId .of (args [2 ], args [3 ]));
383+ return CopyRequest .of (storage , args [0 ], args [1 ], BlobId .of (args [2 ], args [3 ]));
387384 }
388385
389386 @ Override
@@ -400,17 +397,17 @@ public String params() {
400397 private static class ComposeAction extends StorageAction <ComposeRequest > {
401398 @ Override
402399 public void run (Storage storage , ComposeRequest request ) {
403- BlobInfo composedBlobInfo = storage .compose (request );
404- System .out .println ("Composed " + composedBlobInfo );
400+ Blob composedBlob = storage .compose (request );
401+ System .out .println ("Composed " + composedBlob );
405402 }
406403
407404 @ Override
408- ComposeRequest parse (String ... args ) {
405+ ComposeRequest parse (Storage storage , String ... args ) {
409406 if (args .length < 3 ) {
410407 throw new IllegalArgumentException ();
411408 }
412409 ComposeRequest .Builder request = ComposeRequest .builder ();
413- request .target (BlobInfo .builder (args [0 ], args [args .length - 1 ]).build ());
410+ request .target (Blob .builder (storage , args [0 ], args [args .length - 1 ]).build ());
414411 for (int i = 1 ; i < args .length - 1 ; i ++) {
415412 request .addSource (args [i ]);
416413 }
@@ -443,12 +440,12 @@ private void run(Storage storage, BlobId blobId, Map<String, String> metadata) {
443440 System .out .println ("No such object" );
444441 return ;
445442 }
446- Blob updateBlob = blob .update (blob .info (). toBuilder ().metadata (metadata ).build ());
447- System .out .println ("Updated " + updateBlob . info () );
443+ Blob updateBlob = blob .update (blob .toBuilder ().metadata (metadata ).build ());
444+ System .out .println ("Updated " + updateBlob );
448445 }
449446
450447 @ Override
451- Tuple <BlobId , Map <String , String >> parse (String ... args ) {
448+ Tuple <BlobId , Map <String , String >> parse (Storage storage , String ... args ) {
452449 if (args .length < 2 ) {
453450 throw new IllegalArgumentException ();
454451 }
@@ -478,25 +475,25 @@ public String params() {
478475 * @see <a href="https://cloud.google.com/storage/docs/access-control#Signed-URLs">Signed URLs</a>
479476 */
480477 private static class SignUrlAction extends
481- StorageAction <Tuple <ServiceAccountAuthCredentials , BlobInfo >> {
478+ StorageAction <Tuple <ServiceAccountAuthCredentials , Blob >> {
482479
483480 private static final char [] PASSWORD = "notasecret" .toCharArray ();
484481
485482 @ Override
486- public void run (Storage storage , Tuple <ServiceAccountAuthCredentials , BlobInfo > tuple )
483+ public void run (Storage storage , Tuple <ServiceAccountAuthCredentials , Blob > tuple )
487484 throws Exception {
488485 run (storage , tuple .x (), tuple .y ());
489486 }
490487
491- private void run (Storage storage , ServiceAccountAuthCredentials cred , BlobInfo blobInfo )
488+ private void run (Storage storage , ServiceAccountAuthCredentials cred , Blob blob )
492489 throws IOException {
493- Blob blob = new Blob (storage , blobInfo );
494490 System .out .println ("Signed URL: "
495491 + blob .signUrl (1 , TimeUnit .DAYS , SignUrlOption .serviceAccount (cred )));
496492 }
497493
498494 @ Override
499- Tuple <ServiceAccountAuthCredentials , BlobInfo > parse (String ... args ) throws IOException ,
495+ Tuple <ServiceAccountAuthCredentials , Blob > parse (Storage storage , String ... args )
496+ throws IOException ,
500497 KeyStoreException , CertificateException , NoSuchAlgorithmException ,
501498 UnrecoverableKeyException {
502499 if (args .length != 4 ) {
@@ -506,7 +503,7 @@ Tuple<ServiceAccountAuthCredentials, BlobInfo> parse(String... args) throws IOEx
506503 keystore .load (Files .newInputStream (Paths .get (args [0 ])), PASSWORD );
507504 PrivateKey privateKey = (PrivateKey ) keystore .getKey ("privatekey" , PASSWORD );
508505 ServiceAccountAuthCredentials cred = AuthCredentials .createFor (args [1 ], privateKey );
509- return Tuple .of (cred , BlobInfo .builder (BlobId .of (args [2 ], args [3 ])).build ());
506+ return Tuple .of (cred , Blob .builder (storage , BlobId .of (args [2 ], args [3 ])).build ());
510507 }
511508
512509 @ Override
@@ -569,7 +566,7 @@ public static void main(String... args) throws Exception {
569566 Storage storage = optionsBuilder .build ().service ();
570567 Object request ;
571568 try {
572- request = action .parse (args );
569+ request = action .parse (storage , args );
573570 } catch (IllegalArgumentException ex ) {
574571 System .out .println ("Invalid input for action '" + actionName + "'" );
575572 System .out .println ("Expected: " + action .params ());
0 commit comments