Skip to content

Commit c2d28b2

Browse files
committed
---
yaml --- r: 5091 b: refs/heads/master c: 9451e1d h: refs/heads/master i: 5089: b5bc533 5087: 557f364
1 parent 9e23d03 commit c2d28b2

10 files changed

Lines changed: 769 additions & 17 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 720a4789e6128b68fc648bd36833f7d0ea3c8953
2+
refs/heads/master: 9451e1d3d9d5c401d8fdd7e304795e91287be0f8
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
55
refs/heads/pubsub-alpha: d6bbd32eed6cb48cda8d6798ee70ddd6bfc1f07d

trunk/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/BlobSnippets.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.google.cloud.ReadChannel;
2929
import com.google.cloud.ServiceAccountSigner;
3030
import com.google.cloud.WriteChannel;
31+
import com.google.cloud.storage.Acl;
32+
import com.google.cloud.storage.Acl.User;
3133
import com.google.cloud.storage.Blob;
3234
import com.google.cloud.storage.Blob.BlobSourceOption;
3335
import com.google.cloud.storage.BlobId;
@@ -40,6 +42,7 @@
4042
import java.net.URL;
4143
import java.nio.ByteBuffer;
4244
import java.util.HashMap;
45+
import java.util.List;
4346
import java.util.Map;
4447
import java.util.concurrent.TimeUnit;
4548

@@ -228,4 +231,67 @@ public URL signUrlWithSigner(String keyPath) throws IOException {
228231
// [END signUrlWithSigner]
229232
return signedUrl;
230233
}
234+
235+
/**
236+
* Example of getting the ACL entry for an entity.
237+
*/
238+
// [TARGET getAcl(Entity)]
239+
public Acl getAcl() {
240+
// [START getAcl]
241+
Acl acl = blob.getAcl(User.ofAllAuthenticatedUsers());
242+
// [END getAcl]
243+
return acl;
244+
}
245+
246+
/**
247+
* Example of deleting the ACL entry for an entity.
248+
*/
249+
// [TARGET deleteAcl(Entity)]
250+
public boolean deleteAcl() {
251+
// [START deleteAcl]
252+
boolean deleted = blob.deleteAcl(User.ofAllAuthenticatedUsers());
253+
if (deleted) {
254+
// the acl entry was deleted
255+
} else {
256+
// the acl entry was not found
257+
}
258+
// [END deleteAcl]
259+
return deleted;
260+
}
261+
262+
/**
263+
* Example of creating a new ACL entry.
264+
*/
265+
// [TARGET createAcl(Acl)]
266+
public Acl createAcl() {
267+
// [START createAcl]
268+
Acl acl = blob.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER));
269+
// [END createAcl]
270+
return acl;
271+
}
272+
273+
/**
274+
* Example of updating a new ACL entry.
275+
*/
276+
// [TARGET updateAcl(Acl)]
277+
public Acl updateAcl() {
278+
// [START updateAcl]
279+
Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER));
280+
// [END updateAcl]
281+
return acl;
282+
}
283+
284+
/**
285+
* Example of listing the ACL entries.
286+
*/
287+
// [TARGET listAcls()]
288+
public List<Acl> listAcls() {
289+
// [START listAcls]
290+
List<Acl> acls = blob.listAcls();
291+
for (Acl acl : acls) {
292+
// do something with ACL entry
293+
}
294+
// [END listAcls]
295+
return acls;
296+
}
231297
}

trunk/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/BucketSnippets.java

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import static java.nio.charset.StandardCharsets.UTF_8;
2626

2727
import com.google.cloud.Page;
28+
import com.google.cloud.storage.Acl;
29+
import com.google.cloud.storage.Acl.User;
2830
import com.google.cloud.storage.Blob;
2931
import com.google.cloud.storage.Bucket;
3032
import com.google.cloud.storage.Bucket.BucketSourceOption;
@@ -124,8 +126,8 @@ public Page<Blob> listBlobs() {
124126
}
125127

