1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28:51 -05:00

Easy way to retrieve manifest for script bundle

This commit is contained in:
Reinhard Pointner 2016-04-10 09:14:36 +00:00
parent 21d643c544
commit f6f3e411e3

View File

@ -2,6 +2,7 @@ package net.filebot.cli;
import static java.nio.charset.StandardCharsets.*; import static java.nio.charset.StandardCharsets.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.stream.Collectors.*;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -10,6 +11,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
@ -52,4 +54,10 @@ public class ScriptBundle implements ScriptProvider {
throw new FileNotFoundException("Script not found: " + name); throw new FileNotFoundException("Script not found: " + name);
} }
public Map<String, String> 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()));
}
}
} }