java.util.jar.Manifest.<init>()方法的使用及代码示例

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

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

Manifest.<init>介绍

[英]Creates a new Manifest instance.
[中]创建一个新的清单实例。

代码示例

代码示例来源: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: 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: 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: apache/hive

  1. public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException {
  2. Preconditions.checkNotNull(relativePath, "relativePath");
  3. Preconditions.checkNotNull(zos, "zos");
  4. // by JAR spec, if there is a manifest, it must be the first entry in
  5. // the
  6. // ZIP.
  7. File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
  8. ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
  9. if (!manifestFile.exists()) {
  10. zos.putNextEntry(manifestEntry);
  11. new Manifest().write(new BufferedOutputStream(zos));
  12. zos.closeEntry();
  13. } else {
  14. InputStream is = new FileInputStream(manifestFile);
  15. copyToZipStream(is, manifestEntry, zos);
  16. }
  17. zos.closeEntry();
  18. zipDir(dir, relativePath, zos, true);
  19. zos.close();
  20. }

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

  1. Manifest manifest = new Manifest();
  2. manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  3. JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest);
  4. add(new File("inputDirectory"), target);
  5. target.close();

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

  1. File f = new File(url.getPath());
  2. jis = new JarInputStream(url.openStream());
  3. mf = jis.getManifest();
  4. } catch (IOException ioe) {
  5. try {
  6. is = new FileInputStream(manifest);
  7. mf = new Manifest(is);
  8. } catch (IOException e) {
  9. throw new PluginException("Failed loading manifest for plugin jar: " + url, e);

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

  1. manifest = new Manifest(is, verifier != null);
  2. } finally {
  3. is.close();

代码示例来源:origin: apache/hive

  1. /**
  2. * Loads the manifest attributes from the jar.
  3. *
  4. * @throws java.net.MalformedURLException
  5. * @throws IOException
  6. */
  7. private static synchronized void loadManifestAttributes() throws IOException {
  8. if (manifestAttributes != null) {
  9. return;
  10. }
  11. Class<?> clazz = HiveDriver.class;
  12. String classContainer = clazz.getProtectionDomain().getCodeSource()
  13. .getLocation().toString();
  14. URL manifestUrl = new URL("jar:" + classContainer
  15. + "!/META-INF/MANIFEST.MF");
  16. Manifest manifest = new Manifest(manifestUrl.openStream());
  17. manifestAttributes = manifest.getMainAttributes();
  18. }

代码示例来源: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: org.patterntesting/patterntesting-rt

  1. private static Manifest getManifest(final URI uri) throws IOException {
  2. String content = IOUtils.toString(uri, StandardCharsets.UTF_8);
  3. InputStream istream = new ByteArrayInputStream(content.getBytes("UTF8"));
  4. try {
  5. Manifest manifest = new Manifest(istream);
  6. manifest.read(istream);
  7. manifest.getMainAttributes().putValue(MANIFEST_URI, uri.toString());
  8. return manifest;
  9. } finally {
  10. istream.close();
  11. }
  12. }

代码示例来源:origin: scouter-project/scouter

  1. public static void print() throws IOException {
  2. InputStream manifestStream = Thread.currentThread().getContextClassLoader()
  3. .getResourceAsStream("META-INF/MANIFEST.MF");
  4. try {
  5. Manifest manifest = new Manifest(manifestStream);
  6. Attributes attributes = manifest.getMainAttributes();
  7. String impVersion = attributes.getValue("Implementation-Version");
  8. System.out.println(attributes);
  9. } catch (IOException ex) {
  10. ex.printStackTrace();
  11. }
  12. }

代码示例来源: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: stackoverflow.com

  1. Class clazz = MyClass.class;
  2. String className = clazz.getSimpleName() + ".class";
  3. String classPath = clazz.getResource(className).toString();
  4. if (!classPath.startsWith("jar")) {
  5. // Class not from JAR
  6. return;
  7. }
  8. String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
  9. "/META-INF/MANIFEST.MF";
  10. Manifest manifest = new Manifest(new URL(manifestPath).openStream());
  11. Attributes attr = manifest.getMainAttributes();
  12. String value = attr.getValue("Manifest-Version");

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

  1. try (JarFile jf = new JarFile(new File(new URI(loc)), false)) {
  2. Manifest mf = jf.getManifest();
  3. if (mf != null) {
  4. File manifestFile = new File(new URI(m.group(1) + "META-INF/MANIFEST.MF"));
  5. if (manifestFile.isFile()) {
  6. try (InputStream is = new FileInputStream(manifestFile)) {
  7. if (isPluginManifest(new Manifest(is))) {
  8. LOGGER.log(Level.FINE, "{0} looks like a Jenkins plugin based on {1}, OK", new Object[] {loc, manifestFile});
  9. return true;

代码示例来源:origin: apache/geode

  1. Path locationPath = new File(location).getCanonicalFile().toPath();
  2. Files.createDirectories(locationPath);
  3. Manifest manifest = new Manifest();
  4. Attributes global = manifest.getMainAttributes();
  5. global.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
  6. global.put(new Attributes.Name("Class-Path"), String.join(" ", manifestEntries));

代码示例来源:origin: org.apache.ant/ant

  1. manifest = new Manifest(in);
  2. } catch (IOException e) {
  3. throw new BuildException("Unable to read manifest", e, getLocation());
  4. } finally {
  5. if (in != null) {
  6. in.close();
  7. entryFile = new File(config.srcDir, entryName);

代码示例来源:origin: org.avaje.ebean/querybean-agent

  1. private void addResource(InputStream is) throws IOException {
  2. try {
  3. addManifest(new Manifest(is));
  4. } finally {
  5. try {
  6. is.close();
  7. } catch (IOException e) {
  8. System.err.println("Error closing manifest resource");
  9. e.printStackTrace();
  10. }
  11. }
  12. }

代码示例来源:origin: com.netflix.eureka/eureka-client

  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: chewiebug/GCViewer

  1. /**
  2. * Returns Manifest-Attributes for MANIFEST.MF, if running for a .jar file
  3. *
  4. * @return Manifest Attributes (may be empty but never null)
  5. * @throws IOException If something went wrong finding the MANIFEST file
  6. * @see <a href="http://stackoverflow.com/a/1273432">stackoverflow article</a>
  7. */
  8. private static Attributes getAttributes() throws IOException {
  9. Class clazz = BuildInfoReader.class;
  10. String className = clazz.getSimpleName() + ".class";
  11. String classPath = clazz.getResource(className).toString();
  12. if (!classPath.startsWith("jar")) {
  13. // Class not from JAR
  14. return new Attributes(0);
  15. }
  16. String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + FILE_NAME;
  17. Manifest manifest = new Manifest(new URL(manifestPath).openStream());
  18. return manifest.getMainAttributes();
  19. }

代码示例来源: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. }

相关文章