java.util.jar.Manifest类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(395)

本文整理了Java中java.util.jar.Manifest类的一些代码示例,展示了Manifest类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Manifest类的具体详情如下:
包路径:java.util.jar.Manifest
类名称:Manifest

Manifest介绍

[英]The Manifest class is used to obtain attribute information for a JarFile and its entries.
[中]Manifest类用于获取JarFile及其条目的属性信息。

代码示例

代码示例来源:origin: skylot/jadx

  1. public static String getVersion() {
  2. try {
  3. ClassLoader classLoader = Jadx.class.getClassLoader();
  4. if (classLoader != null) {
  5. Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF");
  6. while (resources.hasMoreElements()) {
  7. Manifest manifest = new Manifest(resources.nextElement().openStream());
  8. String ver = manifest.getMainAttributes().getValue("jadx-version");
  9. if (ver != null) {
  10. return ver;
  11. }
  12. }
  13. }
  14. } catch (Exception e) {
  15. LOG.error("Can't get manifest file", e);
  16. }
  17. return "dev";
  18. }
  19. }

代码示例来源:origin: Sable/soot

  1. private void addManifest(ZipOutputStream destination, Collection<File> dexFiles) throws IOException {
  2. final Manifest manifest = new Manifest();
  3. manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  4. manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "Soot Dex Printer");
  5. if (dexFiles != null && !dexFiles.isEmpty()) {
  6. manifest.getMainAttributes().put(new Attributes.Name("Dex-Location"),
  7. dexFiles.stream().map(File::getName).collect(Collectors.joining(" ")));
  8. }
  9. final ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
  10. destination.putNextEntry(manifestEntry);
  11. manifest.write(new BufferedOutputStream(destination));
  12. destination.closeEntry();
  13. }

