Package org.jclouds.http.options

Examples of org.jclouds.http.options.GetOptions


*/
@Singleton
public class BlobToObjectGetOptions implements
         Function<org.jclouds.blobstore.options.GetOptions, GetOptions> {
   public GetOptions apply(org.jclouds.blobstore.options.GetOptions from) {
      GetOptions httpOptions = new GetOptions();
      if (from != null) {
         if (from.getIfMatch() != null) {
            httpOptions.ifETagMatches(from.getIfMatch());
         }
         if (from.getIfModifiedSince() != null) {
            httpOptions.ifModifiedSince(from.getIfModifiedSince());
         }
         if (from.getIfNoneMatch() != null) {
            httpOptions.ifETagDoesntMatch(from.getIfNoneMatch());
         }
         if (from.getIfUnmodifiedSince() != null) {
            httpOptions.ifUnmodifiedSince(from.getIfUnmodifiedSince());
         }
         for (String range : from.getRanges()) {
            String[] firstLast = range.split("\\-");
            if (firstLast.length == 2)
               httpOptions.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1]));
            else if (range.startsWith("-"))
               httpOptions.tail(Long.parseLong(firstLast[0]));
            else
               httpOptions.startAt(Long.parseLong(firstLast[0]));
         }
      }
      return httpOptions;
   }


    * @param key
    *           file name
    */
   @Override
   public Blob getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions optionsList) {
      GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
      return object2Blob.apply(sync.getObject(container, key, httpOptions));
   }

    * @param key
    *           object key
    */
   @Override
   public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
      GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
      ListenableFuture<SwiftObject> returnVal = async.getObject(container, key, httpOptions);
      return transform(returnVal, object2Blob, userExecutor);
   }

            @BinderParam(BindToStringPayload.class) String payload);
   }

   public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
      Date date = new Date();
      GetOptions options = GetOptions.Builder.ifModifiedSince(date);
      Invokable<?, ?> method = method(TestRequest.class, "get", String.class,
            HttpRequestOptions[].class);
      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of("1", options)));
      assertEquals(request.getEndpoint().getHost(), "localhost");

            ImmutableList.of(dateService.rfc822DateFormat(date)));
   }

   public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
      Date date = new Date();
      GetOptions options = GetOptions.Builder.ifModifiedSince(date);
      Invokable<?, ?> method = method(TestRequest.class, "get", String.class, HttpRequestOptions.class);
      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of("1", options)));
      assertEquals(request.getEndpoint().getHost(), "localhost");
      assertEquals(request.getEndpoint().getPath(), "/1");

   @Override
   public GetOptions apply(org.jclouds.blobstore.options.GetOptions from) {
      checkNotNull(from, "options");
      if (from == org.jclouds.blobstore.options.GetOptions.NONE)
         return GetOptions.NONE;
      GetOptions httpOptions = new GetOptions();
      if (from.getIfMatch() != null) {
         httpOptions.ifETagMatches(from.getIfMatch());
      }
      if (from.getIfModifiedSince() != null) {
         httpOptions.ifModifiedSince(from.getIfModifiedSince());
      }
      if (from.getIfNoneMatch() != null) {
         httpOptions.ifETagDoesntMatch(from.getIfNoneMatch());
      }
      if (from.getIfUnmodifiedSince() != null) {
         httpOptions.ifUnmodifiedSince(from.getIfUnmodifiedSince());
      }
      for (String range : from.getRanges()) {
         String[] firstLast = range.split("\\-", 2);
         if (!firstLast[0].isEmpty() && !firstLast[1].isEmpty())
            httpOptions.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1]));
         else if (firstLast[0].isEmpty() && !firstLast[1].isEmpty())
            httpOptions.tail(Long.parseLong(firstLast[1]));
         else
            httpOptions.startAt(Long.parseLong(firstLast[0]));
      }
      return httpOptions;
   }

      Date ifUnmodifiedSince = new Date(999999l);

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifUnmodifiedSince(ifUnmodifiedSince);
      GetOptions expected = new GetOptions();
      expected.ifUnmodifiedSince(ifUnmodifiedSince);

      assertEquals(fn.apply(in), expected);
   }

      Date ifModifiedSince = new Date(999999l);

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifModifiedSince(ifModifiedSince);
      GetOptions expected = new GetOptions();
      expected.ifModifiedSince(ifModifiedSince);

      assertEquals(fn.apply(in), expected);
   }

      String ifUnmatch = "foo";

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifETagDoesntMatch(ifUnmatch);
      GetOptions expected = new GetOptions();
      expected.ifETagDoesntMatch(ifUnmatch);

      assertEquals(fn.apply(in), expected);
   }

      String ifMatch = "foo";

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifETagMatches(ifMatch);
     
      GetOptions expected = new GetOptions();
      expected.ifETagMatches(ifMatch);

      assertEquals(fn.apply(in), expected);
   }

TOP

Related Classes of org.jclouds.http.options.GetOptions

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.