Coverage Report - org.apache.maven.index.util.zip.TrueZipZipFileHandle
 
Classes in this File Line Coverage Branch Coverage Complexity
TrueZipZipFileHandle
0 %
0/22
0 %
0/10
1,625
TrueZipZipFileHandle$1
0 %
0/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  
 
 29  
 import de.schlichtherle.truezip.zip.ZipEntry;
 30  
 import de.schlichtherle.truezip.zip.ZipFile;
 31  
 
 32  
 public class TrueZipZipFileHandle
 33  
     extends AbstractZipHandle
 34  
     implements ZipHandle
 35  
 {
 36  
     private final ZipFile zipFile;
 37  
 
 38  
     public TrueZipZipFileHandle( final File targetFile )
 39  
         throws IOException
 40  
     {
 41  0
         super( targetFile );
 42  
 
 43  0
         this.zipFile = new ZipFile( targetFile );
 44  0
     }
 45  
 
 46  
     protected ZipFile getZipFile()
 47  
     {
 48  0
         return zipFile;
 49  
     }
 50  
 
 51  
     public boolean hasEntry( String path )
 52  
         throws IOException
 53  
     {
 54  0
         return getZipFile().getEntry( path ) != null;
 55  
     }
 56  
 
 57  
     public List<String> getEntries()
 58  
     {
 59  0
         return getEntries( new EntryNameFilter()
 60  0
         {
 61  
             public boolean accepts( String entryName )
 62  
             {
 63  0
                 return true;
 64  
             }
 65  
         } );
 66  
     }
 67  
 
 68  
     public List<String> getEntries( EntryNameFilter filter )
 69  
     {
 70  0
         ArrayList<String> entries = new ArrayList<String>();
 71  
 
 72  0
         Enumeration<? extends ZipEntry> en = getZipFile().entries();
 73  
 
 74  0
         while ( en.hasMoreElements() )
 75  
         {
 76  0
             final ZipEntry e = en.nextElement();
 77  
 
 78  0
             final String name = e.getName();
 79  
 
 80  0
             if ( filter != null && !filter.accepts( name ) )
 81  
             {
 82  0
                 continue;
 83  
             }
 84  
 
 85  0
             entries.add( name );
 86  0
         }
 87  
 
 88  0
         return entries;
 89  
     }
 90  
 
 91  
     public InputStream getEntryContent( String path )
 92  
         throws IOException
 93  
     {
 94  0
         ZipEntry entry = getZipFile().getEntry( path );
 95  
 
 96  0
         if ( entry != null )
 97  
         {
 98  0
             return getZipFile().getInputStream( entry );
 99  
         }
 100  
         else
 101  
         {
 102  0
             return null;
 103  
         }
 104  
     }
 105  
 
 106  
     public void close()
 107  
         throws IOException
 108  
     {
 109  0
         getZipFile().close();
 110  0
     }
 111  
 
 112  
 }