Coverage Report - org.apache.maven.index.util.zip.ZipFacade
 
Classes in this File Line Coverage Branch Coverage Complexity
ZipFacade
75 %
12/16
75 %
6/8
4,5
 
 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  
 
 25  0
 public class ZipFacade
 26  
 {
 27  
     public static final long MEGABYTE = 1048576L;
 28  
 
 29  1
     public static final long JAVA_ZIPFILE_SIZE_THRESHOLD = Long.getLong(
 30  
         "org.apache.maven.index.util.zip.ZipFacade.javaZipFileSizeThreshold", 100L * MEGABYTE );
 31  
 
 32  
     private static final boolean TRUEZIP_AVAILABLE;
 33  
 
 34  
     static
 35  
     {
 36  
         Class<?> clazz;
 37  
 
 38  
         try
 39  
         {
 40  1
             clazz = Class.forName( "de.schlichtherle.truezip.zip.ZipFile" );
 41  
         }
 42  0
         catch ( ClassNotFoundException e )
 43  
         {
 44  0
             clazz = null;
 45  1
         }
 46  
 
 47  1
         TRUEZIP_AVAILABLE = clazz != null;
 48  1
     }
 49  
 
 50  
     public static ZipHandle getZipHandle( File targetFile )
 51  
         throws IOException
 52  
     {
 53  7022
         if ( targetFile.isFile() )
 54  
         {
 55  6996
             if ( TRUEZIP_AVAILABLE && targetFile.length() > JAVA_ZIPFILE_SIZE_THRESHOLD )
 56  
             {
 57  0
                 return new TrueZipZipFileHandle( targetFile );
 58  
             }
 59  
             else
 60  
             {
 61  6996
                 return new JavaZipFileHandle( targetFile );
 62  
             }
 63  
         }
 64  
 
 65  26
         throw new IOException( "The targetFile should point to an existing ZIP file!" );
 66  
     }
 67  
 
 68  
     public static void close( ZipHandle handle )
 69  
         throws IOException
 70  
     {
 71  7022
         if ( handle != null )
 72  
         {
 73  6860
             handle.close();
 74  
         }
 75  7022
     }
 76  
 }