1 package org.apache.maven.index.util.zip;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 public class ZipFacade
26 {
27 public static final long MEGABYTE = 1048576L;
28
29 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 clazz = Class.forName( "de.schlichtherle.truezip.zip.ZipFile" );
41 }
42 catch ( ClassNotFoundException e )
43 {
44 clazz = null;
45 }
46
47 TRUEZIP_AVAILABLE = clazz != null;
48 }
49
50 public static ZipHandle getZipHandle( File targetFile )
51 throws IOException
52 {
53 if ( targetFile.isFile() )
54 {
55 if ( TRUEZIP_AVAILABLE && targetFile.length() > JAVA_ZIPFILE_SIZE_THRESHOLD )
56 {
57 return new TrueZipZipFileHandle( targetFile );
58 }
59 else
60 {
61 return new JavaZipFileHandle( targetFile );
62 }
63 }
64
65 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 if ( handle != null )
72 {
73 handle.close();
74 }
75 }
76 }