Coverage Report - org.apache.creadur.whisker.app.load.StreamableClassPathResource
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamableClassPathResource
0%
0/6
N/A
1
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF 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  
  */
 19  
 package org.apache.creadur.whisker.app.load;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.io.InputStream;
 23  
 
 24  
 import org.apache.creadur.whisker.app.StreamableResource;
 25  
 
 26  
 /**
 27  
  * Streams, on demand, the contents of a resource located on the class path.
 28  
  */
 29  
 public class StreamableClassPathResource extends StreamableResource {
 30  
 
 31  
     /** The full name <strong>including path</strong> of a resource on the class path */
 32  
     private final String name;
 33  
   
 34  
     /**
 35  
      * Constructs an instance that streams the given class path resource
 36  
      * on demand.
 37  
      * @param name full name <strong>including path</strong> of 
 38  
      * a resource on the class path,
 39  
      * not null
 40  
      */
 41  
     public StreamableClassPathResource(String name) {
 42  0
         super();
 43  0
         this.name = name;
 44  0
     }
 45  
 
 46  
     
 47  
     /**
 48  
      * Gets the location on the class path of the resource to be streamed.
 49  
      * @return not null
 50  
      */
 51  
     public String getName() {
 52  0
         return name;
 53  
     }
 54  
 
 55  
 
 56  
 
 57  
     /**
 58  
      * @see StreamableResource#open()
 59  
      */
 60  
     @Override
 61  
     public InputStream open() throws IOException {
 62  0
         return getClass().getClassLoader().getResourceAsStream(name);
 63  
     }
 64  
     
 65  
     @Override
 66  
     public String toString() {
 67  0
         return "StreamableClassPathResource [name=" + name + "]";
 68  
     }
 69  
 }