Package org.jclouds.io

Examples of org.jclouds.io.MutableContentMetadata


   @Override
   public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
      try {
         String xml = xmlParser.toXML(checkNotNull(input, "input"));
         request.setPayload(xml);
         MutableContentMetadata metadata = request.getPayload().getContentMetadata();
         if (contentTypeMustBeAdded(metadata)) {
            metadata.setContentType("application/xml");
         }
         return request;
      } catch (IOException ex) {
         throw new BindException(request, ex);
      }
View Full Code Here


      if (connection.getRequestProperty(USER_AGENT) == null) {
          connection.setRequestProperty(USER_AGENT, DEFAULT_USER_AGENT);
      }
      Payload payload = request.getPayload();
      if (payload != null) {
         MutableContentMetadata md = payload.getContentMetadata();
         for (Map.Entry<String,String> entry : contentMetadataCodec.toHeaders(md).entries()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
         }
         if (chunked) {
            connection.setChunkedStreamingMode(8196);
            writePayloadToConnection(payload, "streaming", connection);
         } else {
            Long length = checkNotNull(md.getContentLength(), "payload.getContentLength");
            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6755625
            checkArgument(length < Integer.MAX_VALUE,
                  "JDK 1.6 does not support >2GB chunks. Use chunked encoding, if possible.");
            if (length > 0) {
               connection.setRequestProperty(CONTENT_LENGTH, length.toString());
View Full Code Here

         payload = (in.getPayload() instanceof DelegatingPayload) ? (DelegatingPayload.class.cast(in.getPayload())
                  .getDelegate() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(DelegatingPayload.class
                  .cast(in.getPayload()).getDelegate()) : null : null;
      try {
         if (payload == null || !(payload instanceof ByteArrayPayload)) {
            MutableContentMetadata oldMd = in.getPayload().getContentMetadata();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            in.getPayload().writeTo(out);
            payload = (ByteArrayPayload) Payloads.calculateMD5(Payloads.newPayload(out.toByteArray()));
            HttpUtils.copy(oldMd, payload.getContentMetadata());
         } else {
View Full Code Here

      copyPayloadMetadata(oldContent, wiredPayload);
      request.setPayload(wiredPayload);
   }

   private void copyPayloadMetadata(Payload oldContent, Payload wiredPayload) {
      MutableContentMetadata oldMd = oldContent.getContentMetadata();
      MutableContentMetadata wiredMd = wiredPayload.getContentMetadata();
      if (oldMd.getContentLength() != null)
         wiredMd.setContentLength(oldMd.getContentLength());
      wiredMd.setContentType(oldMd.getContentType());
      wiredMd.setContentMD5(oldMd.getContentMD5());
      wiredMd.setContentDisposition(oldMd.getContentDisposition());
      wiredMd.setContentEncoding(oldMd.getContentEncoding());
      wiredMd.setContentLanguage(oldMd.getContentLanguage());
      wiredMd.setExpires(oldMd.getExpires());
   }
View Full Code Here

    */
   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

      if (connection.getRequestProperty(USER_AGENT) == null) {
          connection.setRequestProperty(USER_AGENT, DEFAULT_USER_AGENT);
      }
      Payload payload = request.getPayload();
      if (payload != null) {
         MutableContentMetadata md = payload.getContentMetadata();
         for (Map.Entry<String, String> entry : contentMetadataCodec.toHeaders(md).entries()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
         }
         if (chunked) {
            connection.setChunkedStreamingMode(8196);
            writePayloadToConnection(payload, "streaming", connection);
         } else {
            Long length = checkNotNull(md.getContentLength(), "payload.getContentLength");
            if (length > 0) {
               connection.setRequestProperty(CONTENT_LENGTH, length.toString());
               if (length <= Integer.MAX_VALUE) {
                  connection.setFixedLengthStreamingMode(length.intValue());
               } else {
View Full Code Here

      }
   }

   protected void assertContentHeadersEqual(HttpRequest request, String contentType, String contentDispositon,
         String contentEncoding, String contentLanguage, Long length, byte[] contentMD5, Date expires) {
      MutableContentMetadata md = request.getPayload().getContentMetadata();
      if (request.getFirstHeaderOrNull(TRANSFER_ENCODING) == null) {
         assertEquals(md.getContentLength(), length);
      } else {
         assertEquals(request.getFirstHeaderOrNull(TRANSFER_ENCODING), "chunked");
         assert md.getContentLength() == null || md.getContentLength().equals(length);
      }
      assertEquals(md.getContentType(), contentType);
      assertEquals(md.getContentDisposition(), contentDispositon);
      assertEquals(md.getContentEncoding(), contentEncoding);
      assertEquals(md.getContentLanguage(), contentLanguage);
      assertEquals(md.getContentMD5(), contentMD5);
      assertEquals(md.getExpires(), expires);
   }
View Full Code Here

   @Override
   public SwiftObject apply(HttpResponse from) {

      Payload payload = from.getPayload();
      MutableContentMetadata contentMeta = payload.getContentMetadata();

      String deleteAt = from.getFirstHeaderOrNull(OBJECT_DELETE_AT);
      if (deleteAt != null) {
         long fromEpoch = Long.parseLong(from.getFirstHeaderOrNull(OBJECT_DELETE_AT)) * 1000;
         contentMeta.setExpires(new Date(fromEpoch));
         payload.setContentMetadata(contentMeta);
      }

      String etag = from.getFirstHeaderOrNull(ETAG);
      if (etag != null) {
View Full Code Here

         BlobRequestSigner signer = ctx.getSigner(regionId);
         HttpResponse response;
         try {
            HttpRequest putRequest;
            putRequest = signer.signPutBlob(containerName, blob2, 600);
            MutableContentMetadata metadata = blob2.getMetadata()
                  .getContentMetadata();
            HttpRequest.Builder<?> putRequestBuilder = putRequest.toBuilder()
                  .addHeader(HttpHeaders.CONTENT_TYPE,
                        metadata.getContentType());
            putRequestBuilder.addHeader(HttpHeaders.CONTENT_LENGTH,
                  String.valueOf(input.size()));
            putRequestBuilder.payload(input);
            putRequest = putRequestBuilder.build();
            Payload payload = Payloads.newPayload(input.read());
View Full Code Here

         apacheRequest.setEntity(entity);
      }
     
      // TODO Reproducing old behaviour exactly; ignoring Content-Type, Content-Length and Content-MD5
      Set<String> desiredHeaders = ImmutableSet.of("Content-Disposition", "Content-Encoding", "Content-Language", "Expires");
      MutableContentMetadata md = payload.getContentMetadata();
      for (Map.Entry<String, String> entry : contentMetadataCodec.toHeaders(md).entries()) {
         if (desiredHeaders.contains(entry.getKey())) {
            apacheRequest.addHeader(entry.getKey(), entry.getValue());
         }
      }
View Full Code Here

TOP

Related Classes of org.jclouds.io.MutableContentMetadata

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.