summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
Publish
Diffstat (limited to 'bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala')
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
new file mode 100644
index 00000000000..86e46295448
--- /dev/null
+++ b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
@@ -0,0 +1,24 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.plugin.util
+
+import java.util.jar.JarFile
+import java.util.zip.{ZipFile, ZipEntry}
+import IO.using
+import java.io.{Closeable, InputStream, File}
+
+/**
+ * @author tonytv
+ */
+object JarFiles {
+ def withJarFile[T](file : File)(f : JarFile => T ) : T =
+ using(new JarFile(file) with Closeable, readOnly = true)(f)
+
+ def withInputStream[T](zipFile: ZipFile, zipEntry: ZipEntry)(f: InputStream => T): T =
+ using(zipFile.getInputStream(zipEntry), readOnly = true)(f)
+
+ def getManifest(jarFile : File) : Option[java.util.jar.Manifest] = {
+ withJarFile(jarFile) { jar =>
+ Option(jar.getManifest)
+ }
+ }
+}