From f6f3e411e348e45bbcc6a53d971f5257dfd84b50 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 10 Apr 2016 09:14:36 +0000 Subject: [PATCH] Easy way to retrieve manifest for script bundle --- source/net/filebot/cli/ScriptBundle.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/net/filebot/cli/ScriptBundle.java b/source/net/filebot/cli/ScriptBundle.java index e203f456..4269c99d 100644 --- a/source/net/filebot/cli/ScriptBundle.java +++ b/source/net/filebot/cli/ScriptBundle.java @@ -2,6 +2,7 @@ package net.filebot.cli; import static java.nio.charset.StandardCharsets.*; import static java.util.Arrays.*; +import static java.util.stream.Collectors.*; import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; @@ -10,6 +11,7 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.util.Arrays; +import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; @@ -52,4 +54,10 @@ public class ScriptBundle implements ScriptProvider { throw new FileNotFoundException("Script not found: " + name); } + public Map getManifest() throws Exception { + try (JarInputStream jar = new JarInputStream(new ByteArrayInputStream(bundle.get()), true)) { + return jar.getManifest().getMainAttributes().entrySet().stream().collect(toMap(it -> it.getKey().toString(), it -> it.getValue().toString())); + } + } + }