diff options
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.scala | 24 |
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) + } + } +} |