1-
21/*
32 * Copyright 2015 Google Inc. All Rights Reserved.
43 *
3130import java .net .URL ;
3231import java .util .Objects ;
3332
34-
3533/**
3634 * A Google cloud storage object.
3735 */
@@ -89,38 +87,68 @@ static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption...
8987 }
9088 }
9189
90+ /**
91+ * Construct a {@code Blob} object for the provided {@code BlobInfo}. The storage service is used
92+ * to issue requests.
93+ *
94+ * @param storage the storage service used for issuing requests
95+ * @param info blob's info
96+ */
9297 public Blob (Storage storage , BlobInfo info ) {
9398 this .storage = checkNotNull (storage );
9499 this .info = checkNotNull (info );
95100 }
96101
102+ /**
103+ * Construct a {@code Blob} object for the provided bucket and blob names. The storage service is
104+ * used to issue requests.
105+ *
106+ * @param storage the storage service used for issuing requests
107+ * @param bucket bucket's name
108+ * @param blob blob's name
109+ */
110+ public Blob (Storage storage , String bucket , String blob ) {
111+ this .storage = checkNotNull (storage );
112+ this .info = BlobInfo .of (bucket , blob );
113+ }
114+
115+ /**
116+ * Get the blobs's information.
117+ *
118+ * @return a {@code BlobInfo} object for this blob
119+ */
97120 public BlobInfo info () {
98121 return info ;
99122 }
100123
101124 /**
102- * Returns true if this blob exists.
125+ * Check if this blob exists.
103126 *
127+ * @return true if this blob exists, false otherwise
104128 * @throws StorageException upon failure
105129 */
106130 public boolean exists () {
107131 return storage .get (info .bucket (), info .name ()) != null ;
108132 }
109133
110134 /**
111- * Returns the blob's content.
135+ * Return this blob's content.
112136 *
137+ * @param options blob read options
138+ * @return the blob's content
113139 * @throws StorageException upon failure
114140 */
115141 public byte [] content (Storage .BlobSourceOption ... options ) {
116142 return storage .readAllBytes (info .bucket (), info .name (), options );
117143 }
118144
119145 /**
120- * Updates the blob's information. Bucket or blob's name cannot be changed by this method. If you
146+ * Update the blob's information. Bucket or blob's name cannot be changed by this method. If you
121147 * want to rename the blob or move it to a different bucket use the {@link #copyTo} and
122148 * {@link #delete} operations.
123149 *
150+ * @param blobInfo new blob's information. Bucket and blob names must match the current ones
151+ * @param options update options
124152 * @throws StorageException upon failure
125153 */
126154 public void update (BlobInfo blobInfo , BlobTargetOption ... options ) {
@@ -130,29 +158,35 @@ public void update(BlobInfo blobInfo, BlobTargetOption... options) {
130158 }
131159
132160 /**
133- * Deletes this blob.
161+ * Delete this blob.
134162 *
135- * @return true if bucket was deleted
163+ * @param options blob delete options
164+ * @return true if blob was deleted
136165 * @throws StorageException upon failure
137166 */
138167 public boolean delete (BlobSourceOption ... options ) {
139168 return storage .delete (info .bucket (), info .name (), convert (info , options ));
140169 }
141170
142171 /**
143- * Send a copy request .
172+ * Copy this blob .
144173 *
145- * @return the copied blob.
174+ * @param target target blob
175+ * @param options source blob options
176+ * @return the copied blob
146177 * @throws StorageException upon failure
147178 */
148179 public Blob copyTo (BlobInfo target , BlobSourceOption ... options ) {
149180 return copyTo (target , ImmutableList .copyOf (options ), ImmutableList .<BlobTargetOption >of ());
150181 }
151182
152183 /**
153- * Send a copy request .
184+ * Copy this blob .
154185 *
155- * @return the copied blob.
186+ * @param target target blob
187+ * @param sourceOptions source blob options
188+ * @param targetOptions target blob options
189+ * @return the copied blob
156190 * @throws StorageException upon failure
157191 */
158192 public Blob copyTo (BlobInfo target , Iterable <BlobSourceOption > sourceOptions ,
@@ -165,36 +199,47 @@ public Blob copyTo(BlobInfo target, Iterable<BlobSourceOption> sourceOptions,
165199 }
166200
167201 /**
168- * Returns a channel for reading this blob's content.
202+ * Return a channel for reading this blob's content.
169203 *
204+ * @param options blob read options
205+ * @return a {@code BlobReadChannel} object to read this blob
170206 * @throws StorageException upon failure
171207 */
172208 public BlobReadChannel reader (BlobSourceOption ... options ) {
173209 return storage .reader (info .bucket (), info .name (), convert (info , options ));
174210 }
175211
176212 /**
177- * Returns a channel for writing to this blob.
213+ * Return a channel for writing to this blob.
178214 *
215+ * @param options target blob options
216+ * @return a {@code BlobWriteChannel} object for writing to this blob
179217 * @throws StorageException upon failure
180218 */
181219 public BlobWriteChannel writer (BlobTargetOption ... options ) {
182220 return storage .writer (info , options );
183221 }
184222
185223 /**
186- * Generates a signed URL for this blob. If you want to allow access to for a fixed amount of time
224+ * Generate a signed URL for this blob. If you want to allow access to for a fixed amount of time
187225 * for this blob, you can use this method to generate a URL that is only valid within a certain
188226 * time period. This is particularly useful if you don't want publicly accessible blobs, but don't
189227 * want to require users to explicitly log in.
190228 *
191229 * @param expirationTimeInSeconds the signed URL expiration (using epoch time)
230+ * @param options signed url options
231+ * @return a signed URL for this bucket and the specified options
192232 * @see <a href="https://cloud.google.com/storage/docs/access-control#Signed-URLs">Signed-URLs</a>
193233 */
194234 public URL signUrl (long expirationTimeInSeconds , SignUrlOption ... options ) {
195235 return storage .signUrl (info , expirationTimeInSeconds , options );
196236 }
197237
238+ /**
239+ * Get this blobs's {@code Storage} object.
240+ *
241+ * @return the storage service used by this blob to issue requests
242+ */
198243 public Storage storage () {
199244 return storage ;
200245 }
0 commit comments