代码示例来源:origin: pxb1988/dex2jar

  1. Manifest input = jar.getManifest();
  2. Manifest output = new Manifest();
  3. Attributes main = output.getMainAttributes();
  4. if (input != null) {
  5. main.putAll(input.getMainAttributes());
  6. main.putValue("Manifest-Version", "1.0");
  7. main.putValue("Created-By", "1.6.0_21 (d2j-" + AbstractJarSign.class.getPackage().getImplementationVersion() + ")");
  8. for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
  9. JarEntry entry = e.nextElement();
  10. byName.put(entry.getName(), entry);
  11. String name = entry.getName();
  12. if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !stripPattern.matcher(name).matches()) {
  13. InputStream data = jar.getInputStream(entry);
  14. while ((num = data.read(buffer)) > 0) {
  15. md.update(buffer, 0, num);
  16. attr = input.getAttributes(name);
  17. attr = attr != null ? new Attributes(attr) : new Attributes();
  18. attr.putValue(digName, encodeBase64(md.digest()));
  19. output.getEntries().put(name, attr);

代码示例来源:origin: redisson/redisson

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public File toJar(File file) throws IOException {
  5. Manifest manifest = new Manifest();
  6. manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
  7. return toJar(file, manifest);
  8. }

代码示例来源:origin: robovm/robovm

  1. private boolean isSealed(Manifest manifest, String dirName) {
  2. Attributes attributes = manifest.getAttributes(dirName);
  3. if (attributes != null) {
  4. String value = attributes.getValue(Attributes.Name.SEALED);
  5. if (value != null) {
  6. return value.equalsIgnoreCase("true");
  7. }
  8. }
  9. Attributes mainAttributes = manifest.getMainAttributes();
  10. String value = mainAttributes.getValue(Attributes.Name.SEALED);
  11. return (value != null && value.equalsIgnoreCase("true"));
  12. }

代码示例来源:origin: Netflix/eureka

  1. private static Manifest loadManifest(String jarUrl) throws Exception {
  2. InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream();
  3. try {
  4. return new Manifest(is);
  5. } finally {
  6. is.close();
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. JarFile jar = new JarFile(new File("path/to/your/jar-file"));
  2. InputStream is = jar.getInputStream(jar.getEntry("META-INF/MANIFEST.MF"));
  3. Manifest man = new Manifest(is);
  4. is.close();
  5. for(Map.Entry<String, Attributes> entry: man.getEntries().entrySet()) {
  6. for(Object attrkey: entry.getValue().keySet()) {
  7. if (attrkey instanceof Attributes.Name &&
  8. ((Attributes.Name)attrkey).toString().indexOf("-Digest") != -1)
  9. signed.add(entry.getKey());
  10. for(Enumeration<JarEntry> entry = jar.entries(); entry.hasMoreElements(); ) {
  11. JarEntry je = entry.nextElement();
  12. if (!je.isDirectory())
  13. entries.add(je.getName());

代码示例来源:origin: stackoverflow.com

  1. Enumeration<URL> resources = getClass().getClassLoader()
  2. .getResources("META-INF/MANIFEST.MF");
  3. while (resources.hasMoreElements()) {
  4. try {
  5. Manifest manifest = new Manifest(resources.nextElement().openStream());
  6. // check that this is your manifest and do what you need or get the next one
  7. ...
  8. } catch (IOException E) {
  9. // handle
  10. }
  11. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Manifest getManifest() throws IOException {
  5. File file = new File(folder, JarFile.MANIFEST_NAME);
  6. if (file.exists()) {
  7. InputStream inputStream = new FileInputStream(file);
  8. try {
  9. return new Manifest(inputStream);
  10. } finally {
  11. inputStream.close();
  12. }
  13. } else {
  14. return NO_MANIFEST;
  15. }
  16. }

代码示例来源:origin: redisson/redisson

  1. try {
  2. try {
  3. Manifest manifest = new Manifest(inputStream);
  4. Map<Attributes.Name, String> values = new HashMap<Attributes.Name, String>();
  5. Attributes mainAttributes = manifest.getMainAttributes();
  6. if (mainAttributes != null) {
  7. for (Attributes.Name attributeName : ATTRIBUTE_NAMES) {
  8. values.put(attributeName, mainAttributes.getValue(attributeName));
  9. Attributes attributes = manifest.getAttributes(packageName.replace('.', '/').concat("/"));
  10. if (attributes != null) {
  11. for (Attributes.Name attributeName : ATTRIBUTE_NAMES) {
  12. String value = attributes.getValue(attributeName);
  13. if (value != null) {
  14. values.put(attributeName, value);
  15. : NOT_SEALED);
  16. } finally {
  17. inputStream.close();

代码示例来源:origin: jenkinsci/jenkins

  1. URL sealBase = null;
  2. Attributes sectionAttributes = manifest.getAttributes(sectionName);
  3. if (sectionAttributes != null) {
  4. specificationTitle = sectionAttributes.getValue(Name.SPECIFICATION_TITLE);
  5. specificationVendor = sectionAttributes.getValue(Name.SPECIFICATION_VENDOR);
  6. specificationVersion = sectionAttributes.getValue(Name.SPECIFICATION_VERSION);
  7. implementationTitle = sectionAttributes.getValue(Name.IMPLEMENTATION_TITLE);
  8. implementationVendor = sectionAttributes.getValue(Name.IMPLEMENTATION_VENDOR);
  9. sealedString = sectionAttributes.getValue(Name.SEALED);
  10. Attributes mainAttributes = manifest.getMainAttributes();
  11. if (mainAttributes != null) {
  12. if (specificationTitle == null) {
  13. sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath()));
  14. } catch (MalformedURLException e) {

代码示例来源:origin: pxb1988/dex2jar

  1. int num;
  2. Map<String, Attributes> entries = manifest.getEntries();
  3. List<String> names = new ArrayList<>(entries.keySet());
  4. Collections.sort(names);
  5. for (String name : names) {
  6. JarEntry inEntry = in.getJarEntry(name);
  7. JarEntry outEntry = null;
  8. if (inEntry.getMethod() == JarEntry.STORED) {
  9. out.putNextEntry(outEntry);
  10. InputStream data = in.getInputStream(inEntry);
  11. while ((num = data.read(buffer)) > 0) {
  12. out.write(buffer, 0, num);

代码示例来源:origin: jenkinsci/jenkins

  1. protected String identifyPluginShortName(File t) {
  2. try {
  3. JarFile j = new JarFile(t);
  4. try {
  5. String name = j.getManifest().getMainAttributes().getValue("Short-Name");
  6. if (name!=null) return name;
  7. } finally {
  8. j.close();
  9. }
  10. } catch (IOException e) {
  11. LOGGER.log(WARNING, "Failed to identify the short name from "+t,e);
  12. }
  13. return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded
  14. }

代码示例来源:origin: biz.aQute/bndlib

  1. public Manifest getManifest() throws Exception {
  2. check();
  3. if (manifest == null) {
  4. Resource manifestResource = getResource("META-INF/MANIFEST.MF");
  5. if (manifestResource != null) {
  6. InputStream in = manifestResource.openInputStream();
  7. manifest = new Manifest(in);
  8. in.close();
  9. }
  10. }
  11. return manifest;
  12. }

代码示例来源:origin: google/guava

  1. manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH.toString());
  2. if (classpathAttribute != null) {
  3. for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) {
  4. continue;
  5. if (url.getProtocol().equals("file")) {
  6. builder.add(toFile(url));

代码示例来源:origin: stackoverflow.com

  1. URLClassLoader cl = (URLClassLoader) getClass().getClassLoader();
  2. try {
  3. URL url = cl.findResource("META-INF/MANIFEST.MF");
  4. Manifest manifest = new Manifest(url.openStream());
  5. // do stuff with it
  6. ...
  7. } catch (IOException E) {
  8. // handle
  9. }

代码示例来源:origin: jenkinsci/jenkins

  1. /*package*/ static @CheckForNull Manifest parsePluginManifest(URL bundledJpi) {
  2. try {
  3. URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi});
  4. InputStream in=null;
  5. try {
  6. URL res = cl.findResource(PluginWrapper.MANIFEST_FILENAME);
  7. if (res!=null) {
  8. in = getBundledJpiManifestStream(res);
  9. Manifest manifest = new Manifest(in);
  10. return manifest;
  11. }
  12. } finally {
  13. Util.closeAndLogFailures(in, LOGGER, PluginWrapper.MANIFEST_FILENAME, bundledJpi.toString());
  14. if (cl instanceof Closeable)
  15. ((Closeable)cl).close();
  16. }
  17. } catch (IOException e) {
  18. LOGGER.log(WARNING, "Failed to parse manifest of "+bundledJpi, e);
  19. }
  20. return null;
  21. }

代码示例来源:origin: jenkinsci/jenkins

  1. private String getVersionOf(Manifest manifest) {
  2. String v = manifest.getMainAttributes().getValue("Plugin-Version");
  3. if(v!=null) return v;
  4. // plugins generated before maven-hpi-plugin 1.3 should still have this attribute
  5. v = manifest.getMainAttributes().getValue("Implementation-Version");
  6. if(v!=null) return v;
  7. return "???";
  8. }

代码示例来源:origin: org.apache.felix/maven-bundle-plugin

  1. private boolean isOsgi( Jar jar ) throws Exception
  2. {
  3. if ( jar.getManifest() != null )
  4. {
  5. return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null;
  6. }
  7. return false;
  8. }

代码示例来源:origin: gocd/gocd

  1. private static String defaultMainClassName(JarFile jarFile) throws IOException {
  2. return jarFile.getManifest().getMainAttributes().getValue("GoCD-Main-Class");
  3. }
  4. }

相关文章