@@ -104,19 +104,23 @@ Here is a code snippet showing a simple usage example from within Compute/App En
104104import static java.nio.charset.StandardCharsets.UTF_8 ;
105105
106106import com.google.gcloud.storage.Blob ;
107+ import com.google.gcloud.storage.BlobId ;
107108import com.google.gcloud.storage.Storage ;
108109import com.google.gcloud.storage.StorageFactory ;
109110import com.google.gcloud.storage.StorageOptions ;
110111
111112import java.nio.ByteBuffer ;
112113import java.nio.channels.WritableByteChannel ;
113114
114- Storage storage = StorageFactory . instance(). get(StorageOptions . getDefaultInstance());
115- Blob blob = new Blob (storage, " bucket" , " blob_name" );
116- if (! blob. exists()) {
117- storage2. create(blob. info(), " Hello, Cloud Storage!" . getBytes(UTF_8 ));
115+ StorageOptions options = StorageOptions . builder(). projectId(" project" ). build();
116+ Storage storage = StorageFactory . instance(). get(options);
117+ BlobId blobId = BlobId . of(" bucket" , " blob_name" );
118+ Blob blob = Blob . load(storage, blobId);
119+ if (blob == null ) {
120+ BlobInfo blobInfo = BlobInfo . builder(blobId). contentType(" text/plain" ). build();
121+ storage. create(blobInfo, " Hello, Cloud Storage!" . getBytes(UTF_8 ));
118122} else {
119- System . out. println(" Updating content for " + blob . info() . name());
123+ System . out. println(" Updating content for " + blobId . name());
120124 byte [] prevContent = blob. content();
121125 System . out. println(new String (prevContent, UTF_8 ));
122126 WritableByteChannel channel = blob. writer();
0 commit comments