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

COVERAGE SUMMARY FOR SOURCE FILE [InputStreamSupplierPayload.java]

nameclass, %method, %block, %line, %
InputStreamSupplierPayload.java0%   (0/1)0%   (0/4)0%   (0/52)0%   (0/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InputStreamSupplierPayload0%   (0/1)0%   (0/4)0%   (0/52)0%   (0/14)
InputStreamSupplierPayload (InputSupplier): void 0%   (0/1)0%   (0/7)0%   (0/3)
getInput (): InputStream 0%   (0/1)0%   (0/19)0%   (0/6)
isRepeatable (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
release (): void 0%   (0/1)0%   (0/24)0%   (0/4)

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.io.payloads;
20 
21import static com.google.common.io.Closeables.closeQuietly;
22 
23import java.io.IOException;
24import java.io.InputStream;
25import java.util.List;
26 
27import com.google.common.base.Throwables;
28import com.google.common.collect.Lists;
29import com.google.common.io.InputSupplier;
30 
31/**
32 * @author Adrian Cole
33 */
34public class InputStreamSupplierPayload extends BasePayload<InputSupplier<? extends InputStream>> {
35   private List<InputStream> toClose = Lists.newArrayList();
36 
37   public InputStreamSupplierPayload(InputSupplier<? extends InputStream> content) {
38      super(content);
39   }
40 
41   /**
42    * {@inheritDoc}
43    */
44   @Override
45   public InputStream getInput() {
46      try {
47         InputStream returnVal = content.getInput();
48         toClose.add(returnVal);
49         return returnVal;
50      } catch (IOException e) {
51         Throwables.propagate(e);
52         return null;
53      }
54   }
55 
56   /**
57    * {@inheritDoc}
58    */
59   @Override
60   public boolean isRepeatable() {
61      return true;
62   }
63 
64   /**
65    * if we created the stream, then it is already consumed on close.
66    */
67   @Override
68   public void release() {
69      if (toClose.size() > 0)
70         for (InputStream content = toClose.remove(0); toClose.size() > 0; content = toClose.remove(0))
71            closeQuietly(content);
72   }
73 
74}

[all classes][org.jclouds.io.payloads]
EMMA 2.0.5312 (C) Vladimir Roubtsov