當前位置: 首頁>>代碼示例>>Java>>正文


Java Attributes.putValue方法代碼示例

本文整理匯總了Java中java.util.jar.Attributes.putValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Attributes.putValue方法的具體用法?Java Attributes.putValue怎麽用?Java Attributes.putValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.jar.Attributes的用法示例。


在下文中一共展示了Attributes.putValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: redefineFoo

import java.util.jar.Attributes; //導入方法依賴的package包/類
static void redefineFoo() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    Attributes mainAttrs = manifest.getMainAttributes();
    mainAttrs.putValue("Agent-Class", FooAgent.class.getName());
    mainAttrs.putValue("Can-Redefine-Classes", "true");
    mainAttrs.putValue("Can-Retransform-Classes", "true");

    Path jar = Files.createTempFile("myagent", ".jar");
    try {
        JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jar.toFile()), manifest);
        add(jarStream, FooAgent.class);
        add(jarStream, FooTransformer.class);
        jarStream.close();
        runAgent(jar);
    } finally {
        Files.deleteIfExists(jar);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:RedefineMethodUsedByMultipleMethodHandles.java

示例2: createJar

import java.util.jar.Attributes; //導入方法依賴的package包/類
private void createJar(Map<String, String> manifestAttributes) throws IOException {
    emitFile();

    Manifest manifest = new Manifest();
    final Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.putValue("Manifest-Version", "1.0");
    mainAttributes.putValue("Main-Class", PRINT_VERSION_CLASS);
    manifestAttributes.forEach(mainAttributes::putValue);

    try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(VERSION_JAR), manifest)) {
        jar.putNextEntry(new ZipEntry(PRINT_VERSION_CLASS + ".class"));
        jar.write(Files.readAllBytes(clsFile.toPath()));
        jar.closeEntry();
    } finally {
        javaFile.delete();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MultipleJRERemoved.java

示例3: getMeta

import java.util.jar.Attributes; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Override
protected Manifest getMeta() {
    Manifest retManifest = new Manifest();
    Attributes main = retManifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("Patch-Name", name);

    try {
        fillManifest(main);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return retManifest;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:19,代碼來源:MergePatch.java

示例4: getMeta

import java.util.jar.Attributes; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
protected Manifest getMeta() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("From-File", baseFiles.get(0).getName());
    main.putValue("To-File", newFiles.get(0).getName());
    main.putValue("Patch-Name", name);
    main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes));
    main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses));
    main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods));
    main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses));
    main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses));
    main.putValue(name + "-add-classes", Formater.dotStringList(addClasses));

    return manifest;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:20,代碼來源:ApkPatch.java

示例5: redefineFoo

import java.util.jar.Attributes; //導入方法依賴的package包/類
protected void redefineFoo() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    Attributes mainAttrs = manifest.getMainAttributes();
    mainAttrs.putValue("Agent-Class", FooAgent.class.getName());
    mainAttrs.putValue("Can-Redefine-Classes", "true");
    mainAttrs.putValue("Can-Retransform-Classes", "true");

    Path jar = Files.createTempFile("myagent", ".jar");
    try {
        JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jar.toFile()), manifest);
        add(jarStream, FooAgent.class);
        add(jarStream, FooTransformer.class);
        jarStream.close();

        loadAgent(jar);
    } finally {
        Files.deleteIfExists(jar);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:RedefineClassTest.java

示例6: createMultiReleaseJar

import java.util.jar.Attributes; //導入方法依賴的package包/類
private static File createMultiReleaseJar(
        @NonNull final File loc,
        final boolean hasMultiVersionAttr,
        @NonNull final Collection<Pair<String,Collection<Integer>>> spec) throws IOException {
    final Manifest mf = new Manifest();
    final Attributes attrs = mf.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //NOI18N
    if (hasMultiVersionAttr) {
        attrs.putValue(
                "Multi-Release",      //NOI18N
                Boolean.TRUE.toString());
    }
    try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(loc), mf)) {
        for (Pair<String,Collection<Integer>> p : spec) {
            final String fqn = p.first();
            final Collection<Integer> versions = p.second();
            final String path = FileObjects.convertPackage2Folder(fqn) + ".class";  //NOI18N
            final String name = FileObjects.getBaseName(fqn,'.');                   //NOI18N
            final Collection<String[]> prefixes = new ArrayList<>();
            for (Integer version : versions) {
                if (version == 0) {
                    prefixes.add(new String[]{"","Base"});                  //NOI18N
                } else {
                    prefixes.add(new String[]{"META-INF/versions/"+version, version.toString()});   //NOI18N
                }
            }
            for (String[] prefix : prefixes) {
                final String pathWithScope = prefix[0].isEmpty() ?
                        path :
                        String.format("%s/%s", prefix[0], path);            //NOI18N
                jar.putNextEntry(new ZipEntry(pathWithScope));
                jar.write(String.format("%s %s", name, prefix[1]).getBytes(Charset.forName("UTF-8")));  //NOI18N
                jar.closeEntry();
            }
        }
    }
    return loc;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:MRJARCachingFileManagerTest.java

