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 super( targetFile );
42
43 this.zipFile = new ZipFile( targetFile );
44 }
45
46 protected ZipFile getZipFile()
47 {
48 return zipFile;
49 }
50
51 public boolean hasEntry( String path )
52 throws IOException
53 {
54 return getZipFile().getEntry( path ) != null;
55 }
56
57 public List<String> getEntries()
58 {
59 return getEntries( new EntryNameFilter()
60 {
61 public boolean accepts( String entryName )
62 {
63 return true;
64 }
65 } );
66 }
67
68 public List<String> getEntries( EntryNameFilter filter )
69 {
70 ArrayList<String> entries = new ArrayList<String>();
71
72 Enumeration<? extends ZipEntry> en = getZipFile().entries();
73
74 while ( en.hasMoreElements() )
75 {
76 final ZipEntry e = en.nextElement();
77
78 final String name = e.getName();
79
80 if ( filter != null && !filter.accepts( name ) )
81 {
82 continue;
83 }
84
85 entries.add( name );
86 }
87
88 return entries;
89 }
90
91 public InputStream getEntryContent( String path )
92 throws IOException
93 {
94 ZipEntry entry = getZipFile().getEntry( path );
95
96 if ( entry != null )
97 {
98 return getZipFile().getInputStream( entry );
99 }
100 else
101 {
102 return null;
103 }
104 }
105
106 public void close()
107 throws IOException
108 {
109 getZipFile().close();
110 }
111
112 }