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