1
1
package org .codehaus .plexus .archiver .zip ;
2
2
3
+ import java .io .Closeable ;
3
4
import java .io .File ;
4
5
import java .io .IOException ;
5
6
import java .util .Enumeration ;
6
7
import java .util .Iterator ;
7
8
8
9
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
10
+ import org .apache .commons .compress .archivers .zip .ZipFile ;
9
11
import org .codehaus .plexus .components .io .resources .AbstractPlexusIoArchiveResourceCollection ;
10
12
import org .codehaus .plexus .components .io .resources .PlexusIoResource ;
11
13
@@ -26,26 +28,45 @@ protected Iterator<PlexusIoResource> getEntries()
26
28
{
27
29
throw new IOException ( "The tar archive file has not been set." );
28
30
}
29
- final org .apache .commons .compress .archivers .zip .ZipFile zipFile = new org .apache .commons .compress .archivers .zip .ZipFile ( f );
30
- final Enumeration en = zipFile .getEntries ();
31
- return new Iterator <PlexusIoResource >()
31
+ final ZipFile zipFile = new ZipFile ( f );
32
+ return new CloseableIterator ( zipFile );
33
+ }
34
+
35
+ class CloseableIterator
36
+ implements Iterator <PlexusIoResource >, Closeable
37
+ {
38
+ final Enumeration en ;
39
+
40
+ private final ZipFile zipFile ;
41
+
42
+ public CloseableIterator ( ZipFile zipFile )
43
+ {
44
+ this .en = zipFile .getEntriesInPhysicalOrder ();
45
+ this .zipFile = zipFile ;
46
+ }
47
+
48
+ public boolean hasNext ( ) {
49
+ return en .hasMoreElements ();
50
+ }
51
+
52
+ public PlexusIoResource next ()
32
53
{
33
- public boolean hasNext ()
34
- {
35
- return en .hasMoreElements ();
36
- }
37
-
38
- public PlexusIoResource next ()
39
- {
40
- final ZipArchiveEntry entry = (ZipArchiveEntry ) en .nextElement ();
41
-
42
- return new ZipResource ( zipFile , entry , getStreamTransformer () );
43
- }
44
-
45
- public void remove ()
46
- {
47
- throw new UnsupportedOperationException ( "Removing isn't implemented." );
48
- }
49
- };
54
+ final ZipArchiveEntry entry = (ZipArchiveEntry ) en .nextElement ();
55
+
56
+ return new ZipResource ( zipFile , entry , getStreamTransformer () );
57
+ }
58
+
59
+ public void remove ()
60
+ {
61
+ throw new UnsupportedOperationException ( "Removing isn't implemented." );
62
+ }
63
+
64
+ public void close ()
65
+ throws IOException
66
+ {
67
+ zipFile .close ();
68
+ }
50
69
}
70
+
71
+ ;
51
72
}
0 commit comments