summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
blob: 86e462954487da4ff58801aa0fc60672504054ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
    }
  }
}