Coverage Report - org.apache.commons.classscan.builtin.JarResourceFile
 
Classes in this File Line Coverage Branch Coverage Complexity
JarResourceFile
0%
0/7
N/A
1
JarResourceFile$1
0%
0/4
N/A
1
 
 1  
 /*
 2  
  * Licensed under the Apache License, Version 2.0 (the "License");
 3  
  * you may not use this file except in compliance with the License.
 4  
  * You may obtain a copy of the License at
 5  
  *
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package org.apache.commons.classscan.builtin;
 15  
 
 16  
 import java.io.FilterInputStream;
 17  
 import java.io.IOException;
 18  
 import java.io.InputStream;
 19  
 import java.util.jar.JarEntry;
 20  
 import java.util.jar.JarFile;
 21  
 
 22  
 import org.apache.commons.classscan.ResourceFile;
 23  
 
 24  
 public class JarResourceFile implements ResourceFile {
 25  
 
 26  
         final JarFile jarFile;
 27  
         final JarEntry jarEntry;
 28  
 
 29  0
         public JarResourceFile(JarFile jarFile, JarEntry jarEntry) {
 30  0
                 this.jarFile = jarFile;
 31  0
                 this.jarEntry = jarEntry;
 32  0
         }
 33  
 
 34  
         @Override
 35  
         public InputStream getBytes() throws IOException {
 36  0
                 final InputStream is = jarFile.getInputStream(jarEntry);
 37  
                 // close the jarFile when stream is closed
 38  0
                 return new FilterInputStream(is) {
 39  
                         @Override
 40  
                         public void close() throws IOException {
 41  0
                                 super.close();
 42  0
                                 jarFile.close();
 43  0
                         }
 44  
                 };
 45  
         }
 46  
 
 47  
         @Override
 48  
         public String getFileName() {
 49  0
                 return jarEntry.getName();
 50  
         }
 51  
 }