5252import java .security .UnrecoverableKeyException ;
5353import java .security .cert .CertificateException ;
5454import java .util .Arrays ;
55- import java .util .Calendar ;
5655import java .util .HashMap ;
5756import java .util .Map ;
5857import java .util .concurrent .TimeUnit ;
@@ -96,22 +95,6 @@ protected String params() {
9695 }
9796 }
9897
99- private static abstract class BlobAction extends StorageAction <Blob > {
100-
101- @ Override
102- Blob parse (Storage storage , String ... args ) {
103- if (args .length != 2 ) {
104- throw new IllegalArgumentException ();
105- }
106- return new Blob (storage , args [0 ], args [1 ]);
107- }
108-
109- @ Override
110- public String params () {
111- return "<bucket> <path>" ;
112- }
113- }
114-
11598 private static abstract class BlobsAction extends StorageAction <Blob []> {
11699
117100 @ Override
@@ -121,7 +104,7 @@ Blob[] parse(Storage storage, String... args) {
121104 }
122105 Blob [] blobs = new Blob [args .length - 1 ];
123106 for (int i = 1 ; i < args .length ; i ++) {
124- blobs [i - 1 ] = new Blob (storage , args [0 ], args [i ]);
107+ blobs [i - 1 ] = Blob . load (storage , args [0 ], args [i ]);
125108 }
126109 return blobs ;
127110 }
@@ -145,11 +128,11 @@ public void run(Storage storage, Blob... blobs) {
145128 if (blobs .length == 1 ) {
146129 if (blobs [0 ].info ().name ().isEmpty ()) {
147130 // get Bucket
148- Bucket bucket = new Bucket (storage , blobs [0 ].info ().bucket ());
149- System .out .println ("Bucket info: " + bucket .reload (). info ());
131+ Bucket bucket = Bucket . load (storage , blobs [0 ].info ().bucket ());
132+ System .out .println ("Bucket info: " + bucket .info ());
150133 } else {
151134 // get Blob
152- System .out .println ("Blob info: " + blobs [0 ].reload (). info ());
135+ System .out .println ("Blob info: " + blobs [0 ].info ());
153136 }
154137 } else {
155138 // use batch to get multiple blobs.
@@ -167,7 +150,7 @@ public void run(Storage storage, Blob... blobs) {
167150 @ Override
168151 Blob [] parse (Storage storage , String ... args ) {
169152 if (args .length < 2 ) {
170- return new Blob [] {new Blob (storage , args [0 ], "" )};
153+ return new Blob [] {new Blob (storage , BlobInfo . builder ( args [0 ], "" ). build () )};
171154 }
172155 return super .parse (storage , args );
173156 }
@@ -239,7 +222,7 @@ public void run(Storage storage, String bucketName) {
239222 }
240223 } else {
241224 // list a bucket's blobs
242- Bucket bucket = new Bucket (storage , bucketName );
225+ Bucket bucket = Bucket . load (storage , bucketName );
243226 for (Blob b : bucket .list ()) {
244227 System .out .println (b .info ());
245228 }
@@ -321,7 +304,6 @@ public void run(Storage storage, Tuple<Blob, Path> tuple) throws IOException {
321304 }
322305
323306 private void run (Storage storage , Blob blob , Path downloadTo ) throws IOException {
324- blob = blob .reload ();
325307 if (!blob .exists ()) {
326308 System .out .println ("No such object" );
327309 return ;
@@ -367,7 +349,7 @@ Tuple<Blob, Path> parse(Storage storage, String... args) {
367349 } else {
368350 path = null ;
369351 }
370- return Tuple .of (new Blob (storage , args [0 ], args [1 ]), path );
352+ return Tuple .of (Blob . load (storage , args [0 ], args [1 ]), path );
371353 }
372354
373355 @ Override
@@ -448,7 +430,6 @@ public void run(Storage storage, Tuple<Blob, Map<String, String>> tuple)
448430 }
449431
450432 private void run (Storage storage , Blob blob , Map <String , String > metadata ) {
451- blob = blob .reload ();
452433 if (!blob .exists ()) {
453434 System .out .println ("No such object" );
454435 return ;
@@ -462,7 +443,7 @@ Tuple<Blob, Map<String, String>> parse(Storage storage, String... args) {
462443 if (args .length < 2 ) {
463444 throw new IllegalArgumentException ();
464445 }
465- Blob blob = new Blob (storage , args [0 ], args [1 ]);
446+ Blob blob = Blob . load (storage , args [0 ], args [1 ]);
466447 Map <String , String > metadata = new HashMap <>();
467448 for (int i = 2 ; i < args .length ; i ++) {
468449 int idx = args [i ].indexOf ('=' );
@@ -515,7 +496,7 @@ Tuple<ServiceAccountAuthCredentials, Blob> parse(Storage storage, String... args
515496 keystore .load (Files .newInputStream (Paths .get (args [0 ])), PASSWORD );
516497 PrivateKey privateKey = (PrivateKey ) keystore .getKey ("privatekey" , PASSWORD );
517498 ServiceAccountAuthCredentials cred = AuthCredentials .createFor (args [1 ], privateKey );
518- return Tuple .of (cred , new Blob (storage , args [2 ], args [3 ]));
499+ return Tuple .of (cred , Blob . load (storage , args [2 ], args [3 ]));
519500 }
520501
521502 @ Override
0 commit comments