示例7: getDigestAttributes

import java.util.jar.Attributes; //導入方法依賴的package包/類
private Attributes getDigestAttributes(
        ZipEntry ze, ZipFile zf, MessageDigest[] digests)
        throws IOException {

    String[] base64Digests = getDigests(ze, zf, digests);
    Attributes attrs = new Attributes();

    for (int i = 0; i < digests.length; i++) {
        attrs.putValue(digests[i].getAlgorithm() + "-Digest",
                base64Digests[i]);
    }
    return attrs;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:JarSigner.java

示例8: handleDisplayAttribute

import java.util.jar.Attributes; //導入方法依賴的package包/類
private void handleDisplayAttribute(Properties props, Attributes netbeans, Attributes osgi, String netbeansHeader, String osgiHeader) throws IOException {
    String val = netbeans.getValue(netbeansHeader);
    if (val != null) {
        osgi.putValue(osgiHeader, val);
    } else if (props.containsKey(netbeansHeader)) {
        osgi.putValue(osgiHeader, "%" + netbeansHeader);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:MakeOSGi.java

示例9: processFragment

import java.util.jar.Attributes; //導入方法依賴的package包/類
private void processFragment(File fragment) throws Exception {
    String cnb = findFragmentHost(fragment);
    File bundleFile = new File(destdir, fragment.getName());
    if (bundleFile.lastModified() > fragment.lastModified()) {
        log("Skipping " + fragment + " since " + bundleFile + " is newer", Project.MSG_VERBOSE);
        return;
    }
    log("Processing " + fragment + " into " + bundleFile);
    Manifest mf = new Manifest();
    Attributes attr = mf.getMainAttributes();
    attr.putValue("Manifest-Version", "1.0"); // workaround for JDK bug
    attr.putValue("Bundle-ManifestVersion", "2");
    attr.putValue("Bundle-SymbolicName", cnb + "-branding");
    attr.putValue("Fragment-Host", cnb);
    try (JarFile jar = new JarFile(fragment);
            OutputStream bundle = new FileOutputStream(bundleFile);
            ZipOutputStream zos = new JarOutputStream(bundle, mf)) {
        Set<String> parents = new HashSet<>();
        Enumeration<? extends ZipEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String path = entry.getName();
            if (path.endsWith("/") || path.equals("META-INF/MANIFEST.MF")) {
                continue;
            }   try (InputStream is = jar.getInputStream(entry)) {
                writeEntry(zos, path, is, parents);
            }
        }
        zos.finish();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:MakeOSGi.java

示例10: setUp

import java.util.jar.Attributes; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    clearWorkDir();

    // XXX NbRepository seems to randomly produce different instances of Services/MIMEResolver
    // so when using "real" repo, test can fail randomly
    // XXX cannot use MockLookup for now or MetaInfServicesTest fails
    // (clash between org.foo.Interface in openide.util/test and services-jar-1)
    System.setProperty(Lookup.class.getName(), MyLkp.class.getName());
    FileUtil.createFolder(FileUtil.getConfigRoot(), "Services/MIMEResolver");
    
    err = ErrorManager.getDefault().getInstance("TEST-" + getName());

    NbLoaderPool.IN_TEST = true; // allow it to fire changes w/o module system
    DataLoaderPool.getDefault().addChangeListener(this);
    
    assertEquals("No change in pool during initialization", 0, poolChange);
    
    LocalFileSystem lfs = new LocalFileSystem();
    lfs.setRootDirectory(getWorkDir());
    
    fo = FileUtil.createData(lfs.getRoot(), "X.lenka");
    
    Attributes at = new Attributes();
    at.putValue("OpenIDE-Module-Class", "Loader");
    String name = Lenka.class.getName().replace('.', '/') + ".class";
    ls = (ManifestSection.LoaderSection)ManifestSection.create(name, at, null);
    NbLoaderPool.add(ls);
    
    loader = Lenka.getLoader(Lenka.class);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:NbLoaderPoolResolverChangeTest.java

示例11: prepareResourceEntries

import java.util.jar.Attributes; //導入方法依賴的package包/類
private void prepareResourceEntries(DeploymentDescriptor deploymentDescriptor) throws SLException {
    for (Resource resource : deploymentDescriptor.getResources2_0()) {
        String resourceConfigPath = (String) resource.getParameters().get(SupportedParameters.SERVICE_CONFIG_PATH);
        if (resourceConfigPath != null) {
            prepareFile(resourceConfigPath);

            Attributes attributes = new Attributes();
            attributes.putValue(MtaArchiveHelper.ATTR_MTA_RESOURCE, resource.getName());
            manifestEntries.put(resourceConfigPath, attributes);
        }
    }
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:13,代碼來源:MtaArchiveBuilder.java

示例12: addOTACert

import java.util.jar.Attributes; //導入方法依賴的package包/類
/**
 * Add a copy of the public key to the archive; this should exactly match one
 * of the files in /system/etc/security/otacerts.zip on the device. (The same
 * cert can be extracted from the CERT.RSA file but this is much easier to get
 * at.)
 */
private static void addOTACert(
        JarOutputStream outputJar,
        long timestamp,
        Manifest manifest)
        throws IOException, GeneralSecurityException {
    InputStream input = new ByteArrayInputStream(readKeyContents(PUBLIC_KEY));
    
    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    
    JarEntry je = new JarEntry(OTACERT_NAME);
    je.setTime(timestamp);
    outputJar.putNextEntry(je);
    
    byte[] b = new byte[4096];
    int read;
    
    System.out.print("\rGenerating OTA certificate...");
    
    while ((read = input.read(b)) != -1) {
        outputJar.write(b, 0, read);
        md.update(b, 0, read);
    }
    input.close();
    
    Attributes attr = new Attributes();
    attr.putValue("SHA1-Digest", base64.encode(md.digest()));
    manifest.getEntries().put(OTACERT_NAME, attr);
}
 
開發者ID:KuroroLucilfer,項目名稱:PackageSigner2,代碼行數:36,代碼來源:Signer.java

示例13: prepareModuleEntries

import java.util.jar.Attributes; //導入方法依賴的package包/類
private void prepareModuleEntries(String path, List<Module> modules) throws SLException {
    prepareFile(path);
    Attributes attributes = new Attributes();
    List<String> moduleNames = modules.stream().map(module -> module.getName()).collect(Collectors.toList());
    attributes.putValue(MtaArchiveHelper.ATTR_MTA_MODULE, String.join(Constants.MODULE_SEPARATOR, moduleNames));
    manifestEntries.put(path, attributes);
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:8,代碼來源:MtaArchiveBuilder.java

示例14: createManifest

import java.util.jar.Attributes; //導入方法依賴的package包/類
private Manifest createManifest() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (DexPatch)");
    main.putValue("Created-Time", (new Date(System.currentTimeMillis())).toGMTString());
    return manifest;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:9,代碼來源:DexPatchPackageTask.java

示例15: LocalSignedJarBuilder

import java.util.jar.Attributes; //導入方法依賴的package包/類
/**
 * Creates a {@link SignedJarBuilder} with a given output stream, and signing information.
 * <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then
 * the archive will not be signed.
 *
 * @param out         the {@link OutputStream} where to write the Jar archive.
 * @param key         the {@link PrivateKey} used to sign the archive, or <code>null</code>.
 * @param certificate the {@link X509Certificate} used to sign the archive, or
 *                    <code>null</code>.
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
public LocalSignedJarBuilder(@NonNull OutputStream out,
                             @Nullable PrivateKey key,
                             @Nullable X509Certificate certificate,
                             @Nullable String builtBy,
                             @Nullable String createdBy,
                             @Nullable String signFile) throws IOException, NoSuchAlgorithmException {
    mOutputJar = new JarOutputStream(new BufferedOutputStream(out));
    mOutputJar.setLevel(9);
    mKey = key;
    mCertificate = certificate;
    mSignFile = signFile;

    if (mKey != null && mCertificate != null) {
        mManifest = new Manifest();
        Attributes main = mManifest.getMainAttributes();
        main.putValue("Manifest-Version", "1.0");
        if (builtBy != null) {
            main.putValue("Built-By", builtBy);
        }
        if (createdBy != null) {
            main.putValue("Created-By", createdBy);
        }

        mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    }
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:39,代碼來源:LocalSignedJarBuilder.java


注:本文中的java.util.jar.Attributes.putValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。