@@ -108,6 +108,8 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
108
108
if (entry.isDirectory) ensureDir(dirs, entry.getName)
109
109
else ensureDir(dirs, dirName(entry.getName))
110
110
}
111
+
112
+ def close (): Unit
111
113
}
112
114
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
113
115
final class FileZipArchive (jpath : JPath ) extends ZipArchive (jpath) {
@@ -176,6 +178,7 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
176
178
}
177
179
} finally {
178
180
if (ZipArchive .closeZipFile) zipFile.close()
181
+ else closeables ::= zipFile
179
182
}
180
183
(root, dirs)
181
184
}
@@ -194,15 +197,23 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
194
197
case x : FileZipArchive => jpath.toAbsolutePath == x.jpath.toAbsolutePath
195
198
case _ => false
196
199
}
200
+
201
+ private [this ] var closeables : List [java.io.Closeable ] = Nil
202
+ override def close (): Unit = {
203
+ closeables.foreach(_.close)
204
+ }
197
205
}
198
206
199
207
final class ManifestResources (val url : URL ) extends ZipArchive (null ) {
200
208
def iterator (): Iterator [AbstractFile ] = {
201
209
val root = new DirEntry (" /" , null )
202
210
val dirs = mutable.HashMap [String , DirEntry ](" /" -> root)
203
- val manifest = new Manifest (input)
211
+ val stream = input
212
+ val manifest = new Manifest (stream)
204
213
val iter = manifest.getEntries().keySet().iterator().asScala.filter(_.endsWith(" .class" )).map(new ZipEntry (_))
205
214
215
+ closeables ::= stream
216
+
206
217
for (zipEntry <- iter) {
207
218
val dir = getDir(dirs, zipEntry)
208
219
if (! zipEntry.isDirectory) {
@@ -251,4 +262,9 @@ final class ManifestResources(val url: URL) extends ZipArchive(null) {
251
262
}
252
263
}
253
264
}
265
+
266
+ private [this ] var closeables : List [java.io.Closeable ] = Nil
267
+ override def close (): Unit = {
268
+ closeables.foreach(_.close())
269
+ }
254
270
}
0 commit comments