Skip to content

Commit c6b7f27

Browse files
committed
Merge pull request #209 from mziccard/storage-example
Update storage examples, add storage section to readme
2 parents 429ac30 + 167197f commit c6b7f27

File tree

3 files changed

+128
-83
lines changed

3 files changed

+128
-83
lines changed

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1414
This client supports the following Google Cloud Platform services:
1515

1616
- [Google Cloud Datastore] (#google-cloud-datastore)
17+
- [Google Cloud Storage] (#google-cloud-storage)
1718

1819
<!---
1920
- [Google Cloud Storage] (https://cloud.google.com/storage/)
@@ -44,7 +45,7 @@ Example Applications
4445
Google Cloud Datastore
4546
----------------------
4647

47-
Google [Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
48+
[Google Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
4849
storing non-relational data. Cloud Datastore automatically scales with
4950
your users and supports ACID transactions, high availability of reads and
5051
writes, strong consistency for reads and ancestor queries, and eventual
@@ -86,6 +87,46 @@ if (entity == null) {
8687
}
8788
```
8889

90+
Google Cloud Storage
91+
----------------------
92+
93+
[Google Cloud Storage][cloud-storage] is a durable and highly available
94+
object storage service. Google Cloud Storage is almost infinitely scalable
95+
and guarantees consistency: when a write succeeds, the latest copy of the
96+
object will be returned to any GET, globally.
97+
98+
See the [Google Cloud Storage docs][cloud-storage-activation] for more details on how to activate
99+
Cloud Storage for your project.
100+
101+
See the ``gcloud-java`` API [storage documentation][storage-api] to learn how to interact
102+
with the Cloud Storage using this Client Library.
103+
104+
```java
105+
import static java.nio.charset.StandardCharsets.UTF_8;
106+
107+
import com.google.gcloud.storage.Blob;
108+
import com.google.gcloud.storage.Storage;
109+
import com.google.gcloud.storage.StorageFactory;
110+
import com.google.gcloud.storage.StorageOptions;
111+
112+
import java.nio.ByteBuffer;
113+
import java.nio.channels.WritableByteChannel;
114+
115+
StorageOptions options = StorageOptions.builder().projectId(PROJECT_ID).build();
116+
Storage storage = StorageFactory.instance().get(options);
117+
Blob blob = new Blob(storage, "bucket", "blob_name");
118+
if (!blob.exists()) {
119+
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
120+
} else {
121+
System.out.println("Updating content for " + blob.info().name());
122+
byte[] prevContent = blob.content();
123+
System.out.println(new String(prevContent, UTF_8));
124+
WritableByteChannel channel = blob.writer();
125+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
126+
channel.close();
127+
}
128+
```
129+
89130
Contributing
90131
------------
91132

@@ -130,3 +171,5 @@ Apache 2.0 - See [LICENSE] for more information.
130171
[cloud-storage]: https://cloud.google.com/storage/
131172
[cloud-storage-docs]: https://cloud.google.com/storage/docs/overview
132173
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
174+
[cloud-storage-activation]: https://cloud.google.com/storage/docs/signup
175+
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html

0 commit comments

Comments
 (0)