Package org.jclouds.s3.options

Examples of org.jclouds.s3.options.ListBucketOptions$Builder


    *            if anything goes wrong
    */
   @Test
   public void testSinglePageResult() throws Exception {
      S3Client api = createMock(S3Client.class);
      ListBucketOptions options = new ListBucketOptions();
      ListBucketResponse response = new ListBucketHandlerTest().expected();

      expect(api.listBucket("bucket", options)).andReturn(response).once();

      EasyMock.replay(api);


    */
   @Test
   public void testMultiPageResult() throws Exception {
      String nextMarker = "FOO";
      S3Client api = createMock(S3Client.class);
      ListBucketOptions options = new ListBucketOptions();
      ListBucketResponse response2 = new ListBucketHandlerTest().expected();
      ListBucketResponse response1 = new ListBucketResponseImpl(response2.getName(), response2, response2.getPrefix(),
            null, nextMarker, response2.getMaxKeys(), response2.getDelimiter(), false, response2.getCommonPrefixes());

      expect(api.listBucket("bucket", options)).andReturn(response1).once();
      expect(api.listBucket("bucket", options.afterMarker(nextMarker))).andReturn(response2).once();

      EasyMock.replay(api);

      PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options);


@Singleton
public class ContainerToBucketListOptions implements
         Function<ListContainerOptions, ListBucketOptions> {
   public ListBucketOptions apply(ListContainerOptions from) {
      checkNotNull(from, "set options to instance NONE instead of passing null");
      ListBucketOptions httpOptions = new ListBucketOptions();
      if (!from.isRecursive()) {
         httpOptions.delimiter("/");
      }
      if (from.getDir() != null) {// TODO unit test
         String path = from.getDir();
         if (!path.endsWith("/"))
            path = path + "/";
         httpOptions.withPrefix(path);
      }
      if (from.getMarker() != null) {
         httpOptions.afterMarker(from.getMarker());
      }
      if (from.getMaxResults() != null) {
         httpOptions.maxResults(from.getMaxResults());
      }
      return httpOptions;
   }

    * @param container
    *           bucket name
    */
   @Override
   public PageSet<? extends StorageMetadata> list(String container, ListContainerOptions options) {
      ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
      PageSet<? extends StorageMetadata> list = bucket2ResourceList.apply(sync.listBucket(container, httpOptions));
      return options.isDetailed() ? fetchBlobMetadataProvider.get().setContainerName(container).apply(list) : list;
   }

   @Override
   public ListenableFuture<Boolean> putBucketInRegion(@Nullable String region, String name,
            PutBucketOptions... optionsList) {
      region = region == null ? Region.US_STANDARD : region;
      final PutBucketOptions options = (optionsList.length == 0) ? new PutBucketOptions() : optionsList[0];
      keyToAcl.put(name, options.getAcl());
      return blobStore.createContainerInLocation(new LocationBuilder().scope(LocationScope.REGION).id(region)
               .description(region).build(), name);
   }

   @Override
   public ListenableFuture<Boolean> putBucketInRegion(@Nullable String region, String name,
            PutBucketOptions... optionsList) {
      region = region == null ? Region.US_STANDARD : region;
      final PutBucketOptions options = (optionsList.length == 0) ? new PutBucketOptions() : optionsList[0];
      keyToAcl.put(name, options.getAcl());
      return blobStore.createContainerInLocation(new LocationBuilder().scope(LocationScope.REGION).id(region)
               .description(region).build(), name);
   }

               + sourceObject));
   }

   public ListenableFuture<String> putObject(final String bucketName, final S3Object object,
            PutObjectOptions... nullableOptions) {
      final PutObjectOptions options = (nullableOptions.length == 0) ? new PutObjectOptions() : nullableOptions[0];
      if (options.getAcl() != null)
         keyToAcl.put(bucketName + "/" + object.getMetadata().getKey(), options.getAcl());
      return blobStore.putBlob(bucketName, object2Blob.apply(object));
   }

         object.getMetadata().setKey(publicReadWriteObjectKey);
         object.setPayload("");
         // Public Read-Write object
         getApi()
                  .putObject(containerName, object,
                           new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ_WRITE));

         assertConsistencyAware(new Runnable() {
            public void run() {
               try {
                  AccessControlList acl = getApi().getObjectACL(containerName, publicReadWriteObjectKey);

      final String containerName = getContainerName();
      try {
         S3Object object = getApi().newS3Object();
         object.getMetadata().setKey(publicReadObjectKey);
         object.setPayload("");
         getApi().putObject(containerName, object, new PutObjectOptions().withAcl(CannedAccessPolicy.PUBLIC_READ));

         assertConsistencyAware(new Runnable() {
            public void run() {
               try {
                  AccessControlList acl = getApi().getObjectACL(containerName, publicReadObjectKey);

               + sourceObject));
   }

   public ListenableFuture<String> putObject(final String bucketName, final S3Object object,
            PutObjectOptions... nullableOptions) {
      final PutObjectOptions options = (nullableOptions.length == 0) ? new PutObjectOptions() : nullableOptions[0];
      if (options.getAcl() != null)
         keyToAcl.put(bucketName + "/" + object.getMetadata().getKey(), options.getAcl());
      return blobStore.putBlob(bucketName, object2Blob.apply(object));
   }

TOP

Related Classes of org.jclouds.s3.options.ListBucketOptions$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.