Package org.jclouds.io

Examples of org.jclouds.io.Payload


    * @throws IOException
    */
   public static byte[] closeClientButKeepContentStream(PayloadEnclosing response) {
      byte[] returnVal = toByteArrayOrNull(response);
      if (returnVal != null && !response.getPayload().isRepeatable()) {
         Payload newPayload = Payloads.newByteArrayPayload(returnVal);
         MutableContentMetadata fromMd = response.getPayload().getContentMetadata();
         MutableContentMetadata toMd = newPayload.getContentMetadata();
         copy(fromMd, toMd);
         response.setPayload(newPayload);
      }
      return returnVal;
   }
View Full Code Here


               }

            };
         HttpRequestBase.class.cast(apacheRequest).setURI(request.getEndpoint());
      }
      Payload payload = request.getPayload();

      // Since we may remove headers, ensure they are added to the apache
      // request after this block
      if (apacheRequest instanceof HttpEntityEnclosingRequest) {
         if (payload != null) {
View Full Code Here

   @Override
   protected HttpResponse invoke(HttpUriRequest nativeRequest) throws IOException {
      org.apache.http.HttpResponse apacheResponse = executeRequest(nativeRequest);

      Payload payload = null;
      if (apacheResponse.getEntity() != null)
         try {
            payload = Payloads.newInputStreamPayload(consumeOnClose(apacheResponse.getEntity().getContent()));
            if (apacheResponse.getEntity().getContentLength() >= 0)
               payload.getContentMetadata().setContentLength(apacheResponse.getEntity().getContentLength());
            if (apacheResponse.getEntity().getContentType() != null)
               payload.getContentMetadata().setContentType(apacheResponse.getEntity().getContentType().getValue());
         } catch (IOException e) {
            logger.warn(e, "couldn't receive payload for request: %s", nativeRequest.getRequestLine());
            throw e;
         }
      Multimap<String, String> headers = LinkedHashMultimap.create();
      for (Header header : apacheResponse.getAllHeaders()) {
         headers.put(header.getName(), header.getValue());
      }
      if (payload != null) {
         contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers);
      }
      return HttpResponse.builder().statusCode(apacheResponse.getStatusLine().getStatusCode())
                                   .message(apacheResponse.getStatusLine().getReasonPhrase())
                                   .payload(payload)
                                   .headers(filterOutContentHeaders(headers)).build();
View Full Code Here

         String uploadId = getApi().initiateMultipartUpload(containerName,
                  ObjectMetadataBuilder.create().key(key).contentMD5(oneHundredOneConstitutionsMD5).build());
         byte[] buffer = toByteArray(oneHundredOneConstitutions);
         assertEquals(oneHundredOneConstitutionsLength, (long) buffer.length);

         Payload part1 = newByteArrayPayload(buffer);
         part1.getContentMetadata().setContentLength((long) buffer.length);
         part1.getContentMetadata().setContentMD5(oneHundredOneConstitutionsMD5);

         String eTagOf1 = null;
         try {
            eTagOf1 = getApi().uploadPart(containerName, key, 1, uploadId, part1);
         } catch (KeyNotFoundException e) {
View Full Code Here

public class BindAzureBlobMetadataToRequestTest extends BaseAsyncClientTest<AzureBlobAsyncClient> {

   @Test
   public void testPassWithMinimumDetailsAndPayload64MB() {
      AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(64 * 1024 * 1024l);
      blob.setPayload(payload);
      blob.getProperties().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindAzureBlobMetadataToRequest binder = injector.getInstance(BindAzureBlobMetadataToRequest.class);
View Full Code Here

   }

   @Test
   public void testExtendedPropertiesBind() {
      AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(64 * 1024 * 1024l);
      blob.setPayload(payload);
      blob.getProperties().setName("foo");
      blob.getProperties().setMetadata(ImmutableMap.of("foo", "bar"));

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
View Full Code Here

   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testNoContentLengthIsBad() {
      AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(null);
      blob.setPayload(payload);
      blob.getProperties().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindAzureBlobMetadataToRequest binder = injector.getInstance(BindAzureBlobMetadataToRequest.class);
View Full Code Here

   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testNoNameIsBad() {
      AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(5368709120000l);
      blob.setPayload(payload);

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindAzureBlobMetadataToRequest binder = injector.getInstance(BindAzureBlobMetadataToRequest.class);
      binder.bindToRequest(request, blob);
View Full Code Here

   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testOver64MBIsBad() {
      AzureBlob blob = injector.getInstance(AzureBlob.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(64 * 1024 * 1024l + 1);
      blob.setPayload(payload);
      blob.getProperties().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindAzureBlobMetadataToRequest binder = injector.getInstance(BindAzureBlobMetadataToRequest.class);
View Full Code Here

      File payloadFile = File.createTempFile("testPutFileParallel", "png");
      Files.copy(createTestInput(), payloadFile);
      payloadFile.deleteOnExit();
     
      final Payload testPayload = Payloads.newFilePayload(payloadFile);
      final byte[] md5 = md5Supplier(testPayload);
      testPayload.getContentMetadata().setContentType("image/png");
     
      final AtomicInteger blobCount = new AtomicInteger();
      final String container = getContainerName();
      try {
         Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
View Full Code Here

TOP

Related Classes of org.jclouds.io.Payload

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.