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 | 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 | |
} |