• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ObjectAccessControl类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.google.api.services.storage.model.ObjectAccessControl的典型用法代码示例。如果您正苦于以下问题:Java ObjectAccessControl类的具体用法?Java ObjectAccessControl怎么用?Java ObjectAccessControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ObjectAccessControl类属于com.google.api.services.storage.model包,在下文中一共展示了ObjectAccessControl类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: uploadFile

点赞 3

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
/**
 * Uploads data to an object in a bucket.
 *
 * @param name the name of the destination object.
 * @param contentType the MIME type of the data.
 * @param file the file to upload.
 * @param bucketName the name of the bucket to create the object in.
 */
private void uploadFile(String name, String contentType, File file, String bucketName) throws IOException,
        GeneralSecurityException {
    InputStreamContent contentStream = new InputStreamContent(contentType, new FileInputStream(file));
    // Setting the length improves upload performance
    contentStream.setLength(file.length());
    StorageObject objectMetadata = new StorageObject()
            // Set the destination object name
            .setName(name)
            // Set the access control list to publicly read-only
            .setAcl(Arrays.asList(
                    new ObjectAccessControl().setEntity("allUsers").setRole("READER")));

    // Do the insert
    Storage client = StorageFactory.getService();
    Storage.Objects.Insert insertRequest = client.objects().insert(
            bucketName, objectMetadata, contentStream);

    insertRequest.execute();
    LogUtils.debug(LOG_TAG, "Successfully uploaded file to bucket.\nName: " + name + "\nBucket name: " +
            bucketName);
}
 

开发者ID:darshanmaiya,
项目名称:MCSFS,
代码行数:30,
代码来源:GCStore.java

示例2: saveImage

点赞 3

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
/**
 * Method to insert a image into the bucket of the cloud storage.
 *
 * @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
 * @since 15/10/2015
 *
 * @param name of the image.
 * @param contentStream to be converted.
 *
 * @return the media link of the image.
 *
 * @throws IOException in case a IO problem.
 * @throws GeneralSecurityException in case a security problem.
 */
public static String saveImage(String name, InputStreamContent contentStream)
    throws IOException, GeneralSecurityException {
  logger.finest("###### Saving a image");
  StorageObject objectMetadata = new StorageObject()
      // Set the destination object name
      .setName(name)
      // Set the access control list to publicly read-only
      .setAcl(Arrays.asList(new ObjectAccessControl().setEntity(ALL_USERS).setRole(READER)));

  Storage client = getService();
  String bucketName = getBucket().getName();
  Storage.Objects.Insert insertRequest =
      client.objects().insert(bucketName, objectMetadata, contentStream);

  return insertRequest.execute().getMediaLink();
}
 

开发者ID:ciandt-dev,
项目名称:tech-gallery,
代码行数:31,
代码来源:StorageHandler.java

示例3: uploadFile

点赞 3

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
/**
 * Uploads data to an object in a bucket.
 *
 * @param name the name of the destination object.
 * @param contentType the MIME type of the data.
 * @param file the file to upload.
 * @param bucketName the name of the bucket to create the object in.
 */
public static void uploadFile(
    String name, String contentType, File file, String bucketName)
    throws IOException, GeneralSecurityException {
  InputStreamContent contentStream = new InputStreamContent(
      contentType, new FileInputStream(file));
  // Setting the length improves upload performance
  contentStream.setLength(file.length());
  StorageObject objectMetadata = new StorageObject()
      // Set the destination object name
      .setName(name)
      // Set the access control list to publicly read-only
      .setAcl(Arrays.asList(
          new ObjectAccessControl().setEntity("allUsers").setRole("READER")));

  // Do the insert
  Storage client = StorageFactory.getService();
  Storage.Objects.Insert insertRequest = client.objects().insert(
      bucketName, objectMetadata, contentStream);

  insertRequest.execute();
}
 

开发者ID:GoogleCloudPlatform,
项目名称:java-docs-samples,
代码行数:30,
代码来源:StorageSample.java

示例4: addPublicReadAccess

点赞 3

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
private static List<ObjectAccessControl> addPublicReadAccess(
    List<ObjectAccessControl> defaultAcl) {
  List<ObjectAccessControl> acl = Lists.newArrayList(defaultAcl);
  final String publicEntity = "allUsers";
  boolean alreadyShared = Iterables.tryFind(acl,
      new Predicate<ObjectAccessControl>() {
        @Override
        public boolean apply(ObjectAccessControl access) {
          return Objects.equal(access.getEntity(), publicEntity);
        }
      }).isPresent();
  /* If the entity 'allUsers' didn't already has READER or OWNER access, grant
     READER. This is to avoid having both an OWNER record and a READER record
     for that same entity */
  if (!alreadyShared) {
    acl.add(new ObjectAccessControl()
        .setEntity("allUsers")
        .setRole("READER"));
  }
  return acl;
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:22,
代码来源:AbstractUpload.java

示例5: getDefaultObjectAcl

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
private static List<ObjectAccessControl> getDefaultObjectAcl(Bucket bucket,
    TaskListener listener) {
  List<ObjectAccessControl> defaultAcl = bucket.getDefaultObjectAcl();
  if (defaultAcl == null) {
    listener.error(Messages.AbstractUpload_BucketObjectAclsError(
        bucket.getName()));
    return ImmutableList.of();
  } else {
    return defaultAcl;
  }
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:12,
代码来源:AbstractUpload.java

示例6: testRetryOn401

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
@Test
public void testRetryOn401() throws Exception {
  final boolean sharedPublicly = false;
  final boolean forFailedJobs = true;
  final boolean showInline = false;
  final String pathPrefix = null;

  Bucket bucket = new Bucket();
  bucket.setName(BUCKET_NAME);
  bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));

  final AbstractUpload.UploadSpec uploads =
      new AbstractUpload.UploadSpec(workspace,
          ImmutableList.of(workspaceFile, workspaceFile2));

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      sharedPublicly, forFailedJobs, showInline, pathPrefix,
      new MockUploadModule(executor), /* no retries */
      FAKE_DETAILS,
      uploads);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.passThruWhen(Storage.Buckets.Insert.class,
      MockUploadModule.checkBucketName(BUCKET_NAME));
  executor.passThruWhen(Storage.Objects.Insert.class,
      MockUploadModule.checkObjectName(FILENAME));
  executor.throwWhen(Storage.Objects.Insert.class,
      httpResponseException,
      MockUploadModule.checkObjectName(FILENAME2));
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Objects.Insert.class,
      MockUploadModule.checkObjectName(FILENAME2));

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:36,
代码来源:AbstractUploadTest.java

