Skip to content

Commit 8a1d549

Browse files
jmdobrytswast
authored andcommitted
Add Storage quickstart sample.
1 parent bb3f49e commit 8a1d549

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

bigquery/cloud-client/src/main/java/com/example/bigquery/QuickstartSample.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public class QuickstartSample {
2727
public static void main(String... args) throws Exception {
2828
// Instantiates a client
2929
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
30+
3031
// The name for the new dataset
3132
String datasetName = "my_new_dataset";
33+
34+
// Prepares a new dataset
3235
Dataset dataset = null;
3336
DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build();
34-
// Creates the new dataset
37+
38+
// Creates the dataset
3539
dataset = bigquery.create(datasetInfo);
40+
3641
System.out.printf("Dataset %s created.%n", dataset.datasetId().dataset());
3742
}
3843
}

datastore/cloud-client/src/main/java/com/example/datastore/QuickstartSample.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ public class QuickstartSample {
2727
public static void main(String... args) throws Exception {
2828
// Instantiates a client
2929
Datastore datastore = DatastoreOptions.defaultInstance().service();
30+
3031
// The kind for the new entity
3132
String kind = "Task";
3233
// The name/ID for the new entity
3334
String name = "sampletask1";
3435
// The Cloud Datastore key for the new entity
3536
Key taskKey = datastore.newKeyFactory().kind(kind).newKey(name);
37+
3638
// Prepares the new entity
3739
Entity task = Entity.builder(taskKey)
3840
.set("description", "Buy milk")
3941
.build();
42+
4043
// Saves the entity
4144
datastore.put(task);
45+
4246
System.out.printf("Saved %s: %s%n", task.key().name(), task.getString("description"));
4347
}
4448
}

pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public class QuickstartSample {
2727
public static void main(String... args) throws Exception {
2828
// Instantiates a client
2929
PubSub pubsub = PubSubOptions.defaultInstance().service();
30+
3031
// The name for the new topic
3132
String topicName = "my-new-topic";
33+
3234
// Creates the new topic
3335
Topic topic = pubsub.create(TopicInfo.of(topicName));
36+
3437
System.out.printf("Topic %s created.%n", topic.name());
3538
}
3639
}

storage/cloud-client/pom.xml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!--
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<groupId>come.example.storage</groupId>
19+
<artifactId>storage-google-cloud-samples</artifactId>
20+
<packaging>jar</packaging>
21+
22+
<!-- Parent defines config for testing & linting. -->
23+
<parent>
24+
<artifactId>doc-samples</artifactId>
25+
<groupId>com.google.cloud</groupId>
26+
<version>1.0.0</version>
27+
<relativePath>../..</relativePath>
28+
</parent>
29+
30+
<properties>
31+
<maven.compiler.target>1.8</maven.compiler.target>
32+
<maven.compiler.source>1.8</maven.compiler.source>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.google.cloud</groupId>
39+
<artifactId>google-cloud-storage</artifactId>
40+
<version>0.4.0</version>
41+
</dependency>
42+
</dependencies>
43+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2016, Google, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.example.storage;
18+
19+
// [START storage_quickstart]
20+
// Imports the Google Cloud client library
21+
import com.google.cloud.storage.Storage;
22+
import com.google.cloud.storage.StorageOptions;
23+
import com.google.cloud.storage.Bucket;
24+
import com.google.cloud.storage.BucketInfo;
25+
26+
public class QuickstartSample {
27+
public static void main(String... args) throws Exception {
28+
// Instantiates a client
29+
Storage storage = StorageOptions.defaultInstance().service();
30+
31+
// The name for the new bucket
32+
String bucketName = "my-new-bucket";
33+
34+
// Creates the new bucket
35+
Bucket bucket = storage.create(BucketInfo.of(bucketName));
36+
37+
System.out.printf("Bucket %s created.%n", bucket.name());
38+
}
39+
}
40+
// [END storage_quickstart]

translate/cloud-client/src/main/java/com/example/translate/QuickstartSample.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ public class QuickstartSample {
2727
public static void main(String... args) throws Exception {
2828
// Instantiates a client
2929
Translate translate = TranslateOptions.builder().apiKey("YOUR_API_KEY").build().service();
30+
3031
// The text to translate
3132
String text = "Hello, world!";
33+
3234
// Translates some text into Russian
3335
Translation translation = translate.translate(
3436
text,
3537
TranslateOption.sourceLanguage("en"),
3638
TranslateOption.targetLanguage("ru")
3739
);
40+
3841
System.out.printf("Text: %s%n", text);
3942
System.out.printf("Translation: %s%n", translation.translatedText());
4043
}

0 commit comments

Comments
 (0)