Skip to content

Commit ac2921b

Browse files
committed
Rename setters/getters/builders for Storage classes to meet proto conventions
1 parent 9c81978 commit ac2921b

41 files changed

Lines changed: 3491 additions & 1235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ import com.google.cloud.storage.StorageOptions;
548548
549549
Storage storage = StorageOptions.defaultInstance().service();
550550
BlobId blobId = BlobId.of("bucket", "blob_name");
551-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
551+
BlobInfo blobInfo = BlobInfo.newBuiler(blobId).setContentType("text/plain").build();
552552
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
553553
```
554554
The second snippet shows how to update a Storage blob if it exists. Complete source code can be
@@ -569,7 +569,7 @@ Storage storage = StorageOptions.defaultInstance().service();
569569
BlobId blobId = BlobId.of("bucket", "blob_name");
570570
Blob blob = storage.get(blobId);
571571
if (blob != null) {
572-
byte[] prevContent = blob.content();
572+
byte[] prevContent = blob.getContent();
573573
System.out.println(new String(prevContent, UTF_8));
574574
WritableByteChannel channel = blob.writer();
575575
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/StorageExample.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import java.util.Arrays;
5555
import java.util.HashMap;
5656
import java.util.Iterator;
57-
import java.util.LinkedList;
5857
import java.util.List;
5958
import java.util.Map;
6059
import java.util.concurrent.TimeUnit;
@@ -182,9 +181,9 @@ private static class InfoAction extends BlobsAction {
182181
@Override
183182
public void run(Storage storage, BlobId... blobIds) {
184183
if (blobIds.length == 1) {
185-
if (blobIds[0].name().isEmpty()) {
184+
if (blobIds[0].getName().isEmpty()) {
186185
// get Bucket
187-
Bucket bucket = storage.get(blobIds[0].bucket());
186+
Bucket bucket = storage.get(blobIds[0].getBucket());
188187
if (bucket == null) {
189188
System.out.println("No such bucket");
190189
return;
@@ -229,7 +228,8 @@ public String params() {
229228
* If more than one blob is supplied a Batch operation would be used to delete all requested
230229
* blobs in a single RPC.
231230
*
232-
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/delete">Objects: delete</a>
231+
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/delete">
232+
* Objects: delete</a>
233233
*/
234234
private static class DeleteAction extends BlobsAction {
235235
@Override
@@ -296,7 +296,8 @@ public String params() {
296296
/**
297297
* This class demonstrates how to create a new Blob or to update its content.
298298
*
299-
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/insert">Objects: insert</a>
299+
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/insert">
300+
* Objects: insert</a>
300301
*/
301302
private static class UploadAction extends StorageAction<Tuple<Path, BlobInfo>> {
302303
@Override
@@ -337,7 +338,7 @@ Tuple<Path, BlobInfo> parse(String... args) throws IOException {
337338
Path path = Paths.get(args[0]);
338339
String contentType = Files.probeContentType(path);
339340
String blob = args.length < 3 ? path.getFileName().toString() : args[2];
340-
return Tuple.of(path, BlobInfo.builder(args[1], blob).contentType(contentType).build());
341+
return Tuple.of(path, BlobInfo.newBuilder(args[1], blob).setContentType(contentType).build());
341342
}
342343

343344
@Override
@@ -370,9 +371,9 @@ private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOExcep
370371
if (downloadTo != null) {
371372
writeTo = new PrintStream(new FileOutputStream(downloadTo.toFile()));
372373
}
373-
if (blob.size() < 1_000_000) {
374+
if (blob.getSize() < 1_000_000) {
374375
// Blob is small read all its content in one request
375-
byte[] content = blob.content();
376+
byte[] content = blob.getContent();
376377
writeTo.write(content);
377378
} else {
378379
// When Blob size is big or unknown use the blob's channel reader.
@@ -425,7 +426,7 @@ private static class CopyAction extends StorageAction<CopyRequest> {
425426
@Override
426427
public void run(Storage storage, CopyRequest request) {
427428
CopyWriter copyWriter = storage.copy(request);
428-
System.out.printf("Copied %s%n", copyWriter.result());
429+
System.out.printf("Copied %s%n", copyWriter.getResult());
429430
}
430431

431432
@Override
@@ -445,7 +446,8 @@ public String params() {
445446
/**
446447
* This class demonstrates how to use the compose command.
447448
*
448-
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/compose">Objects: compose</a>
449+
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/compose">
450+
* Objects: compose</a>
449451
*/
450452
private static class ComposeAction extends StorageAction<ComposeRequest> {
451453
@Override
@@ -459,8 +461,8 @@ ComposeRequest parse(String... args) {
459461
if (args.length < 3) {
460462
throw new IllegalArgumentException();
461463
}
462-
ComposeRequest.Builder request = ComposeRequest.builder();
463-
request.target(BlobInfo.builder(args[0], args[args.length - 1]).build());
464+
ComposeRequest.Builder request = ComposeRequest.newBuilder();
465+
request.setTarget(BlobInfo.newBuilder(args[0], args[args.length - 1]).build());
464466
for (int i = 1; i < args.length - 1; i++) {
465467
request.addSource(args[i]);
466468
}
@@ -476,7 +478,8 @@ public String params() {
476478
/**
477479
* This class demonstrates how to update a blob's metadata.
478480
*
479-
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/update">Objects: update</a>
481+
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/objects/update">
482+
* Objects: update</a>
480483
*/
481484
private static class UpdateMetadataAction extends
482485
StorageAction<Tuple<BlobId, Map<String, String>>> {
@@ -493,7 +496,7 @@ private void run(Storage storage, BlobId blobId, Map<String, String> metadata) {
493496
System.out.println("No such object");
494497
return;
495498
}
496-
Blob updateBlob = blob.toBuilder().metadata(metadata).build().update();
499+
Blob updateBlob = blob.toBuilder().setMetadata(metadata).build().update();
497500
System.out.printf("Updated %s%n", updateBlob);
498501
}
499502

@@ -539,7 +542,7 @@ public void run(Storage storage, Tuple<ServiceAccountAuthCredentials, BlobInfo>
539542
}
540543

541544
private void run(Storage storage, ServiceAccountAuthCredentials cred, BlobInfo blobInfo) {
542-
Blob blob = storage.get(blobInfo.blobId());
545+
Blob blob = storage.get(blobInfo.getBlobId());
543546
System.out.printf("Signed URL: %s%n",
544547
blob.signUrl(1, TimeUnit.DAYS, SignUrlOption.signWith(cred)));
545548
}
@@ -555,7 +558,7 @@ Tuple<ServiceAccountAuthCredentials, BlobInfo> parse(String... args) throws IOEx
555558
keystore.load(Files.newInputStream(Paths.get(args[0])), PASSWORD);
556559
PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", PASSWORD);
557560
ServiceAccountAuthCredentials cred = AuthCredentials.createFor(args[1], privateKey);
558-
return Tuple.of(cred, BlobInfo.builder(BlobId.of(args[2], args[3])).build());
561+
return Tuple.of(cred, BlobInfo.newBuilder(BlobId.of(args[2], args[3])).build());
559562
}
560563

561564
@Override
@@ -576,14 +579,14 @@ private abstract static class AclAction extends StorageAction<Tuple<BlobId, Acl>
576579
public void run(Storage storage, Tuple<BlobId, Acl> params) {
577580
BlobId blobId = params.x();
578581
Acl acl = params.y();
579-
if (blobId.name().isEmpty()) {
580-
Bucket bucket = storage.get(blobId.bucket());
582+
if (blobId.getName().isEmpty()) {
583+
Bucket bucket = storage.get(blobId.getBucket());
581584
if (bucket == null) {
582-
System.out.printf("Bucket %s does not exist%n", blobId.bucket());
585+
System.out.printf("Bucket %s does not exist%n", blobId.getBucket());
583586
return;
584587
}
585588
acl = bucket.createAcl(acl);
586-
System.out.printf("Added ACL %s to bucket %s%n", acl, blobId.bucket());
589+
System.out.printf("Added ACL %s to bucket %s%n", acl, blobId.getBucket());
587590
} else {
588591
Blob blob = storage.get(blobId);
589592
if (blob == null) {

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public boolean exists() {
7777
* Example of reading all bytes of the blob, if its generation matches the
7878
* {@link Blob#generation()} value, otherwise a {@link StorageException} is thrown.
7979
*/
80-
// [TARGET content(BlobSourceOption...)]
81-
public byte[] content() {
82-
// [START content]
83-
byte[] content = blob.content(BlobSourceOption.generationMatch());
84-
// [END content]
80+
// [TARGET getContent(BlobSourceOption...)]
81+
public byte[] getContent() {
82+
// [START getContent]
83+
byte[] content = blob.getContent(BlobSourceOption.generationMatch());
84+
// [END getContent]
8585
return content;
8686
}
8787

@@ -108,8 +108,8 @@ public Blob update() {
108108
// [START update]
109109
Map<String, String> newMetadata = new HashMap<>();
110110
newMetadata.put("key", "value");
111-
blob.toBuilder().metadata(null).build().update();
112-
Blob updatedBlob = blob.toBuilder().metadata(newMetadata).build().update();
111+
blob.toBuilder().setMetadata(null).build().update();
112+
Blob updatedBlob = blob.toBuilder().setMetadata(newMetadata).build().update();
113113
// [END update]
114114
return updatedBlob;
115115
}
@@ -140,7 +140,7 @@ public boolean delete() {
140140
public Blob copyToId(String bucketName, String blobName) {
141141
// [START copyToId]
142142
CopyWriter copyWriter = blob.copyTo(BlobId.of(bucketName, blobName));
143-
Blob copiedBlob = copyWriter.result();
143+
Blob copiedBlob = copyWriter.getResult();
144144
// [END copyToId]
145145
return copiedBlob;
146146
}
@@ -153,7 +153,7 @@ public Blob copyToId(String bucketName, String blobName) {
153153
public Blob copyToBucket(String bucketName) {
154154
// [START copyToBucket]
155155
CopyWriter copyWriter = blob.copyTo(bucketName);
156-
Blob copiedBlob = copyWriter.result();
156+
Blob copiedBlob = copyWriter.getResult();
157157
// [END copyToBucket]
158158
return copiedBlob;
159159
}
@@ -167,7 +167,7 @@ public Blob copyToBucket(String bucketName) {
167167
public Blob copyToStrings(String bucketName, String blobName) {
168168
// [START copyToStrings]
169169
CopyWriter copyWriter = blob.copyTo(bucketName, blobName);
170-
Blob copiedBlob = copyWriter.result();
170+
Blob copiedBlob = copyWriter.getResult();
171171
// [END copyToStrings]
172172
return copiedBlob;
173173
}

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/BucketSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Bucket reload() {
8787
// [TARGET update(BucketTargetOption...)]
8888
public Bucket update() {
8989
// [START update]
90-
Bucket updatedBucket = bucket.toBuilder().versioningEnabled(true).build().update();
90+
Bucket updatedBucket = bucket.toBuilder().setVersioningEnabled(true).build().update();
9191
// [END update]
9292
return updatedBucket;
9393
}

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateAndListBucketsAndBlobs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String... args) {
5151
Blob blob = bucket.create("my_blob_name", "a simple blob".getBytes(UTF_8), "text/plain");
5252

5353
// Read the blob content from the server
54-
String blobContent = new String(blob.content(), UTF_8);
54+
String blobContent = new String(blob.getContent(), UTF_8);
5555

5656
// List all your buckets
5757
Iterator<Bucket> bucketIterator = storage.list().iterateAll();

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateBlob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CreateBlob {
3838
public static void main(String... args) {
3939
Storage storage = StorageOptions.defaultInstance().service();
4040
BlobId blobId = BlobId.of("bucket", "blob_name");
41-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
41+
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
4242
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
4343
}
4444
}

0 commit comments

Comments
 (0)