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

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

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

Manifest.write介绍

[英]Writes this Manifest's name/attributes pairs to the given OutputStream. The MANIFEST_VERSION or SIGNATURE_VERSION attribute must be set before calling this method, or no attributes will be written.
[中]将此清单的名称/属性对写入给定的OutputStream。在调用此方法之前,必须设置MANIFEST_VERSION或SIGNATURE_VERSION属性,否则不会写入任何属性。

代码示例

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

  1. /**
  2. * Writes this {@code Manifest}'s name/attributes pairs to the given {@code OutputStream}.
  3. * The {@code MANIFEST_VERSION} or {@code SIGNATURE_VERSION} attribute must be set before
  4. * calling this method, or no attributes will be written.
  5. *
  6. * @throws IOException
  7. * If an error occurs writing the {@code Manifest}.
  8. */
  9. public void write(OutputStream os) throws IOException {
  10. write(this, os);
  11. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Sink write(Manifest manifest) throws IOException {
  5. if (manifest != null) {
  6. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  7. try {
  8. manifest.write(outputStream);
  9. } finally {
  10. outputStream.close();
  11. }
  12. storage.put(JarFile.MANIFEST_NAME, outputStream.toByteArray());
  13. }
  14. return this;
  15. }

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

  1. /**
  2. * Write out manifest to destfile.
  3. *
  4. * @param manifest the manifest
  5. * @throws IOException if error writing file
  6. */
  7. private void writeManifest(final Manifest manifest) throws IOException {
  8. try (OutputStream output = Files.newOutputStream(destFile.toPath())) {
  9. manifest.write(output);
  10. output.flush();
  11. }
  12. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Sink write(Manifest manifest) throws IOException {
  5. if (manifest != null) {
  6. File target = new File(folder, JarFile.MANIFEST_NAME);
  7. if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) {
  8. throw new IOException("Could not create directory: " + target.getParent());
  9. }
  10. OutputStream outputStream = new FileOutputStream(target);
  11. try {
  12. manifest.write(outputStream);
  13. } finally {
  14. outputStream.close();
  15. }
  16. }
  17. return this;
  18. }

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

  1. /**
  2. * Constructs a new {@code JarOutputStream} using an output stream. The
  3. * content of the {@code Manifest} must match the JAR entry information
  4. * written subsequently to the stream.
  5. *
  6. * @param os
  7. * the {@code OutputStream} to write to
  8. * @param manifest
  9. * the {@code Manifest} to output for this JAR file.
  10. * @throws IOException
  11. * if an error occurs creating the {@code JarOutputStream}.
  12. */
  13. public JarOutputStream(OutputStream os, Manifest manifest) throws IOException {
  14. super(os);
  15. if (manifest == null) {
  16. throw new NullPointerException("manifest == null");
  17. }
  18. this.manifest = manifest;
  19. ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME);
  20. putNextEntry(ze);
  21. this.manifest.write(this);
  22. closeEntry();
  23. }

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

  1. mf.write(baos);
  2. baos.flush();
  3. Files.write(targetPath, baos.toByteArray());

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

  1. private String getJarVersion(Path jarPath) throws IOException {
  2. try (final JarFile jarFile = new JarFile(jarPath.toFile())) {
  3. final Manifest manifest;
  4. try {
  5. manifest = jarFile.getManifest();
  6. } catch (IOException ex) {
  7. throw new IOException("Version not found. Failed to load the manifest.", ex);
  8. }
  9. String manifestContents;
  10. try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
  11. manifest.write(outputStream);
  12. manifestContents = outputStream.toString();
  13. } catch (IOException ex) {
  14. manifestContents = "(Failed to read the contents of the manifest.)";
  15. }
  16. final Attributes mainAttributes = manifest.getMainAttributes();
  17. final String implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
  18. if (implementationVersion == null) {
  19. throw new IOException("Version not found. Failed to read \""
  20. + Attributes.Name.IMPLEMENTATION_VERSION
  21. + "\": "
  22. + manifestContents);
  23. }
  24. return implementationVersion;
  25. } catch (IOException ex) {
  26. throw new IOException("Version not found. Failed to load the jar file.", ex);
  27. }
  28. // NOTE: Checking embulk/version.rb is no longer needed.
  29. // The jar manifest with "Implementation-Version" has been included in Embulk jars from v0.4.0.
  30. }

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

  1. public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
  2. throws IOException {
  3. Preconditions.checkNotNull(relativePath, "relativePath");
  4. Preconditions.checkNotNull(zos, "zos");
  5. // by JAR spec, if there is a manifest, it must be the first entry in 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. copyToZipStream(manifestFile, manifestEntry, zos);
  15. }
  16. zos.closeEntry();
  17. zipDir(dir, relativePath, zos, true);
  18. zos.close();
  19. }

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

  1. private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException {
  2. try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) {
  3. Manifest manifest = new Manifest(manifestInputStream);
  4. Attributes mainAttributes = manifest.getMainAttributes();
  5. if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) {
  6. descriptor.markAsInvalid(Arrays.asList("Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null);
  7. return;
  8. }
  9. mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName);
  10. mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath);
  11. mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator);
  12. descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator);
  13. try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) {
  14. manifest.write(manifestOutputStream);
  15. }
  16. }
  17. }

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

  1. private void addHeaderToManifest(String header, String value) throws IOException {
  2. FileInputStream manifestInputStream = new FileInputStream(manifestFile);
  3. Manifest manifest = new Manifest(manifestInputStream);
  4. Attributes entries = manifest.getMainAttributes();
  5. entries.put(new Attributes.Name(header), value);
  6. FileOutputStream manifestOutputStream = new FileOutputStream(manifestFile, false);
  7. manifest.write(manifestOutputStream);
  8. manifestOutputStream.close();
  9. manifestInputStream.close();
  10. }

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

  1. je.setTime(timestamp);
  2. outputJar.putNextEntry(je);
  3. manifest.write(outputJar);

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

  1. manifest.write(print);
  2. print.flush();
  3. main.putValue(digestAlg + "-Digest-Manifest", encodeBase64(md.digest()));
  4. m2.write(print);
  5. main.putValue(digestAlg + "-Digest-Manifest-Main-Attributes", encodeBase64(md.digest()));
  6. sf.write(out);

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

  1. @Test
  2. public void testExistingManifest() throws Exception {
  3. File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
  4. TestJarFinder.class.getName() + "-testExistingManifest");
  5. delete(dir);
  6. dir.mkdirs();
  7. File metaInfDir = new File(dir, "META-INF");
  8. metaInfDir.mkdirs();
  9. File manifestFile = new File(metaInfDir, "MANIFEST.MF");
  10. Manifest manifest = new Manifest();
  11. OutputStream os = new FileOutputStream(manifestFile);
  12. manifest.write(os);
  13. os.close();
  14. File propsFile = new File(dir, "props.properties");
  15. Writer writer = new FileWriter(propsFile);
  16. new Properties().store(writer, "");
  17. writer.close();
  18. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  19. JarOutputStream zos = new JarOutputStream(baos);
  20. JarFinder.jarDir(dir, "", zos);
  21. JarInputStream jis =
  22. new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
  23. Assert.assertNotNull(jis.getManifest());
  24. jis.close();
  25. }

