Skip to content

Commit abc9a00

Browse files
committed
Refactor storage readme example to use strings
1 parent ebfde4b commit abc9a00

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,28 @@ See the ``gcloud-java`` API [storage documentation][storage-api] to learn how to
102102
with the Cloud Storage using this Client Library.
103103

104104
```java
105+
import static java.nio.charset.StandardCharsets.UTF_8;
106+
105107
import com.google.gcloud.storage.Blob;
106108
import com.google.gcloud.storage.Storage;
107109
import com.google.gcloud.storage.StorageFactory;
108110
import com.google.gcloud.storage.StorageOptions;
111+
109112
import java.nio.ByteBuffer;
110113
import java.nio.channels.WritableByteChannel;
111114

112115
StorageOptions options = StorageOptions.builder().projectId(PROJECT_ID).build();
113116
Storage storage = StorageFactory.instance().get(options);
114-
byte[] content = readContent();
115117
Blob blob = new Blob(storage, "bucket", "blob_name");
116118
if (!blob.exists()) {
117-
storage.create(blob.info(), content);
119+
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
118120
} else {
119121
System.out.println("Updating content for " + blob.info().name());
120122
byte[] prevContent = blob.content();
121-
content = mergeContent(prevContent, content);
123+
System.out.println(new String(prevContent, UTF_8));
122124
WritableByteChannel channel = blob.writer();
123-
channel.write(ByteBuffer.wrap(content));
125+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
124126
channel.close();
125-
}
126127
}
127128
```
128129

gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
* <pre>{@code
2222
* StorageOptions options = StorageOptions.builder().projectId("project").build();
2323
* Storage storage = StorageFactory.instance().get(options);
24-
* byte[] content = readContent();
2524
* Blob blob = new Blob(storage, "bucket", "blob_name");
2625
* if (!blob.exists()) {
27-
* storage.create(blob.info(), content);
26+
* storage.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
2827
* } else {
28+
* System.out.println("Updating content for " + blob.info().name());
2929
* byte[] prevContent = blob.content();
30-
* content = mergeContent(prevContent, content);
30+
* System.out.println(new String(prevContent, UTF_8));
3131
* WritableByteChannel channel = blob.writer();
32-
* channel.write(ByteBuffer.wrap(content));
32+
* channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
3333
* channel.close();
3434
* }}</pre>
3535
*

0 commit comments

Comments
 (0)