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