Skip to content

Commit c4bdf80

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 2507 b: refs/heads/update-datastore c: 08c0f28 h: refs/heads/master i: 2505: 965012b 2503: fcfcefe
1 parent 2735828 commit c4bdf80

9 files changed

Lines changed: 156 additions & 143 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: a6da17ebd4241033fe309278db0851156b633985
8+
refs/heads/update-datastore: 08c0f28f6b05b77af79b042a0b56bdb21d2a2286
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2

branches/update-datastore/README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ Most `gcloud-java` libraries require a project ID. There are multiple ways to s
7575
Authentication
7676
--------------
7777

78-
First, ensure that the necessary Google Cloud APIs are enabled for your project. To do this, follow the instructions on the [authentication document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/authentication/readme.md#authentication) shared by all the gcloud language libraries.
79-
80-
Next, choose a method for authenticating API requests from within your project:
78+
There are multiple ways to authenticate to use Google Cloud services.
8179

8280
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
8381
2. When using `gcloud-java` libraries elsewhere, there are two options:
@@ -182,11 +180,6 @@ if (blob == null) {
182180
}
183181
```
184182
185-
Troubleshooting
186-
---------------
187-
188-
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
189-
190183
Java Versions
191184
-------------
192185
@@ -213,7 +206,7 @@ Contributing
213206
214207
Contributions to this library are always welcome and highly encouraged.
215208
216-
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
209+
See [CONTRIBUTING] for more information on how to get started.
217210
218211
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
219212
@@ -224,7 +217,7 @@ Apache 2.0 - See [LICENSE] for more information.
224217
225218
226219
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
227-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
220+
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md
228221
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
229222
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
230223
[cloud-platform]: https://cloud.google.com/

branches/update-datastore/gcloud-java-core/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ If you are using SBT, add this to your dependencies
2929
libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.12"
3030
```
3131

32-
Troubleshooting
33-
---------------
34-
35-
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
36-
3732
Java Versions
3833
-------------
3934

@@ -44,9 +39,7 @@ Contributing
4439

4540
Contributions to this library are always welcome and highly encouraged.
4641

47-
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
48-
49-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
42+
See [CONTRIBUTING] for more information on how to get started.
5043

5144
Versioning
5245
----------
@@ -64,6 +57,5 @@ Apache 2.0 - See [LICENSE] for more information.
6457

6558

6659
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
67-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
6860
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
6961
[cloud-platform]: https://cloud.google.com/

branches/update-datastore/gcloud-java-datastore/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ public class GcloudJavaDatastoreExample {
189189
}
190190
```
191191

192-
Troubleshooting
193-
---------------
194-
195-
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
196-
197192
Java Versions
198193
-------------
199194

@@ -220,9 +215,7 @@ Contributing
220215

221216
Contributions to this library are always welcome and highly encouraged.
222217

223-
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
224-
225-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
218+
See [CONTRIBUTING] for more information on how to get started.
226219

227220
License
228221
-------
@@ -231,7 +224,6 @@ Apache 2.0 - See [LICENSE] for more information.
231224

232225

233226
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
234-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
235227
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
236228
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-datastore
237229
[cloud-platform]: https://cloud.google.com/

branches/update-datastore/gcloud-java-examples/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ To run examples from your command line:
5858
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete <bucket_name> test.txt"
5959
```
6060

61-
Troubleshooting
62-
---------------
63-
64-
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
65-
6661
Java Versions
6762
-------------
6863

@@ -82,9 +77,7 @@ Contributing
8277

8378
Contributions to this library are always welcome and highly encouraged.
8479

85-
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
86-
87-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
80+
See [CONTRIBUTING] for more information on how to get started.
8881

8982
License
9083
-------
@@ -93,7 +86,6 @@ Apache 2.0 - See [LICENSE] for more information.
9386

9487

9588
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
96-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
9789
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
9890
[cloud-platform]: https://cloud.google.com/
9991
[developers-console]:https://console.developers.google.com/

branches/update-datastore/gcloud-java-storage/README.md

Lines changed: 146 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,162 @@ Cloud Storage for your project.
5656
See the ``gcloud-java`` API [storage documentation][storage-api] to learn how to interact
5757
with the Cloud Storage using this Client Library.
5858

59-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) and a project ID if running this snippet elsewhere.
59+
Getting Started
60+
---------------
61+
#### Prerequisites
62+
For this tutorial, you will need a [Google Developers Console](https://console.developers.google.com/) project with the Storage JSON API enabled. You will need to [enable billing](https://support.google.com/cloud/answer/6158867?hl=en) to use Google Cloud Storage. [Follow these instructions](https://cloud.google.com/docs/authentication#preparation) to get your project set up. You will also need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: `gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`.
63+
64+
#### Installation and setup
65+
You'll need to obtain the `gcloud-java-storage` library. See the [Quickstart](#quickstart) section to add `gcloud-java-storage` as a dependency in your code.
66+
67+
#### Creating an authorized service object
68+
To make authenticated requests to Google Cloud Storage, you must create a service object with credentials. You can then make API calls by calling methods on the Storage service object. The simplest way to authenticate is to use [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). These credentials are automatically inferred from your environment, so you only need the following code to create your service object:
69+
70+
```java
71+
import com.google.gcloud.storage.Storage;
72+
import com.google.gcloud.storage.StorageOptions;
73+
74+
Storage storage = StorageOptions.defaultInstance().service();
75+
```
76+
77+
For other authentication options, see the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) page.
78+
79+
#### Storing data
80+
Stored objects are called "blobs" in `gcloud-java` and are organized into containers called "buckets". In this code snippet, we will create a new bucket and upload a blob to that bucket.
81+
82+
Add the following imports at the top of your file:
6083

