Skip to content

Commit 768ec4a

Browse files
Removing Cloud Storage section of main README (#2336)
1 parent 5517ae8 commit 768ec4a

2 files changed

Lines changed: 33 additions & 62 deletions

File tree

README.md

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1515
This client supports the following Google Cloud Platform services at a [GA](#versioning) quality level:
1616
- [Stackdriver Logging](#stackdriver-logging-ga) (GA)
1717
- [Cloud Datastore](#google-cloud-datastore-ga) (GA)
18-
- [Cloud Storage](#google-cloud-storage-ga) (GA)
18+
- [Cloud Storage](google-cloud-storage) (GA)
1919
- [Cloud Translation](#google-translation-ga) (GA)
2020

2121
This client supports the following Google Cloud Platform services at a [Beta](#versioning) quality level:
@@ -352,63 +352,8 @@ if (entity != null) {
352352
.build();
353353
datastore.update(entity);
354354
}
355-
```
356-
357-
Google Cloud Storage (GA)
358-
----------------------
359-
360-
- [API Documentation][storage-api]
361-
- [Official Documentation][cloud-storage-docs]
362-
363-
*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.*
364-
365-
#### Preview
366-
367-
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
368-
369-
The first snippet shows how to create a Storage blob. Complete source code can be found at
370-
[CreateBlob.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateBlob.java).
371-
372-
```java
373-
import static java.nio.charset.StandardCharsets.UTF_8;
374355
375-
import com.google.cloud.storage.Blob;
376-
import com.google.cloud.storage.BlobId;
377-
import com.google.cloud.storage.BlobInfo;
378-
import com.google.cloud.storage.Storage;
379-
import com.google.cloud.storage.StorageOptions;
380-
381-
Storage storage = StorageOptions.getDefaultInstance().getService();
382-
BlobId blobId = BlobId.of("bucket", "blob_name");
383-
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
384-
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
385356
```
386-
The second snippet shows how to update a Storage blob if it exists. Complete source code can be
387-
found at
388-
[UpdateBlob.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/UpdateBlob.java).
389-
```java
390-
import static java.nio.charset.StandardCharsets.UTF_8;
391-
392-
import com.google.cloud.storage.Blob;
393-
import com.google.cloud.storage.BlobId;
394-
import com.google.cloud.storage.Storage;
395-
import com.google.cloud.storage.StorageOptions;
396-
397-
import java.nio.ByteBuffer;
398-
import java.nio.channels.WritableByteChannel;
399-
400-
Storage storage = StorageOptions.getDefaultInstance().getService();
401-
BlobId blobId = BlobId.of("bucket", "blob_name");
402-
Blob blob = storage.get(blobId);
403-
if (blob != null) {
404-
byte[] prevContent = blob.getContent();
405-
System.out.println(new String(prevContent, UTF_8));
406-
WritableByteChannel channel = blob.writer();
407-
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
408-
channel.close();
409-
}
410-
```
411-
412357
Google Translation (GA)
413358
----------------
414359

google-cloud-storage/README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import com.google.cloud.storage.BucketInfo;
9090

9191
Then add the following code to create a bucket and upload a simple blob.
9292

93-
*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. See more about naming rules [here](https://cloud.google.com/storage/docs/bucket-naming?hl=en#requirements).*
93+
*Important: Bucket names have to be globally unique (among all users of Cloud Storage). 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. See more about naming rules [here](https://cloud.google.com/storage/docs/bucket-naming?hl=en#requirements).*
9494

9595
```java
9696
// Create a bucket
@@ -99,19 +99,45 @@ Bucket bucket = storage.create(BucketInfo.of(bucketName));
9999

100100
// Upload a blob to the newly created bucket
101101
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
102-
Blob blob = bucket.create(
103-
"my_blob_name", "a simple blob".getBytes(UTF_8), "text/plain");
102+
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
103+
Blob blob = storage.create(blobInfo, "a simple blob".getBytes(UTF_8));
104104
```
105105

106+
A complete example for creating a blob can be found at
107+
[CreateBlob.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateBlob.java).
108+
106109
At this point, you will be able to see your newly created bucket and blob on the Google Developers Console.
107110

108111
#### Retrieving data
109112
Now that we have content uploaded to the server, we can see how to read data from the server. Add the following line to your program to get back the blob we uploaded.
110113

111114
```java
112-
String blobContent = new String(blob.getContent(), UTF_8);
115+
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
116+
byte[] content = storage.readAllBytes(blobId);
117+
String contentString = new String(content, UTF_8);
113118
```
114119

120+
A complete example for accessing blobs can be found at
121+
[CreateBlob.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateBlob.java).
122+
123+
#### Updating data
124+
Another thing we may want to do is update a blob. The following snippet shows how to update a Storage blob if it exists.
125+
126+
``` java
127+
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
128+
Blob blob = storage.get(blobId);
129+
if (blob != null) {
130+
byte[] prevContent = blob.getContent();
131+
System.out.println(new String(prevContent, UTF_8));
132+
WritableByteChannel channel = blob.writer();
133+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
134+
channel.close();
135+
}
136+
```
137+
138+
The complete source code can be found at
139+
[UpdateBlob.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/UpdateBlob.java).
140+
115141
#### Listing buckets and contents of buckets
116142
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 code to list all your buckets and all the blobs inside each bucket.
117143

@@ -125,15 +151,15 @@ for (Bucket bucket : storage.list().iterateAll()) {
125151
System.out.println("Blobs in the bucket:");
126152
for (Blob blob : bucket.list().iterateAll()) {
127153
System.out.println(blob);
128-
}
154+
}
129155
}
130156
```
131157

132158
#### Complete source code
133159

134160
In
135161
[CreateAndListBucketsAndBlobs.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/CreateAndListBucketsAndBlobs.java)
136-
we put together all the code shown above into one program. The program assumes that you are
162+
we put together examples creating and listing buckets and blobs into one program. The program assumes that you are
137163
running on Compute Engine or from your own desktop. To run the example on App Engine, simply move
138164
the code from the main method to your application's servlet class and change the print statements to
139165
display on your webpage.

0 commit comments

Comments
 (0)