当前位置: 首页>>代码示例>>Java>>正文


Java Manifest.write方法代码示例

本文整理汇总了Java中java.util.jar.Manifest.write方法的典型用法代码示例。如果您正苦于以下问题:Java Manifest.write方法的具体用法?Java Manifest.write怎么用?Java Manifest.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.Manifest的用法示例。


在下文中一共展示了Manifest.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTo

import java.util.jar.Manifest; //导入方法依赖的package包/类
static void writeTo(org.gradle.api.java.archives.Manifest manifest, OutputStream outputStream, String contentCharset) {
    try {
        Manifest javaManifest = generateJavaManifest(manifest.getEffectiveManifest());
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        javaManifest.write(buffer);
        byte[] manifestBytes;
        if (DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = buffer.toByteArray();
        } else {
            // Convert the UTF-8 manifest bytes to the requested content charset
            manifestBytes = buffer.toString(DEFAULT_CONTENT_CHARSET).getBytes(contentCharset);
        }
        outputStream.write(manifestBytes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:DefaultManifest.java

示例2: fakeManifest

import java.util.jar.Manifest; //导入方法依赖的package包/类
private static InputStream fakeManifest(ModuleInfo m) throws IOException {
    String exp = (String) m.getAttribute("OpenIDE-Module-Public-Packages"); // NOI18N
    if ("-".equals(exp)) { // NOI18N
        return null;
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Manifest man = new Manifest();
    man.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
    man.getMainAttributes().putValue("Bundle-ManifestVersion", "2"); // NOI18N
    man.getMainAttributes().putValue("Bundle-SymbolicName", m.getCodeNameBase()); // NOI18N

    if (m.getSpecificationVersion() != null) {
        String spec = threeDotsWithMajor(m.getSpecificationVersion().toString(), m.getCodeName());
        man.getMainAttributes().putValue("Bundle-Version", spec.toString()); // NOI18N
    }
    if (exp != null) {
        man.getMainAttributes().putValue("Export-Package", exp.replaceAll("\\.\\*", "")); // NOI18N
    } else {
        man.getMainAttributes().putValue("Export-Package", m.getCodeNameBase()); // NOI18N
    }
    man.write(os);
    return new ByteArrayInputStream(os.toByteArray());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:NetigsoBundleFile.java

示例3: updateManifest

import java.util.jar.Manifest; //导入方法依赖的package包/类
private boolean updateManifest(Manifest m, ZipOutputStream zos)
    throws IOException
{
    addVersion(m);
    addCreatedBy(m);
    if (ename != null) {
        addMainClass(m, ename);
    }
    ZipEntry e = new ZipEntry(MANIFEST_NAME);
    e.setTime(System.currentTimeMillis());
    if (flag0) {
        crc32Manifest(e, m);
    }
    zos.putNextEntry(e);
    m.write(zos);
    if (vflag) {
        output(getMsg("out.update.manifest"));
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:Main.java

示例4: setupMRJARModuleInfo

import java.util.jar.Manifest; //导入方法依赖的package包/类
static void setupMRJARModuleInfo(String moduleName) throws IOException {
    Path modClasses = MODULE_CLASSES.resolve(moduleName);
    Path metaInfDir = MRJAR_DIR.resolve(moduleName).resolve("META-INF");
    Path versionSection = metaInfDir.resolve("versions").resolve("9");
    createTestDir(versionSection);

    Path versionModuleInfo = versionSection.resolve("module-info.class");
    System.out.println("copying " + modClasses.resolve("module-info.class") + " to " + versionModuleInfo);
    Files.copy(modClasses.resolve("module-info.class"), versionModuleInfo);

    Manifest manifest = new Manifest();
    manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
    manifest.getMainAttributes().putValue("Multi-Release", "true");
    try (OutputStream os = Files.newOutputStream(metaInfDir.resolve("MANIFEST.MF"))) {
        manifest.write(os);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Basic.java

示例5: testExistingManifest

import java.util.jar.Manifest; //导入方法依赖的package包/类
@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();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:TestJarFinder.java

示例6: generateSignatureFile

import java.util.jar.Manifest; //导入方法依赖的package包/类
/** Write the signature file to the given output stream. */
private void generateSignatureFile(Manifest manifest, OutputStream out)
throws IOException, GeneralSecurityException {
    out.write( ("Signature-Version: 1.0\r\n").getBytes());
    out.write( ("Created-By: 1.0 (Android SignApk)\r\n").getBytes());


    // BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(
            new DigestOutputStream(new ByteArrayOutputStream(), md),
            true, "UTF-8");

    // Digest of the entire manifest
    manifest.write(print);
    print.flush();

    out.write( ("SHA1-Digest-Manifest: "+ Base64.encode(md.digest()) + "\r\n\r\n").getBytes());

    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        if (canceled) break;
        progressHelper.progress( ProgressEvent.PRORITY_NORMAL, resourceAdapter.getString(ResourceAdapter.Item.GENERATING_SIGNATURE_FILE));
        // Digest of the manifest stanza for this entry.
        String nameEntry = "Name: " + entry.getKey() + "\r\n"; 
        print.print( nameEntry);
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        out.write( nameEntry.getBytes());
        out.write( ("SHA1-Digest: " +  Base64.encode(md.digest()) + "\r\n\r\n").getBytes());
    }

}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:38,代码来源:ZipSigner.java

示例7: transform

import java.util.jar.Manifest; //导入方法依赖的package包/类
InputStream transform(InputStream inputStream) throws MojoExecutionException {
    try (InputStream in = inputStream) { // No need for new variable in Java 9.
        Manifest manifest = new Manifest(in);
        Attributes attributes = manifest.getMainAttributes();
        if (!attributes.containsKey(PREMAIN_CLASS)) {
            throw new MojoExecutionException(PREMAIN_CLASS + " not found in MANIFEST.MF. This is a bug in promagent-maven-plugin.");
        }
        attributes.put(CREATED_BY, pluginArtifactId + ":" + pluginVersion);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        manifest.write(out);
        return new ByteArrayInputStream(out.toByteArray());
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to transform MANIFEST.MF: " + e.getMessage(), e);
    }
}
 
开发者ID:fstab,项目名称:promagent,代码行数:16,代码来源:ManifestTransformer.java

示例8: writeMeta

import java.util.jar.Manifest; //导入方法依赖的package包/类
public void writeMeta(File outFile, Manifest manifest) {
    try {
        mBuilder.getOutputStream().putNextEntry(
                new JarEntry("META-INF/PATCH.MF"));
        manifest.write(mBuilder.getOutputStream());

        manifest.write(new FileOutputStream(new File(outFile.getParent(), "PATCH.MF")));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:12,代码来源:PatchBuilder.java

示例9: updateManifest

import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
    * Given the MANIFEST.MF from the war file, update the file and write it to the new war file.
    * 
    * @param newWarOutputStream
    *            new war file
    * @param warInputStream
    *            existing war file
    * @param entry
    *            web.xml entry
    * @throws IOException
    */
   protected void updateManifest(JarOutputStream newWarOutputStream, ZipInputStream warInputStream, ZipEntry entry)
    throws IOException {

ZipEntry newEntry = new ZipEntry(MANIFEST_PATH);
newWarOutputStream.putNextEntry(newEntry);

Manifest manifest = new Manifest(warInputStream);
updateClasspath(manifest);
manifest.write(newWarOutputStream);

newWarOutputStream.closeEntry();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:UpdateWarTask.java

示例10: generateSignatureFile

import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
 * Write the signature file to the given output stream.
 */
private void generateSignatureFile(Manifest manifest, OutputStream out)
        throws IOException, GeneralSecurityException {
    out.write(("Signature-Version: 1.0\r\n").getBytes());
    out.write(("Created-By: 1.0 (Android SignApk)\r\n").getBytes());


    // BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(
            new DigestOutputStream(new ByteArrayOutputStream(), md),
            true, "UTF-8");

    // Digest of the entire manifest
    manifest.write(print);
    print.flush();

    out.write(("SHA1-Digest-Manifest: " + Base64.encode(md.digest()) + "\r\n\r\n").getBytes());

    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        if (canceled) break;
        progressHelper.progress(ProgressEvent.PRORITY_NORMAL, resourceAdapter.getString(ResourceAdapter.Item.GENERATING_SIGNATURE_FILE));
        // Digest of the manifest stanza for this entry.
        String nameEntry = "Name: " + entry.getKey() + "\r\n";
        print.print(nameEntry);
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        out.write(nameEntry.getBytes());
        out.write(("SHA1-Digest: " + Base64.encode(md.digest()) + "\r\n\r\n").getBytes());
    }

}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:ZipSigner.java

示例11: create

import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
 * Creates a new JAR file.
 */
void create(OutputStream out, Manifest manifest)
    throws IOException
{
    ZipOutputStream zos = new JarOutputStream(out);
    if (flag0) {
        zos.setMethod(ZipOutputStream.STORED);
    }
    if (manifest != null) {
        if (vflag) {
            output(getMsg("out.added.manifest"));
        }
        ZipEntry e = new ZipEntry(MANIFEST_DIR);
        e.setTime(System.currentTimeMillis());
        e.setSize(0);
        e.setCrc(0);
        zos.putNextEntry(e);
        e = new ZipEntry(MANIFEST_NAME);
        e.setTime(System.currentTimeMillis());
        if (flag0) {
            crc32Manifest(e, manifest);
        }
        zos.putNextEntry(e);
        manifest.write(zos);
        zos.closeEntry();
    }
    for (File file: entries) {
        addFile(zos, file);
    }
    zos.close();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:Main.java

示例12: crc32Manifest

import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
 * Computes the crc32 of a Manifest.  This is necessary when the
 * ZipOutputStream is in STORED mode.
 */
private void crc32Manifest(ZipEntry e, Manifest m) throws IOException {
    CRC32OutputStream os = new CRC32OutputStream();
    m.write(os);
    os.updateEntry(e);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Main.java

示例13: signatureFile

import java.util.jar.Manifest; //导入方法依赖的package包/类
/** Write a .SF file with a digest of the specified manifest. */
private static void signatureFile(Manifest manifest, SignatureStream out)
        throws IOException, GeneralSecurityException {
    Manifest sf = new Manifest();
    Attributes main = sf.getMainAttributes();
    main.putValue("Signature-Version", "1.0");
    
    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(
            new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8");

    // Digest of the entire manifest
    manifest.write(print);
    print.flush();
    main.putValue("SHA1-Digest-Manifest", base64.encode(md.digest()));
    
    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();
        Attributes sfAttr = new Attributes();
        sfAttr.putValue("SHA1-Digest", base64.encode(md.digest()));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    
    System.out.print("\rGenerating signature file...");
    
    sf.write(out);

    // A bug in the java.util.jar implementation of Android platforms
    // up to version 1.6 will cause a spurious IOException to be thrown
    // if the length of the signature file is a multiple of 1024 bytes.
    // As a workaround, add an extra CRLF in this case.
    if ((out.size() % 1024) == 0) {
        out.write('\r');
        out.write('\n');
    }
}
 
开发者ID:KuroroLucilfer,项目名称:PackageSigner2,代码行数:45,代码来源:Signer.java

示例14: writeSignatureFile

import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
 * Writes a .SF file with a digest to the manifest.
 */
private void writeSignatureFile(OutputStream out) throws IOException, GeneralSecurityException {
    Manifest sf = new Manifest();
    Attributes main = sf.getMainAttributes();
    main.putValue("Signature-Version", "1.0");
    main.putValue("Created-By", "1.0 (Android)");

    MessageDigest md = MessageDigest.getInstance(DIGEST_ALGORITHM);
    PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md),
                                        true,
                                        SdkConstants.UTF_8);

    // Digest of the entire manifest
    mManifest.write(print);
    print.flush();
    main.putValue(DIGEST_MANIFEST_ATTR, new String(Base64.encode(md.digest()), "ASCII"));

    Map<String, Attributes> entries = mManifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue(DIGEST_ATTR, new String(Base64.encode(md.digest()), "ASCII"));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    CountOutputStream cout = new CountOutputStream(out);
    sf.write(cout);

    // A bug in the java.util.jar implementation of Android platforms
    // up to version 1.6 will cause a spurious IOException to be thrown
    // if the length of the signature file is a multiple of 1024 bytes.
    // As a workaround, add an extra CRLF in this case.
    if ((cout.size() % 1024) == 0) {
        cout.write('\r');
        cout.write('\n');
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:46,代码来源:LocalSignedJarBuilder.java

示例15: writeSignatureFile

import java.util.jar.Manifest; //导入方法依赖的package包/类
/** Writes a .SF file with a digest to the manifest. */
private void writeSignatureFile(SignatureOutputStream out)
        throws IOException, GeneralSecurityException {
    Manifest sf = new Manifest();
    Attributes main = sf.getMainAttributes();
    main.putValue("Signature-Version", "1.0");
    main.putValue("Created-By", "1.0 (Android)");

    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance(DIGEST_ALGORITHM);
    PrintStream print = new PrintStream(
            new DigestOutputStream(new ByteArrayOutputStream(), md),
            true, SdkConstants.UTF_8);

    // Digest of the entire manifest
    mManifest.write(print);
    print.flush();
    main.putValue(DIGEST_MANIFEST_ATTR, base64.encode(md.digest()));

    Map<String, Attributes> entries = mManifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue(DIGEST_ATTR, base64.encode(md.digest()));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }

    sf.write(out);

    // A bug in the java.util.jar implementation of Android platforms
    // up to version 1.6 will cause a spurious IOException to be thrown
    // if the length of the signature file is a multiple of 1024 bytes.
    // As a workaround, add an extra CRLF in this case.
    if ((out.size() % 1024) == 0) {
        out.write('\r');
        out.write('\n');
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:46,代码来源:SignedJarBuilder.java


注:本文中的java.util.jar.Manifest.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。