6184
```java
6285
import static java.nio.charset.StandardCharsets.UTF_8;
6386

87+
import com.google.gcloud.storage.BlobId;
88+
import com.google.gcloud.storage.BlobInfo;
89+
import com.google.gcloud.storage.BucketInfo;
90+
```
91+
92+
Then add the following code to create a bucket and upload a simple blob.
93+
94+
*Important: Bucket names have to be globally unique. If you choose a bucket name that already exists, you'll get a helpful error message telling you to choose another name. In the code below, replace "my_unique_bucket" with a unique bucket name.*
95+
96+
```java
97+
// Create a bucket
98+
String bucketName = "my_unique_bucket"; // Remember to change this to something unique
99+
BucketInfo bucketInfo = storage.create(BucketInfo.builder(bucketName).build());
100+
101+
// Upload a blob to the newly created bucket
102+
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
103+
BlobInfo blobInfo = storage.create(BlobInfo.builder(blobId).build(),
104+
"a simple blob".getBytes(UTF_8));
105+
```
106+
107+
At this point, you will be able to see your newly created bucket and blob on the Google Developers Console.
108+
109+
#### Retrieving data
110+
Now that we have content uploaded to the server, we can see how to read data from the server. Add the following import:
111+
112+
```java
64113
import com.google.gcloud.storage.Blob;
65-
import com.google.gcloud.storage.Storage;
66-
import com.google.gcloud.storage.StorageOptions;
114+
```
67115

68-
import java.nio.ByteBuffer;
69-
import java.nio.channels.WritableByteChannel;
116+
Then add the following lines to your program to get back the blob we uploaded.
70117