126128
/**
127-
* Example of getting a blob in the bucket, only if its metageneration matches a value, otherwise
128-
* a {@link StorageException} is thrown.
129+
* Example of getting a blob in the bucket, only if its metageneration matches a value,
130+
* otherwise a {@link StorageException} is thrown.
129131
*/
130132
// [TARGET get(String, BlobGetOption...)]
131133
// [VARIABLE "my_blob_name"]
@@ -226,4 +228,130 @@ public Blob createBlobFromInputStreamWithContentType(String blobName) {
226228
// [END createBlobFromInputStreamWithContentType]
227229
return blob;
228230
}
231+
232+
/**
233+
* Example of getting the ACL entry for an entity.
234+
*/
235+
// [TARGET getAcl(Entity)]
236+
public Acl getAcl() {
237+
// [START getAcl]
238+
Acl acl = bucket.getAcl(User.ofAllAuthenticatedUsers());
239+
// [END getAcl]
240+
return acl;
241+
}
242+
243+
/**
244+
* Example of deleting the ACL entry for an entity.
245+
*/
246+
// [TARGET deleteAcl(Entity)]
247+
public boolean deleteAcl() {
248+
// [START deleteAcl]
249+
boolean deleted = bucket.deleteAcl(User.ofAllAuthenticatedUsers());
250+
if (deleted) {
251+
// the acl entry was deleted
252+
} else {
253+
// the acl entry was not found
254+
}
255+
// [END deleteAcl]
256+
return deleted;
257+
}
258+
259+
/**
260+
* Example of creating a new ACL entry.
261+
*/
262+
// [TARGET createAcl(Acl)]
263+
public Acl createAcl() {
264+
// [START createAcl]
265+
Acl acl = bucket.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER));
266+
// [END createAcl]
267+
return acl;
268+
}
269+
270+
/**
271+
* Example of updating a new ACL entry.
272+
*/
273+
// [TARGET updateAcl(Acl)]
274+
public Acl updateAcl() {
275+
// [START updateAcl]
276+
Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER));
277+
// [END updateAcl]
278+
return acl;
279+
}
280+
281+
/**
282+
* Example of listing the ACL entries.
283+
*/
284+
// [TARGET listAcls()]
285+
public List<Acl> listAcls() {
286+
// [START listAcls]
287+
List<Acl> acls = bucket.listAcls();
288+
for (Acl acl : acls) {
289+
// do something with ACL entry
290+
}
291+
// [END listAcls]
292+
return acls;
293+
}
294+
295+
/**
296+
* Example of getting the default ACL entry for an entity.
297+
*/
298+
// [TARGET getDefaultAcl(Entity)]
299+
public Acl getDefaultAcl() {
300+
// [START getDefaultAcl]
301+
Acl acl = bucket.getDefaultAcl(User.ofAllAuthenticatedUsers());
302+
// [END getDefaultAcl]
303+
return acl;
304+
}
305+
306+
/**
307+
* Example of deleting the default ACL entry for an entity.
308+
*/
309+
// [TARGET deleteDefaultAcl(Entity)]
310+
public boolean deleteDefaultAcl() {
311+
// [START deleteDefaultAcl]
312+
boolean deleted = bucket.deleteDefaultAcl(User.ofAllAuthenticatedUsers());
313+
if (deleted) {
314+
// the acl entry was deleted
315+
} else {
316+
// the acl entry was not found
317+
}
318+
// [END deleteDefaultAcl]
319+
return deleted;
320+
}
321+
322+
/**
323+
* Example of creating a new default ACL entry.
324+
*/
325+
// [TARGET createDefaultAcl(Acl)]
326+
public Acl createDefaultAcl() {
327+
// [START createDefaultAcl]
328+
Acl acl = bucket.createDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER));
329+
// [END createDefaultAcl]
330+
return acl;
331+
}
332+
333+
/**
334+
* Example of updating a new default ACL entry.
335+
*/
336+
// [TARGET updateDefaultAcl(Acl)]
337+
public Acl updateDefaultAcl() {
338+
// [START updateDefaultAcl]
339+
Acl acl = bucket.updateDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER));
340+
// [END updateDefaultAcl]
341+
return acl;
342+
}
343+
344+
/**
345+
* Example of listing the default ACL entries.
346+
*/
347+
// [TARGET listDefaultAcls()]
348+
public List<Acl> listDefaultAcls() {
349+
// [START listDefaultAcls]
350+
List<Acl> acls = bucket.listDefaultAcls();
351+
for (Acl acl : acls) {
352+
// do something with ACL entry
353+
}
354+
// [END listDefaultAcls]
355+
return acls;
356+
}
229357
}

0 commit comments

Comments
 (0)