@@ -40,16 +40,16 @@ If you are using Maven, add this to your pom.xml file
40
40
<dependency >
41
41
<groupId >com.google.cloud</groupId >
42
42
<artifactId >google-cloud</artifactId >
43
- <version >0.3 .0</version >
43
+ <version >0.4 .0</version >
44
44
</dependency >
45
45
```
46
46
If you are using Gradle, add this to your dependencies
47
47
``` Groovy
48
- compile 'com.google.cloud:google-cloud:0.3 .0'
48
+ compile 'com.google.cloud:google-cloud:0.4 .0'
49
49
```
50
50
If you are using SBT, add this to your dependencies
51
51
``` Scala
52
- libraryDependencies += " com.google.cloud" % " google-cloud" % " 0.3 .0"
52
+ libraryDependencies += " com.google.cloud" % " google-cloud" % " 0.4 .0"
53
53
```
54
54
55
55
Example Applications
@@ -186,7 +186,7 @@ if (table == null) {
186
186
System.out.println(" Loading data into table " + tableId);
187
187
Job loadJob = table.load(FormatOptions.csv (), " gs://bucket/path" );
188
188
loadJob = loadJob.waitFor ();
189
- if (loadJob.status ().error () ! = null) {
189
+ if (loadJob.getStatus ().getError () ! = null) {
190
190
System.out.println(" Job completed with errors" );
191
191
} else {
192
192
System.out.println(" Job succeeded" );
@@ -222,7 +222,7 @@ if (disk != null) {
222
222
String snapshotName = " disk-name-snapshot" ;
223
223
Operation operation = disk.createSnapshot(snapshotName);
224
224
operation = operation.waitFor ();
225
- if (operation.errors () == null) {
225
+ if (operation.getErrors () == null) {
226
226
// use snapshot
227
227
Snapshot snapshot = compute.getSnapshot(snapshotName);
228
228
}
@@ -252,7 +252,7 @@ MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1")
252
252
Operation operation =
253
253
compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface));
254
254
operation = operation.waitFor ();
255
- if (operation.errors () == null) {
255
+ if (operation.getErrors () == null) {
256
256
// use instance
257
257
Instance instance = compute.getInstance(instanceId);
258
258
}
@@ -282,9 +282,9 @@ import com.google.cloud.datastore.Key;
282
282
import com.google.cloud.datastore.KeyFactory;
283
283
284
284
Datastore datastore = DatastoreOptions.defaultInstance().service ();
285
- KeyFactory keyFactory = datastore.newKeyFactory ().kind (" keyKind" );
285
+ KeyFactory keyFactory = datastore.newKeyFactory ().setKind (" keyKind" );
286
286
Key key = keyFactory.newKey(" keyName" );
287
- Entity entity = Entity.builder (key)
287
+ Entity entity = Entity.newBuilder (key)
288
288
.set(" name" , " John Doe" )
289
289
.set(" age" , 30)
290
290
.set(" access_time" , DateTime.now ())
@@ -303,12 +303,12 @@ import com.google.cloud.datastore.Key;
303
303
import com.google.cloud.datastore.KeyFactory;
304
304
305
305
Datastore datastore = DatastoreOptions.defaultInstance().service ();
306
- KeyFactory keyFactory = datastore.newKeyFactory ().kind (" keyKind" );
306
+ KeyFactory keyFactory = datastore.newKeyFactory ().setKind (" keyKind" );
307
307
Key key = keyFactory.newKey(" keyName" );
308
308
Entity entity = datastore.get(key);
309
309
if (entity ! = null) {
310
310
System.out.println(" Updating access_time for " + entity.getString(" name" ));
311
- entity = Entity.builder (entity)
311
+ entity = Entity.newBuilder (entity)
312
312
.set(" access_time" , DateTime.now ())
313
313
.build ();
314
314
datastore.update(entity);
@@ -359,19 +359,19 @@ Dns dns = DnsOptions.defaultInstance().service();
359
359
String zoneName = " my-unique-zone" ;
360
360
Zone zone = dns.getZone(zoneName);
361
361
String ip = " 12.13.14.15" ;
362
- RecordSet toCreate = RecordSet.builder (" www.someexampledomain.com." , RecordSet.Type.A)
363
- .ttl (24, TimeUnit.HOURS)
362
+ RecordSet toCreate = RecordSet.newBuilder (" www.someexampledomain.com." , RecordSet.Type.A)
363
+ .setTtl (24, TimeUnit.HOURS)
364
364
.addRecord(ip)
365
365
.build ();
366
- ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.builder ().add(toCreate);
366
+ ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.newBuilder ().add(toCreate);
367
367
368
368
// Verify that the record does not exist yet.
369
369
// If it does exist, we will overwrite it with our prepared record.
370
370
Iterator< RecordSet> recordSetIterator = zone.listRecordSets().iterateAll ();
371
371
while (recordSetIterator.hasNext()) {
372
372
RecordSet current = recordSetIterator.next ();
373
- if (toCreate.name().equals(current.name ()) &&
374
- toCreate.type().equals(current.type ())) {
373
+ if (toCreate.name().equals(current.getName ()) &&
374
+ toCreate.type().equals(current.getType ())) {
375
375
changeBuilder.delete(current);
376
376
}
377
377
}
@@ -412,9 +412,9 @@ import java.util.Iterator;
412
412
LoggingOptions options = LoggingOptions.defaultInstance ();
413
413
try(Logging logging = options.service ()) {
414
414
415
- LogEntry firstEntry = LogEntry.builder (StringPayload.of(" message" ))
416
- .logName (" test-log" )
417
- .resource (MonitoredResource.builder(" global" )
415
+ LogEntry firstEntry = LogEntry.newBuilder (StringPayload.of(" message" ))
416
+ .setLogName (" test-log" )
417
+ .setResource (MonitoredResource.builder(" global" )
418
418
.addLabel(" project_id" , options.projectId ())
419
419
.build ())
420
420
.build ();
@@ -477,7 +477,7 @@ try (PubSub pubsub = PubSubOptions.defaultInstance().service()) {
477
477
MessageProcessor callback = new MessageProcessor () {
478
478
@Override
479
479
public void process(Message message) throws Exception {
480
- System.out.printf(" Received message \" %s\" %n" , message.payloadAsString ());
480
+ System.out.printf(" Received message \" %s\" %n" , message.getPayloadAsString ());
481
481
}
482
482
};
483
483
// Create a message consumer and pull messages (for 60 seconds)
@@ -512,13 +512,13 @@ if (project != null) {
512
512
.addLabel("launch-status", "in-development")
513
513
.build()
514
514
.replace();
515
- System.out.println("Updated the labels of project " + newProject.projectId ()
516
- + " to be " + newProject.labels ());
515
+ System.out.println("Updated the labels of project " + newProject.getProjectId ()
516
+ + " to be " + newProject.getLabels ());
517
517
}
518
518
Iterator<Project> projectIterator = resourceManager.list().iterateAll();
519
519
System.out.println("Projects I can view:");
520
520
while (projectIterator.hasNext()) {
521
- System.out.println(projectIterator.next().projectId ());
521
+ System.out.println(projectIterator.next().getProjectId ());
522
522
}
523
523
```
524
524
@@ -548,7 +548,7 @@ import com.google.cloud.storage.StorageOptions;
548
548
549
549
Storage storage = StorageOptions.defaultInstance().service();
550
550
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();
552
552
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
553
553
```
554
554
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();
569
569
BlobId blobId = BlobId.of("bucket", "blob_name");
570
570
Blob blob = storage.get(blobId);
571
571
if (blob != null) {
572
- byte[] prevContent = blob.content ();
572
+ byte[] prevContent = blob.getContent ();
573
573
System.out.println(new String(prevContent, UTF_8));
574
574
WritableByteChannel channel = blob.writer();
575
575
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
@@ -601,14 +601,14 @@ import com.google.cloud.translate.Translation;
601
601
Translate translate = TranslateOptions.defaultInstance().service ();
602
602
603
603
Detection detection = translate.detect(" Hola" );
604
- String detectedLanguage = detection.language ();
604
+ String detectedLanguage = detection.getLanguage ();
605
605
606
606
Translation translation = translate.translate(
607
607
" World" ,
608
608
TranslateOption.sourceLanguage(" en" ),
609
609
TranslateOption.targetLanguage(detectedLanguage));
610
610
611
- System.out.printf(" Hola %s%n" , translation.translatedText ());
611
+ System.out.printf(" Hola %s%n" , translation.getTranslatedText ());
612
612
` ` `
613
613
614
614
Troubleshooting
0 commit comments