代码示例来源:origin: org.codehaus.plexus/plexus-archiver

  1. /**
  2. * Writes the manifest out to a writer.
  3. *
  4. * @param writer the Writer to which the manifest is written
  5. *
  6. * @throws IOException if the manifest cannot be written
  7. */
  8. public void write( Writer writer )
  9. throws IOException
  10. {
  11. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  12. super.write( byteArrayOutputStream );
  13. // We know that UTF-8 is the encoding of the JAR file specification
  14. writer.write( byteArrayOutputStream.toString( "UTF-8" ) );
  15. }

代码示例来源:origin: mulesoft/mule

  1. private File createManifestFileIfNecessary(File targetDirectory, Manifest sourceManifest) {
  2. try {
  3. File manifestFile = new File(targetDirectory.getPath(), "MANIFEST.MF");
  4. if (!manifestFile.exists()) {
  5. Manifest manifest = new Manifest(sourceManifest);
  6. try (FileOutputStream fileOutputStream = new FileOutputStream(manifestFile)) {
  7. manifest.write(fileOutputStream);
  8. }
  9. }
  10. return manifestFile;
  11. } catch (IOException e) {
  12. throw new RuntimeException("Error creating discoverer", e);
  13. }
  14. }

代码示例来源:origin: org.eclipse.jetty/jetty-util

  1. try (OutputStream fout = new FileOutputStream(f))
  2. manifest.write(fout);

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

  1. public void open() throws IOException {
  2. // Update the manifest
  3. Manifest updated = m_manifestBuilder.build(m_manifest);
  4. // Write it to disk
  5. OutputStream os = new FileOutputStream(m_manifest_file);
  6. try {
  7. updated.write(os);
  8. } finally {
  9. Streams.close(os);
  10. }
  11. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

  1. private void saveManifest() throws CoreException, IOException {
  2. ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream();
  3. Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage);
  4. manifest.write(manifestOutput);
  5. ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray());
  6. IFile manifestFile= fJarPackage.getManifestFile();
  7. if (manifestFile.isAccessible()) {
  8. if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false))
  9. manifestFile.setContents(fileInput, true, true, null);
  10. } else
  11. manifestFile.create(fileInput, true, null);
  12. }

相关文章