71-
Storage storage = StorageOptions.defaultInstance().service();
72-
Blob blob = new Blob(storage, "bucket", "blob_name");
73-
if (!blob.exists()) {
74-
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
75-
} else {
76-
System.out.println("Updating content for " + blob.info().name());
77-
byte[] prevContent = blob.content();
78-
System.out.println(new String(prevContent, UTF_8));
79-
WritableByteChannel channel = blob.writer();
80-
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
81-
channel.close();
118+
```java
119+
Blob blob = Blob.load(storage, blobInfo.blobId());
120+
String blobContent = new String(blob.content(), UTF_8);
121+
```
122+
123+
If others have permission to edit the blob, then you may want to call `reload` to get a more up to date copy of the blob later in your program. The following snippet shows how to get a new Blob object containing updated information.
124+
125+
```
126+
Blob refreshedBlob = blob.reload();
127+
```
128+
129+
#### Listing buckets and contents of buckets
130+
Suppose that you've added more buckets and blobs, and now you want to see the names of your buckets and the contents of each one. Add the following imports:
131+
132+
```java
133+
import com.google.gcloud.storage.Bucket;
134+
135+
import java.util.Iterator;
136+
```
137+
138+
Then add the following code to list all your buckets and all the blobs inside your newly created bucket.
139+
140+
```java
141+
// List all your buckets
142+
Iterator<BucketInfo> bucketInfoIterator = storage.list().iterateAll();
143+
System.out.println("My buckets:");
144+
while (bucketInfoIterator.hasNext()) {
145+
System.out.println(bucketInfoIterator.next());
146+
}
147+
148+
// List the blobs in a particular bucket
149+
Bucket bucket = Bucket.load(storage, bucketName);
150+
Iterator<Blob> blobIterator = bucket.list().iterateAll();
151+
System.out.println("My blobs:");
152+
while (blobIterator.hasNext()) {
153+
System.out.println(blobIterator.next().info());
82154
}
83155
```
84156

85-
Troubleshooting
86-
---------------
157+
#### Complete source code
87158

88-
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
159+
Here we put together all the code shown above into one program. This program assumes that you are running on Compute Engine or from your own desktop. To run this example on App Engine, simply move the code from the main method to your application's servlet class and change the print statements to display on your webpage.
160+
161+
```java
162+
import static java.nio.charset.StandardCharsets.UTF_8;
163+
164+
import com.google.gcloud.storage.Storage;
165+
import com.google.gcloud.storage.StorageOptions;
166+
import com.google.gcloud.storage.Blob;
167+
import com.google.gcloud.storage.BlobId;
168+
import com.google.gcloud.storage.BlobInfo;
169+
import com.google.gcloud.storage.Bucket;
170+
import com.google.gcloud.storage.BucketInfo;
171+
172+
import java.util.Iterator;
173+
174+
public class GcloudStorageExample {
175+
176+
public static void main(String[] args) {
177+
// Create a service object
178+
// Credentials are inferred from the environment.
179+
Storage storage = StorageOptions.defaultInstance().service();
180+
181+
// Create a bucket
182+
String bucketName = "my_unique_bucket-1323252"; // Remember to change this to something unique
183+
BucketInfo bucketInfo = storage.create(BucketInfo.builder(bucketName).build());
184+
185+
// Upload a blob to the newly created bucket
186+
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
187+
BlobInfo blobInfo = storage.create(BlobInfo.builder(blobId).build(),
188+
"a simple blob".getBytes(UTF_8));
189+
190+
// Retrieve a blob from the server
191+
Blob blob = Blob.load(storage, blobInfo.blobId());
192+
String blobContent = new String(blob.content(), UTF_8);
193+
194+
// An example of how to get an updated blob
195+
// This is useful in cases where others with access to your blob may have changed it.
196+
Blob refreshedBlob = blob.reload();
197+
198+
// List all your buckets
199+
Iterator<BucketInfo> bucketInfoIterator = storage.list().iterateAll();
200+
System.out.println("My buckets:");
201+
while (bucketInfoIterator.hasNext()) {
202+
System.out.println(bucketInfoIterator.next());
203+
}
204+
205+
// List the blobs in a particular bucket
206+
Bucket bucket = Bucket.load(storage, bucketName);
207+
Iterator<Blob> blobIterator = bucket.list().iterateAll();
208+
System.out.println("My blobs:");
209+
while (blobIterator.hasNext()) {
210+
System.out.println(blobIterator.next().info());
211+
}
212+
}
213+
}
214+
```
89215

90216
Java Versions
91217
-------------
@@ -113,9 +239,7 @@ Contributing
113239

114240
Contributions to this library are always welcome and highly encouraged.
115241

116-
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
117-
118-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
242+
See [CONTRIBUTING] for more information on how to get started.
119243

120244
License
121245
-------
@@ -124,7 +248,6 @@ Apache 2.0 - See [LICENSE] for more information.
124248

125249

126250
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
127-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
128251
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
129252
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-storage
130253
[cloud-platform]: https://cloud.google.com/
@@ -133,4 +256,3 @@ Apache 2.0 - See [LICENSE] for more information.
133256
[cloud-storage-docs]: https://cloud.google.com/storage/docs/overview
134257
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
135258
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html
136-
[cloud-storage-activation]:https://cloud.google.com/storage/docs/signup?hl=en

0 commit comments

Comments
 (0)