Skip to content

Commit 77d4b39

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1237 b: refs/heads/master c: 3af2bba h: refs/heads/master i: 1235: de311f2 v: v3
1 parent 278bf1e commit 77d4b39

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
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: 08c0f28f6b05b77af79b042a0b56bdb21d2a2286
2+
refs/heads/master: 3af2bbabb348c03a10fc643aa1f61b900f8e035b
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/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)