本文整理汇总了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);
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}