EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.aws.s3.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindObjectMetadataToRequest.java]

nameclass, %method, %block, %line, %
BindObjectMetadataToRequest.java100% (1/1)100% (2/2)82%  (89/108)86%  (19/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindObjectMetadataToRequest100% (1/1)100% (2/2)82%  (89/108)86%  (19/22)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)81%  (80/99)84%  (16/19)
BindObjectMetadataToRequest (BindMapToHeadersWithPrefix): void 100% (1/1)100% (9/9)100% (3/3)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.aws.s3.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static org.jclouds.crypto.CryptoStreams.base64;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27import javax.ws.rs.core.HttpHeaders;
28 
29import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
30import org.jclouds.http.HttpRequest;
31import org.jclouds.http.utils.ModifyRequest;
32import org.jclouds.rest.Binder;
33import org.jclouds.s3.domain.ObjectMetadata;
34 
35import com.google.common.collect.ImmutableMultimap;
36import com.google.common.collect.ImmutableMultimap.Builder;
37 
38/**
39 * 
40 * @author Adrian Cole
41 */
42@Singleton
43public class BindObjectMetadataToRequest implements Binder {
44   protected final BindMapToHeadersWithPrefix metadataPrefixer;
45 
46   @Inject
47   public BindObjectMetadataToRequest(BindMapToHeadersWithPrefix metadataPrefixer) {
48      this.metadataPrefixer = checkNotNull(metadataPrefixer, "metadataPrefixer");
49   }
50 
51   @Override
52   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
53      checkArgument(checkNotNull(input, "input") instanceof ObjectMetadata,
54               "this binder is only valid for ObjectMetadata!");
55      checkNotNull(request, "request");
56 
57      ObjectMetadata md = ObjectMetadata.class.cast(input);
58      checkArgument(md.getKey() != null, "objectMetadata.getKey() must be set!");
59 
60      request = metadataPrefixer.bindToRequest(request, md.getUserMetadata());
61 
62      Builder<String, String> headers = ImmutableMultimap.<String, String> builder();
63      if (md.getCacheControl() != null) {
64         headers.put(HttpHeaders.CACHE_CONTROL, md.getCacheControl());
65      }
66 
67      if (md.getContentMetadata().getContentDisposition() != null) {
68         headers.put("Content-Disposition", md.getContentMetadata().getContentDisposition());
69      }
70 
71      if (md.getContentMetadata().getContentEncoding() != null) {
72         headers.put("Content-Encoding", md.getContentMetadata().getContentEncoding());
73      }
74      if (md.getContentMetadata().getContentType() != null) {
75         headers.put(HttpHeaders.CONTENT_TYPE, md.getContentMetadata().getContentType());
76      } else {
77         headers.put(HttpHeaders.CONTENT_TYPE, "binary/octet-stream");
78      }
79 
80      if (md.getContentMetadata().getContentMD5() != null) {
81         headers.put("Content-MD5", base64(md.getContentMetadata().getContentMD5()));
82      }
83 
84      request = ModifyRequest.replaceHeaders(request, headers.build());
85      return request;
86   }
87}

[all classes][org.jclouds.aws.s3.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov