EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.io]

COVERAGE SUMMARY FOR SOURCE FILE [InputSuppliers.java]

nameclass, %method, %block, %line, %
InputSuppliers.java67%  (2/3)60%  (6/10)70%  (48/69)64%  (9/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InputSuppliers$10%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
InputSuppliers$1 (InputStream): void 0%   (0/1)0%   (0/6)0%   (0/1)
getInput (): InputStream 0%   (0/1)0%   (0/3)0%   (0/1)
     
class InputSuppliers100% (1/1)67%  (4/6)68%  (26/38)50%  (4/8)
InputSuppliers (): void 0%   (0/1)0%   (0/3)0%   (0/2)
of (InputStream): InputSupplier 0%   (0/1)0%   (0/9)0%   (0/2)
base64Decoder (InputSupplier): InputSuppliers$Base64InputSupplier 100% (1/1)100% (6/6)100% (1/1)
base64Encoder (InputSupplier): InputSuppliers$Base64InputSupplier 100% (1/1)100% (6/6)100% (1/1)
of (String): InputSupplier 100% (1/1)100% (8/8)100% (1/1)
of (byte []): InputSupplier 100% (1/1)100% (6/6)100% (1/1)
     
class InputSuppliers$Base64InputSupplier100% (1/1)100% (2/2)100% (22/22)100% (5/5)
InputSuppliers$Base64InputSupplier (InputSupplier, int): void 100% (1/1)100% (12/12)100% (4/4)
getInput (): InputStream 100% (1/1)100% (10/10)100% (1/1)

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.io;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.io.IOException;
24import java.io.InputStream;
25 
26import org.jclouds.encryption.internal.Base64;
27 
28import com.google.common.annotations.Beta;
29import com.google.common.annotations.VisibleForTesting;
30import com.google.common.base.Charsets;
31import com.google.common.io.ByteStreams;
32import com.google.common.io.InputSupplier;
33 
34/**
35 * functions related to or replacing those in {@link com.google.common.io.InputSupplier}
36 * 
37 * @author Adrian Cole
38 */
39@Beta
40public class InputSuppliers {
41   /**
42    * base64 encodes bytes from the supplied supplier as they are read.
43    */
44   public static Base64InputSupplier base64Encoder(InputSupplier<? extends InputStream> supplier) throws IOException {
45      return new Base64InputSupplier(supplier, Base64.ENCODE + Base64.DONT_BREAK_LINES);
46   }
47 
48   /**
49    * base64 decodes bytes from the supplied supplier as they are read.
50    */
51   public static Base64InputSupplier base64Decoder(InputSupplier<? extends InputStream> supplier) throws IOException {
52      return new Base64InputSupplier(supplier, Base64.DECODE);
53   }
54 
55   @VisibleForTesting
56   static class Base64InputSupplier implements InputSupplier<InputStream> {
57 
58      private final InputSupplier<? extends InputStream> delegate;
59      private final int mode;
60 
61      Base64InputSupplier(InputSupplier<? extends InputStream> inputSupplier, int mode) {
62         this.delegate = checkNotNull(inputSupplier, "delegate");
63         this.mode = mode;
64      }
65 
66      @Override
67      public InputStream getInput() throws IOException {
68         return new Base64.InputStream(delegate.getInput(), mode);
69      }
70 
71   }
72 
73   public static InputSupplier<? extends InputStream> of(final InputStream in) {
74      checkNotNull(in, "in");
75      return new InputSupplier<InputStream>() {
76 
77         @Override
78         public InputStream getInput() throws IOException {
79            return in;
80         }
81 
82      };
83   }
84 
85   public static InputSupplier<? extends InputStream> of(byte[] in) {
86      return ByteStreams.newInputStreamSupplier(checkNotNull(in, "in"));
87   }
88 
89   public static InputSupplier<? extends InputStream> of(String in) {
90      return of(checkNotNull(in, "in").getBytes(Charsets.UTF_8));
91   }
92}

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