Skip to content

Commit c35cf87

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1975 b: refs/heads/pubsub-alpha c: 3af2bba h: refs/heads/master i: 1973: b725866 1971: 562d34b 1967: 4fae53b
1 parent 8c5d746 commit c35cf87

2 files changed

Lines changed: 20 additions & 42 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 08c0f28f6b05b77af79b042a0b56bdb21d2a2286
6+
refs/heads/pubsub-alpha: 3af2bbabb348c03a10fc643aa1f61b900f8e035b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-storage/README.md

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,43 +95,29 @@ Then add the following code to create a bucket and upload a simple blob.
9595

9696
```java
9797
// 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());
98+
String bucketName = "my_unique_bucket"; // Change this to something unique
99+
BucketInfo bucketInfo = storage.create(BucketInfo.of(bucketName));
100100

101101
// Upload a blob to the newly created bucket
102102
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
103-
BlobInfo blobInfo = storage.create(BlobInfo.builder(blobId).build(),
104-
"a simple blob".getBytes(UTF_8));
103+
BlobInfo blobInfo = storage.create(
104+
BlobInfo.builder(blobId).contentType("text/plain").build(),
105+
"a simple blob".getBytes(UTF_8));
105106
```
106107

107108
At this point, you will be able to see your newly created bucket and blob on the Google Developers Console.
108109

109110
#### 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+
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.
111112

112113
```java
113-
import com.google.gcloud.storage.Blob;
114-
```
115-
116-
Then add the following lines to your program to get back the blob we uploaded.
117-
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();
114+
String blobContent = new String(storage.readAllBytes(blobId), UTF_8);
127115
```
128116

129117
#### Listing buckets and contents of buckets
130118
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:
131119

132120
```java
133-
import com.google.gcloud.storage.Bucket;
134-
135121
import java.util.Iterator;
136122
```
137123

@@ -146,11 +132,10 @@ while (bucketInfoIterator.hasNext()) {
146132
}
147133

148134
// List the blobs in a particular bucket
149-
Bucket bucket = Bucket.load(storage, bucketName);
150-
Iterator<Blob> blobIterator = bucket.list().iterateAll();
135+
Iterator<BlobInfo> blobIterator = storage.list(bucketName).iterateAll();
151136
System.out.println("My blobs:");
152137
while (blobIterator.hasNext()) {
153-
System.out.println(blobIterator.next().info());
138+
System.out.println(blobIterator.next());
154139
}
155140
```
156141

@@ -161,13 +146,11 @@ Here we put together all the code shown above into one program. This program as
161146
```java
162147
import static java.nio.charset.StandardCharsets.UTF_8;
163148

164-
import com.google.gcloud.storage.Storage;
165-
import com.google.gcloud.storage.StorageOptions;
166-
import com.google.gcloud.storage.Blob;
167149
import com.google.gcloud.storage.BlobId;
168150
import com.google.gcloud.storage.BlobInfo;
169-
import com.google.gcloud.storage.Bucket;
170151
import com.google.gcloud.storage.BucketInfo;
152+
import com.google.gcloud.storage.Storage;
153+
import com.google.gcloud.storage.StorageOptions;
171154

172155
import java.util.Iterator;
173156

@@ -179,21 +162,17 @@ public class GcloudStorageExample {
179162
Storage storage = StorageOptions.defaultInstance().service();
180163

181164
// 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());
165+
String bucketName = "my_unique_bucket"; // Change this to something unique
166+
BucketInfo bucketInfo = storage.create(BucketInfo.of(bucketName));
184167

185168
// Upload a blob to the newly created bucket
186169
BlobId blobId = BlobId.of(bucketName, "my_blob_name");
187-
BlobInfo blobInfo = storage.create(BlobInfo.builder(blobId).build(),
188-
"a simple blob".getBytes(UTF_8));
170+
BlobInfo blobInfo = storage.create(
171+
BlobInfo.builder(blobId).contentType("text/plain").build(),
172+
"a simple blob".getBytes(UTF_8));
189173

190174
// 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();
175+
String blobContent = new String(storage.readAllBytes(blobId), UTF_8);
197176

198177
// List all your buckets
199178
Iterator<BucketInfo> bucketInfoIterator = storage.list().iterateAll();
@@ -203,11 +182,10 @@ public class GcloudStorageExample {
203182
}
204183

205184
// List the blobs in a particular bucket
206-
Bucket bucket = Bucket.load(storage, bucketName);
207-
Iterator<Blob> blobIterator = bucket.list().iterateAll();
185+
Iterator<BlobInfo> blobIterator = storage.list(bucketName).iterateAll();
208186
System.out.println("My blobs:");
209187
while (blobIterator.hasNext()) {
210-
System.out.println(blobIterator.next().info());
188+
System.out.println(blobIterator.next());
211189
}
212190
}
213191
}

0 commit comments

Comments
 (0)