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

COVERAGE SUMMARY FOR SOURCE FILE [ParseSystemMetadataFromHeaders.java]

nameclass, %method, %block, %line, %
ParseSystemMetadataFromHeaders.java100% (1/1)100% (3/3)92%  (170/185)93%  (13.1/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseSystemMetadataFromHeaders100% (1/1)100% (3/3)92%  (170/185)93%  (13.1/14)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
apply (HttpResponse): SystemMetadata 100% (1/1)92%  (155/168)93%  (9.3/10)
ParseSystemMetadataFromHeaders (DateService): 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.atmos.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.atmos.domain.FileType;
29import org.jclouds.atmos.domain.SystemMetadata;
30import org.jclouds.atmos.reference.AtmosHeaders;
31import org.jclouds.crypto.CryptoStreams;
32import org.jclouds.date.DateService;
33import org.jclouds.http.HttpResponse;
34 
35import com.google.common.base.Function;
36import com.google.common.collect.Maps;
37 
38/**
39 * @author Adrian Cole
40 */
41@Singleton
42public class ParseSystemMetadataFromHeaders implements Function<HttpResponse, SystemMetadata> {
43   private final DateService dateService;
44 
45   @Inject
46   public ParseSystemMetadataFromHeaders(DateService dateService) {
47      this.dateService = checkNotNull(dateService, "dateService");
48   }
49 
50   public SystemMetadata apply(HttpResponse from) {
51      checkNotNull(from, "http response");
52      String meta = checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META);
53      Map<String, String> metaMap = Maps.newHashMap();
54      String[] metas = meta.split(", ");
55      for (String entry : metas) {
56         String[] entrySplit = entry.split("=");
57         metaMap.put(entrySplit[0], entrySplit[1]);
58      }
59      assert metaMap.size() >= 12 : String.format("Should be 12 entries in %s", metaMap);
60      byte[] md5 = metaMap.containsKey("content-md5") ? CryptoStreams.hex(metaMap.get("content-md5")) : null;
61      return new SystemMetadata(md5, dateService.iso8601SecondsDateParse(checkNotNull(metaMap.get("atime"), "atime")),
62            dateService.iso8601SecondsDateParse(checkNotNull(metaMap.get("ctime"), "ctime")), checkNotNull(
63                  metaMap.get("gid"), "gid"), dateService.iso8601SecondsDateParse(checkNotNull(metaMap.get("itime"),
64                  "itime")), dateService.iso8601SecondsDateParse(checkNotNull(metaMap.get("mtime"), "mtime")),
65            Integer.parseInt(checkNotNull(metaMap.get("nlink"), "nlink")), checkNotNull(metaMap.get("objectid"),
66                  "objectid"), checkNotNull(metaMap.get("objname"), "objname"), checkNotNull(metaMap.get("policyname"),
67                  "policyname"), Long.parseLong(checkNotNull(metaMap.get("size"), "size")),
68            FileType.fromValue(checkNotNull(metaMap.get("type"), "type")), checkNotNull(metaMap.get("uid"), "uid"));
69   }
70}

[all classes][org.jclouds.atmos.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov