Package org.jclouds.s3.options

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


    */
   @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;
   }

    *           bucket name
    */
   @Override
   // TODO get rid of transform, as it serializes async results when the executor is single-threaded.
   public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
      ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
      ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions);
      ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, bucket2ResourceList,
            userExecutor);
      return (options.isDetailed()) ? transform(list,
            fetchBlobMetadataProvider.get().setContainerName(container), userExecutor) : list;

    * @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;
   }

    *           bucket name
    */
   @Override
   // TODO get rid of transform, as it serializes async results when the executor is single-threaded.
   public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
      ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
      ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions);
      ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, bucket2ResourceList,
            userExecutor);
      return (options.isDetailed()) ? transform(list,
            fetchBlobMetadataProvider.get().setContainerName(container), userExecutor) : list;

    *           bucket name
    */
   @Override
   // TODO get rid of transform, as it serializes async results when the executor is single-threaded.
   public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
      ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
      ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions);
      ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, bucket2ResourceList,
            userExecutor);
      return (options.isDetailed()) ? transform(list,
            fetchBlobMetadataProvider.get().setContainerName(container), userExecutor) : list;

    *            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;
   }

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.