示例7: testRetryOn401StillFails

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
@Test(expected = UploadException.class)
public void testRetryOn401StillFails() throws Exception {
  final boolean sharedPublicly = false;
  final boolean forFailedJobs = true;
  final boolean showInline = false;
  final String pathPrefix = null;

  Bucket bucket = new Bucket();
  bucket.setName(BUCKET_NAME);
  bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));

  final AbstractUpload.UploadSpec uploads =
      new AbstractUpload.UploadSpec(workspace,
          ImmutableList.of(workspaceFile));

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      sharedPublicly, forFailedJobs, showInline, pathPrefix,
      new MockUploadModule(executor), /* no retries */
      FAKE_DETAILS,
      uploads);

  int maxRetriesPlus1 =
      RetryStorageOperation.MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES + 1;

  for (int i = 0; i < maxRetriesPlus1; i++) {
    executor.when(Storage.Buckets.Get.class, bucket);
    executor.throwWhen(Storage.Objects.Insert.class,
        httpResponseException,
        MockUploadModule.checkObjectName(FILENAME));
  }

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:34,
代码来源:AbstractUploadTest.java

示例8: testBucketConflict

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
@Test
public void testBucketConflict() throws Exception {
  final boolean sharedPublicly = false;
  final boolean forFailedJobs = true;
  final boolean showInline = false;
  final String pathPrefix = null;

  final AbstractUpload.UploadSpec uploads =
      new AbstractUpload.UploadSpec(workspace, ImmutableList.<FilePath>of());

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      sharedPublicly, forFailedJobs, showInline, pathPrefix,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      uploads);

  Bucket bucket = new Bucket();
  bucket.setName(BUCKET_NAME);
  bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.throwWhen(Storage.Buckets.Insert.class, conflictException,
      MockUploadModule.checkBucketName(BUCKET_NAME));
  executor.when(Storage.Buckets.Get.class, bucket);

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:28,
代码来源:AbstractUploadTest.java

示例9: testNotShared

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
@Test
public void testNotShared() throws Exception {
  final boolean sharedPublicly = false;
  final boolean forFailedJobs = true;
  final boolean showInline = false;
  final String pathPrefix = null;

  final AbstractUpload.UploadSpec uploads =
      new AbstractUpload.UploadSpec(workspace,
          ImmutableList.of(workspaceFile));

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      sharedPublicly, forFailedJobs, showInline, pathPrefix,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      uploads);

  Bucket bucket = new Bucket();
  bucket.setName(BUCKET_NAME);
  bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));

  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Objects.Insert.class,
      new Predicate<Storage.Objects.Insert>() {
        @Override
        public boolean apply(Storage.Objects.Insert operation) {
          StorageObject object = (StorageObject) operation.getJsonContent();

          assertNull(object.getAcl());
          return true;
        }
      });

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:36,
代码来源:AbstractUploadTest.java

示例10: testSharedPublicly

点赞 2

import com.google.api.services.storage.model.ObjectAccessControl; //导入依赖的package包/类
@Test
public void testSharedPublicly() throws Exception {
  final boolean sharedPublicly = true;
  final boolean forFailedJobs = true;
  final boolean showInline = false;
  final String pathPrefix = null;

  final AbstractUpload.UploadSpec uploads =
      new AbstractUpload.UploadSpec(workspace,
          ImmutableList.of(workspaceFile));

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      sharedPublicly, forFailedJobs, showInline, pathPrefix,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      uploads);

  final Bucket bucket = new Bucket();
  bucket.setName(BUCKET_NAME);
  bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));

  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Objects.Insert.class,
      new Predicate<Storage.Objects.Insert>() {
        @Override
        public boolean apply(Storage.Objects.Insert operation) {
          StorageObject object = (StorageObject) operation.getJsonContent();

          assertTrue(object.getAcl().containsAll(
              bucket.getDefaultObjectAcl()));

          List<ObjectAccessControl> addedAcl =
              Lists.newArrayList(Iterables.filter(
                  object.getAcl(), not(in(bucket.getDefaultObjectAcl()))));
          Set<String> addedEntities = Sets.newHashSet();
          for (ObjectAccessControl access : addedAcl) {
            assertEquals("READER", access.getRole());
            addedEntities.add(access.getEntity());
          }
          assertTrue(addedEntities.contains("allUsers"));
          return true;
        }
      });

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 

开发者ID:jenkinsci,
项目名称:google-storage-plugin,
代码行数:47,
代码来源:AbstractUploadTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)