EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.http.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ReturnStringIf2xx.java]

nameclass, %method, %block, %line, %
ReturnStringIf2xx.java100% (1/1)100% (2/2)52%  (33/63)77%  (10/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ReturnStringIf2xx100% (1/1)100% (2/2)52%  (33/63)77%  (10/13)
apply (HttpResponse): String 100% (1/1)50%  (30/60)75%  (9/12)
ReturnStringIf2xx (): void 100% (1/1)100% (3/3)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.http.functions;
20 
21import static org.jclouds.http.HttpUtils.releasePayload;
22 
23import java.io.IOException;
24import java.io.InputStream;
25 
26import javax.inject.Singleton;
27 
28import org.jclouds.http.HttpException;
29import org.jclouds.http.HttpResponse;
30import org.jclouds.util.Strings2;
31 
32import com.google.common.base.Function;
33 
34/**
35 * 
36 * @author Adrian Cole
37 */
38@Singleton
39public class ReturnStringIf2xx implements Function<HttpResponse, String> {
40 
41   public String apply(HttpResponse from) {
42      if (from.getPayload() == null)
43         return null;
44      try {
45         if (from.getStatusCode() >= 200) {
46            InputStream payload = from.getPayload().getInput();
47            String toReturn = null;
48            try {
49               toReturn = Strings2.toStringAndClose(payload);
50            } catch (IOException e) {
51               throw new HttpException(String.format(
52                        "Couldn't receive response %1$s, payload: %2$s ", from, toReturn), e);
53            }
54            return toReturn;
55         } else {
56            throw new HttpException(String.format("Unhandled status code  - %1$s", from));
57         }
58      } finally {
59         releasePayload(from);
60      }
61   }
62 
63}

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