本文整理了Java中java.util.jar.Manifest.write()
方法的一些代码示例,展示了Manifest.write()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Manifest.write()
方法的具体详情如下:
包路径:java.util.jar.Manifest
类名称: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
/**
* Writes this {@code Manifest}'s name/attributes pairs to the given {@code OutputStream}.
* The {@code MANIFEST_VERSION} or {@code SIGNATURE_VERSION} attribute must be set before
* calling this method, or no attributes will be written.
*
* @throws IOException
* If an error occurs writing the {@code Manifest}.
*/
public void write(OutputStream os) throws IOException {
write(this, os);
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Sink write(Manifest manifest) throws IOException {
if (manifest != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
manifest.write(outputStream);
} finally {
outputStream.close();
}
storage.put(JarFile.MANIFEST_NAME, outputStream.toByteArray());
}
return this;
}
代码示例来源:origin: org.apache.ant/ant
/**
* Write out manifest to destfile.
*
* @param manifest the manifest
* @throws IOException if error writing file
*/
private void writeManifest(final Manifest manifest) throws IOException {
try (OutputStream output = Files.newOutputStream(destFile.toPath())) {
manifest.write(output);
output.flush();
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Sink write(Manifest manifest) throws IOException {
if (manifest != null) {
File target = new File(folder, JarFile.MANIFEST_NAME);
if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) {
throw new IOException("Could not create directory: " + target.getParent());
}
OutputStream outputStream = new FileOutputStream(target);
try {
manifest.write(outputStream);
} finally {
outputStream.close();
}
}
return this;
}
代码示例来源:origin: robovm/robovm
/**
* Constructs a new {@code JarOutputStream} using an output stream. The
* content of the {@code Manifest} must match the JAR entry information
* written subsequently to the stream.
*
* @param os
* the {@code OutputStream} to write to
* @param manifest
* the {@code Manifest} to output for this JAR file.
* @throws IOException
* if an error occurs creating the {@code JarOutputStream}.
*/
public JarOutputStream(OutputStream os, Manifest manifest) throws IOException {
super(os);
if (manifest == null) {
throw new NullPointerException("manifest == null");
}
this.manifest = manifest;
ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME);
putNextEntry(ze);
this.manifest.write(this);
closeEntry();
}
代码示例来源:origin: Sable/soot
private void addManifest(ZipOutputStream destination, Collection<File> dexFiles) throws IOException {
final Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "Soot Dex Printer");
if (dexFiles != null && !dexFiles.isEmpty()) {
manifest.getMainAttributes().put(new Attributes.Name("Dex-Location"),
dexFiles.stream().map(File::getName).collect(Collectors.joining(" ")));
}
final ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
destination.putNextEntry(manifestEntry);
manifest.write(new BufferedOutputStream(destination));
destination.closeEntry();
}
代码示例来源:origin: apache/hive
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException {
Preconditions.checkNotNull(relativePath, "relativePath");
Preconditions.checkNotNull(zos, "zos");
// by JAR spec, if there is a manifest, it must be the first entry in
// the
// ZIP.
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
if (!manifestFile.exists()) {
zos.putNextEntry(manifestEntry);
new Manifest().write(new BufferedOutputStream(zos));
zos.closeEntry();
} else {
InputStream is = new FileInputStream(manifestFile);
copyToZipStream(is, manifestEntry, zos);
}
zos.closeEntry();
zipDir(dir, relativePath, zos, true);
zos.close();
}
代码示例来源:origin: pxb1988/dex2jar
mf.write(baos);
baos.flush();
Files.write(targetPath, baos.toByteArray());
代码示例来源:origin: embulk/embulk
private String getJarVersion(Path jarPath) throws IOException {
try (final JarFile jarFile = new JarFile(jarPath.toFile())) {
final Manifest manifest;
try {
manifest = jarFile.getManifest();
} catch (IOException ex) {
throw new IOException("Version not found. Failed to load the manifest.", ex);
}
String manifestContents;
try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
manifest.write(outputStream);
manifestContents = outputStream.toString();
} catch (IOException ex) {
manifestContents = "(Failed to read the contents of the manifest.)";
}
final Attributes mainAttributes = manifest.getMainAttributes();
final String implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (implementationVersion == null) {
throw new IOException("Version not found. Failed to read \""
+ Attributes.Name.IMPLEMENTATION_VERSION
+ "\": "
+ manifestContents);
}
return implementationVersion;
} catch (IOException ex) {
throw new IOException("Version not found. Failed to load the jar file.", ex);
}
// NOTE: Checking embulk/version.rb is no longer needed.
// The jar manifest with "Implementation-Version" has been included in Embulk jars from v0.4.0.
}
代码示例来源:origin: apache/hbase
public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
throws IOException {
Preconditions.checkNotNull(relativePath, "relativePath");
Preconditions.checkNotNull(zos, "zos");
// by JAR spec, if there is a manifest, it must be the first entry in the
// ZIP.
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
if (!manifestFile.exists()) {
zos.putNextEntry(manifestEntry);
new Manifest().write(new BufferedOutputStream(zos));
zos.closeEntry();
} else {
copyToZipStream(manifestFile, manifestEntry, zos);
}
zos.closeEntry();
zipDir(dir, relativePath, zos, true);
zos.close();
}
代码示例来源:origin: gocd/gocd
private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException {
try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) {
Manifest manifest = new Manifest(manifestInputStream);
Attributes mainAttributes = manifest.getMainAttributes();
if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) {
descriptor.markAsInvalid(Arrays.asList("Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null);
return;
}
mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName);
mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath);
mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator);
descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator);
try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) {
manifest.write(manifestOutputStream);
}
}
}
代码示例来源:origin: gocd/gocd
private void addHeaderToManifest(String header, String value) throws IOException {
FileInputStream manifestInputStream = new FileInputStream(manifestFile);
Manifest manifest = new Manifest(manifestInputStream);
Attributes entries = manifest.getMainAttributes();
entries.put(new Attributes.Name(header), value);
FileOutputStream manifestOutputStream = new FileOutputStream(manifestFile, false);
manifest.write(manifestOutputStream);
manifestOutputStream.close();
manifestInputStream.close();
}
代码示例来源:origin: pxb1988/dex2jar
je.setTime(timestamp);
outputJar.putNextEntry(je);
manifest.write(outputJar);
代码示例来源:origin: pxb1988/dex2jar
manifest.write(print);
print.flush();
main.putValue(digestAlg + "-Digest-Manifest", encodeBase64(md.digest()));
m2.write(print);
main.putValue(digestAlg + "-Digest-Manifest-Main-Attributes", encodeBase64(md.digest()));
sf.write(out);
代码示例来源:origin: apache/hbase
@Test
public void testExistingManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
TestJarFinder.class.getName() + "-testExistingManifest");
delete(dir);
dir.mkdirs();
File metaInfDir = new File(dir, "META-INF");
metaInfDir.mkdirs();
File manifestFile = new File(metaInfDir, "MANIFEST.MF");
Manifest manifest = new Manifest();
OutputStream os = new FileOutputStream(manifestFile);
manifest.write(os);
os.close();
File propsFile = new File(dir, "props.properties");
Writer writer = new FileWriter(propsFile);
new Properties().store(writer, "");
writer.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream zos = new JarOutputStream(baos);
JarFinder.jarDir(dir, "", zos);
JarInputStream jis =
new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
Assert.assertNotNull(jis.getManifest());
jis.close();
}
代码示例来源:origin: org.codehaus.plexus/plexus-archiver
/**
* Writes the manifest out to a writer.
*
* @param writer the Writer to which the manifest is written
*
* @throws IOException if the manifest cannot be written
*/
public void write( Writer writer )
throws IOException
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
super.write( byteArrayOutputStream );
// We know that UTF-8 is the encoding of the JAR file specification
writer.write( byteArrayOutputStream.toString( "UTF-8" ) );
}
代码示例来源:origin: mulesoft/mule
private File createManifestFileIfNecessary(File targetDirectory, Manifest sourceManifest) {
try {
File manifestFile = new File(targetDirectory.getPath(), "MANIFEST.MF");
if (!manifestFile.exists()) {
Manifest manifest = new Manifest(sourceManifest);
try (FileOutputStream fileOutputStream = new FileOutputStream(manifestFile)) {
manifest.write(fileOutputStream);
}
}
return manifestFile;
} catch (IOException e) {
throw new RuntimeException("Error creating discoverer", e);
}
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
try (OutputStream fout = new FileOutputStream(f))
manifest.write(fout);
代码示例来源:origin: apache/felix
public void open() throws IOException {
// Update the manifest
Manifest updated = m_manifestBuilder.build(m_manifest);
// Write it to disk
OutputStream os = new FileOutputStream(m_manifest_file);
try {
updated.write(os);
} finally {
Streams.close(os);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
private void saveManifest() throws CoreException, IOException {
ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream();
Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage);
manifest.write(manifestOutput);
ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray());
IFile manifestFile= fJarPackage.getManifestFile();
if (manifestFile.isAccessible()) {
if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false))
manifestFile.setContents(fileInput, true, true, null);
} else
manifestFile.create(fileInput, true, null);
}
内容来源于网络,如有侵权,请联系作者删除!