Coverage Report - org.apache.maven.index.util.zip.JavaZipFileHandle
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaZipFileHandle
90 %
20/22
70 %
7/10
1,625
JavaZipFileHandle$1
100 %
2/2
N/A
1,625
 
 1  
 package org.apache.maven.index.util.zip;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0    
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.io.InputStream;
 25  
 import java.util.ArrayList;
 26  
 import java.util.Enumeration;
 27  
 import java.util.List;
 28  
 import java.util.zip.ZipEntry;
 29  
 import java.util.zip.ZipFile;
 30  
 
 31  
 public class JavaZipFileHandle
 32  
     extends AbstractZipHandle
 33  
     implements ZipHandle
 34  
 {
 35  
     private final ZipFile zipFile;
 36  
 
 37  
     public JavaZipFileHandle( final File targetFile )
 38  
         throws IOException
 39  
     {
 40  6996
         super( targetFile );
 41  
 
 42  6996
         this.zipFile = new ZipFile( targetFile );
 43  6860
     }
 44  
 
 45  
     protected ZipFile getZipFile()
 46  
     {
 47  22167
         return zipFile;
 48  
     }
 49  
 
 50  
     public boolean hasEntry( String path )
 51  
         throws IOException
 52  
     {
 53  12140
         return getZipFile().getEntry( path ) != null;
 54  
     }
 55  
 
 56  
     public List<String> getEntries()
 57  
     {
 58  2223
         return getEntries( new EntryNameFilter()
 59  2223
         {
 60  
             public boolean accepts( String entryName )
 61  
             {
 62  168772
                 return true;
 63  
             }
 64  
         } );
 65  
     }
 66  
 
 67  
     public List<String> getEntries( EntryNameFilter filter )
 68  
     {
 69  2223
         ArrayList<String> entries = new ArrayList<String>();
 70  
 
 71  2223
         Enumeration<? extends ZipEntry> en = getZipFile().entries();
 72  
 
 73  170995
         while ( en.hasMoreElements() )
 74  
         {
 75  168772
             final ZipEntry e = en.nextElement();
 76  
 
 77  168772
             final String name = e.getName();
 78  
 
 79  168772
             if ( filter != null && !filter.accepts( name ) )
 80  
             {
 81  0
                 continue;
 82  
             }
 83  
 
 84  168772
             entries.add( name );
 85  168772
         }
 86  
 
 87  2223
         return entries;
 88  
     }
 89  
 
 90  
     public InputStream getEntryContent( String path )
 91  
         throws IOException
 92  
     {
 93  472
         ZipEntry entry = getZipFile().getEntry( path );
 94  
 
 95  472
         if ( entry != null )
 96  
         {
 97  472
             return getZipFile().getInputStream( entry );
 98  
         }
 99  
         else
 100  
         {
 101  0
             return null;
 102  
         }
 103  
     }
 104  
 
 105  
     public void close()
 106  
         throws IOException
 107  
     {
 108  6860
         getZipFile().close();
 109  6860
     }
 110  
 }