25
25
import com .google .gcloud .storage .BlobId ;
26
26
import com .google .gcloud .storage .BlobInfo ;
27
27
import com .google .gcloud .storage .Bucket ;
28
- import com .google .gcloud .storage .BucketInfo ;
29
28
import com .google .gcloud .storage .CopyWriter ;
30
29
import com .google .gcloud .storage .Storage ;
31
30
import com .google .gcloud .storage .Storage .ComposeRequest ;
@@ -138,22 +137,22 @@ public void run(Storage storage, BlobId... blobIds) {
138
137
System .out .println ("No such bucket" );
139
138
return ;
140
139
}
141
- System .out .println ("Bucket info: " + bucket . info () );
140
+ System .out .println ("Bucket info: " + bucket );
142
141
} else {
143
142
// get Blob
144
- Blob blob = Blob .get (storage , blobIds [0 ]);
143
+ Blob blob = storage .get (blobIds [0 ]);
145
144
if (blob == null ) {
146
145
System .out .println ("No such object" );
147
146
return ;
148
147
}
149
- System .out .println ("Blob info: " + blob . info () );
148
+ System .out .println ("Blob info: " + blob );
150
149
}
151
150
} else {
152
151
// use batch to get multiple blobs.
153
- List <Blob > blobs = Blob .get (storage , Arrays . asList ( blobIds ) );
152
+ List <Blob > blobs = storage .get (blobIds );
154
153
for (Blob blob : blobs ) {
155
154
if (blob != null ) {
156
- System .out .println (blob . info () );
155
+ System .out .println (blob );
157
156
}
158
157
}
159
158
}
@@ -184,7 +183,7 @@ private static class DeleteAction extends BlobsAction {
184
183
@ Override
185
184
public void run (Storage storage , BlobId ... blobIds ) {
186
185
// use batch operation
187
- List <Boolean > deleteResults = Blob .delete (storage , blobIds );
186
+ List <Boolean > deleteResults = storage .delete (blobIds );
188
187
int index = 0 ;
189
188
for (Boolean deleted : deleteResults ) {
190
189
if (deleted ) {
@@ -218,9 +217,9 @@ String parse(String... args) {
218
217
public void run (Storage storage , String bucketName ) {
219
218
if (bucketName == null ) {
220
219
// 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 ());
224
223
}
225
224
} else {
226
225
// list a bucket's blobs
@@ -231,7 +230,7 @@ public void run(Storage storage, String bucketName) {
231
230
}
232
231
Iterator <Blob > blobIterator = bucket .list ().iterateAll ();
233
232
while (blobIterator .hasNext ()) {
234
- System .out .println (blobIterator .next (). info () );
233
+ System .out .println (blobIterator .next ());
235
234
}
236
235
}
237
236
}
@@ -257,8 +256,7 @@ private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOE
257
256
if (Files .size (uploadFrom ) > 1_000_000 ) {
258
257
// When content is not available or large (1MB or more) it is recommended
259
258
// 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 )) {
262
260
byte [] buffer = new byte [1024 ];
263
261
try (InputStream input = Files .newInputStream (uploadFrom )) {
264
262
int limit ;
@@ -311,7 +309,7 @@ public void run(Storage storage, Tuple<BlobId, Path> tuple) throws IOException {
311
309
}
312
310
313
311
private void run (Storage storage , BlobId blobId , Path downloadTo ) throws IOException {
314
- Blob blob = Blob .get (storage , blobId );
312
+ Blob blob = storage .get (blobId );
315
313
if (blob == null ) {
316
314
System .out .println ("No such object" );
317
315
return ;
@@ -320,7 +318,7 @@ private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOExcep
320
318
if (downloadTo != null ) {
321
319
writeTo = new PrintStream (new FileOutputStream (downloadTo .toFile ()));
322
320
}
323
- if (blob .info (). size () < 1_000_000 ) {
321
+ if (blob .size () < 1_000_000 ) {
324
322
// Blob is small read all its content in one request
325
323
byte [] content = blob .content ();
326
324
writeTo .write (content );
@@ -438,13 +436,13 @@ public void run(Storage storage, Tuple<BlobId, Map<String, String>> tuple)
438
436
}
439
437
440
438
private void run (Storage storage , BlobId blobId , Map <String , String > metadata ) {
441
- Blob blob = Blob .get (storage , blobId );
439
+ Blob blob = storage .get (blobId );
442
440
if (blob == null ) {
443
441
System .out .println ("No such object" );
444
442
return ;
445
443
}
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 );
448
446
}
449
447
450
448
@ Override
@@ -488,9 +486,8 @@ public void run(Storage storage, Tuple<ServiceAccountAuthCredentials, BlobInfo>
488
486
run (storage , tuple .x (), tuple .y ());
489
487
}
490
488
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 ());
494
491
System .out .println ("Signed URL: "
495
492
+ blob .signUrl (1 , TimeUnit .DAYS , SignUrlOption .serviceAccount (cred )));
496
493
}
0 commit comments