本文整理汇总了Java中java.util.jar.JarFile类的典型用法代码示例。如果您正苦于以下问题:Java JarFile类的具体用法?Java JarFile怎么用?Java JarFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JarFile类属于java.util.jar包,在下文中一共展示了JarFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPluginDescription
import java.util.jar.JarFile; //导入依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
try (JarFile jar = new JarFile(file)) {
JarEntry entry = jar.getJarEntry("nukkit.yml");
if (entry == null) {
entry = jar.getJarEntry("plugin.yml");
if (entry == null) {
return null;
}
}
try (InputStream stream = jar.getInputStream(entry)) {
return new PluginDescription(Utils.readFile(stream));
}
} catch (IOException e) {
return null;
}
}
示例2: changeManifest
import java.util.jar.JarFile; //导入依赖的package包/类
protected static File changeManifest(File dir, String newName, File orig, String manifest) throws IOException {
File f = new File(dir, newName);
Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
mf.getMainAttributes().putValue("Manifest-Version", "1.0");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
JarFile jf = new JarFile(orig);
Enumeration<JarEntry> en = jf.entries();
InputStream is;
while (en.hasMoreElements()) {
JarEntry e = en.nextElement();
if (e.getName().equals("META-INF/MANIFEST.MF")) {
continue;
}
os.putNextEntry(e);
is = jf.getInputStream(e);
FileUtil.copy(is, os);
is.close();
os.closeEntry();
}
os.close();
return f;
}
示例3: signWithJarSignerAPI
import java.util.jar.JarFile; //导入依赖的package包/类
private static void signWithJarSignerAPI(String jarName)
throws Throwable {
// Get JarSigner
try (FileInputStream fis = new FileInputStream(KEYSTORE)) {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(fis, STOREPASS.toCharArray());
PrivateKey pk = (PrivateKey)ks.getKey(ALIAS, KEYPASS.toCharArray());
Certificate cert = ks.getCertificate(ALIAS);
JarSigner signer = new JarSigner.Builder(pk,
CertificateFactory.getInstance("X.509").generateCertPath(
Collections.singletonList(cert)))
.build();
// Sign jar
try (ZipFile src = new JarFile(jarName);
FileOutputStream out = new FileOutputStream(SIGNED_JAR)) {
signer.sign(src,out);
}
}
}
示例4: getBuildDocHandler
import java.util.jar.JarFile; //导入依赖的package包/类
@Override
public Object getBuildDocHandler(ClassLoader docsClassLoader, Iterable<File> classpath) throws NoSuchMethodException, ClassNotFoundException, IOException, IllegalAccessException {
Class<?> docHandlerFactoryClass = getDocHandlerFactoryClass(docsClassLoader);
Method docHandlerFactoryMethod = docHandlerFactoryClass.getMethod("fromJar", JarFile.class, String.class);
JarFile documentationJar = findDocumentationJar(classpath);
try {
return docHandlerFactoryMethod.invoke(null, documentationJar, "play/docs/content");
} catch (InvocationTargetException e) {
throw UncheckedException.unwrapAndRethrow(e);
}
}
示例5: jarDir
import java.util.jar.JarFile; //导入依赖的package包/类
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();
}
示例6: computeFieldMatches
import java.util.jar.JarFile; //导入依赖的package包/类
private static void computeFieldMatches(File memberMatchesFile, JarFile destJar, File destMappingsFile, File classMatchesFile)
throws IOException, MappingParseException {
System.out.println("Reading class matches...");
ClassMatches classMatches = MatchesReader.readClasses(classMatchesFile);
System.out.println("Reading mappings...");
Mappings destMappings = new MappingsReader().read(new FileReader(destMappingsFile));
System.out.println("Indexing dest jar...");
Deobfuscator destDeobfuscator = new Deobfuscator(destJar);
System.out.println("Writing matches...");
// get the matched and unmatched mappings
MemberMatches<FieldEntry> fieldMatches = MappingsConverter.computeMemberMatches(
destDeobfuscator,
destMappings,
classMatches,
MappingsConverter.getFieldDoer()
);
MatchesWriter.writeMembers(fieldMatches, memberMatchesFile);
System.out.println("Wrote:\n\t" + memberMatchesFile.getAbsolutePath());
}
示例7: loadCorePlugin
import java.util.jar.JarFile; //导入依赖的package包/类
void loadCorePlugin(File file, CaoutchoucClassLoader classLoader) {
try {
JarFile jarFile = new JarFile(file);
Manifest manifest = jarFile.getManifest();
if(manifest == null)
throw new FileNotFoundException("Jar does not contain manifest");
String corePlugin = manifest.getMainAttributes().getValue("corePlugin");
if(corePlugin == null)
throw new IllegalArgumentException("Manifest does not contain \"corePlugin\" tag");
Caoutchouc.addInClassLoader(file);
Class<?> corePluginClass = Class.forName(corePlugin, false, classLoader);
if(ICorePlugin.class.isAssignableFrom(corePluginClass))
this.corePluginsClass.add(corePluginClass);
} catch(Exception exc) {
System.err.println(String.format("Unable to load core plugin %s", file.getName()));
exc.printStackTrace();
}
}
示例8: generateLargeJar
import java.util.jar.JarFile; //导入依赖的package包/类
static void generateLargeJar(File result, File source) throws IOException {
if (result.exists()) {
result.delete();
}
try (JarOutputStream copyTo = new JarOutputStream(new FileOutputStream(result));
JarFile srcJar = new JarFile(source)) {
for (JarEntry je : Collections.list(srcJar.entries())) {
copyTo.putNextEntry(je);
if (!je.isDirectory()) {
copyStream(srcJar.getInputStream(je), copyTo);
}
copyTo.closeEntry();
}
int many = Short.MAX_VALUE * 2 + 2;
for (int i = 0 ; i < many ; i++) {
JarEntry e = new JarEntry("F-" + i + ".txt");
copyTo.putNextEntry(e);
}
copyTo.flush();
copyTo.close();
}
}
示例9: get2thDexSHA1
import java.util.jar.JarFile; //导入依赖的package包/类
/**
* 获取dex2文件的SHA1-Digest值
*
* @param context
* @return
*/
private String get2thDexSHA1(Context context) {
ApplicationInfo info = context.getApplicationInfo();
String source = info.sourceDir;
try {
JarFile jar = new JarFile(source);
Manifest mf = jar.getManifest();
Map<String, Attributes> map = mf.getEntries();
Attributes a = map.get("classes2.dex");
return a.getValue("SHA1-Digest");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例10: loadLocalizedBundlesFromPlatform
import java.util.jar.JarFile; //导入依赖的package包/类
private void loadLocalizedBundlesFromPlatform(final BrandableModule moduleEntry,
final String bundleEntry, final Set<String> keys, final Set<BundleKey> bundleKeys) throws IOException {
Properties p = new Properties();
JarFile module = new JarFile(moduleEntry.getJarLocation());
JarEntry je = module.getJarEntry(bundleEntry);
InputStream is = module.getInputStream(je);
File bundle = new File(getModuleEntryDirectory(moduleEntry),bundleEntry);
try {
p.load(is);
} finally {
is.close();
}
for (String key : NbCollections.checkedMapByFilter(p, String.class, String.class, true).keySet()) {
if (keys.contains(key)) {
String value = p.getProperty(key);
bundleKeys.add(new BundleKey(moduleEntry, bundle, key, value));
}
}
}
示例11: copyJarFile
import java.util.jar.JarFile; //导入依赖的package包/类
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
if (in.getManifest() != null) {
ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
out.putNextEntry(me);
in.getManifest().write(out);
out.closeEntry();
}
byte[] buffer = new byte[1 << 14];
for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
out.putNextEntry(je);
for (int nr; 0 < (nr = in.read(buffer)); ) {
out.write(buffer, 0, nr);
}
}
in.close();
markJarFile(out); // add PACK200 comment
}
示例12: get2thDexSHA1
import java.util.jar.JarFile; //导入依赖的package包/类
/**
* Get classes.dex file signature
*
* @param context
* @return
*/
private String get2thDexSHA1(Context context) {
ApplicationInfo ai = context.getApplicationInfo();
String source = ai.sourceDir;
try {
JarFile jar = new JarFile(source);
java.util.jar.Manifest mf = jar.getManifest();
Map<String, Attributes> map = mf.getEntries();
Attributes a = map.get("classes2.dex");
if(a!=null){
return a.getValue("SHA1-Digest");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例13: testNames
import java.util.jar.JarFile; //导入依赖的package包/类
@Test
public void testNames() throws Exception {
String rname = "version/Version.class";
String vname = "META-INF/versions/9/version/Version.class";
ZipEntry ze1;
ZipEntry ze2;
try (JarFile jf = new JarFile(multirelease)) {
ze1 = jf.getEntry(vname);
}
Assert.assertEquals(ze1.getName(), vname);
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Runtime.Version.parse("9"))) {
ze2 = jf.getEntry(rname);
}
Assert.assertEquals(ze2.getName(), rname);
Assert.assertNotEquals(ze1.getName(), ze2.getName());
}
示例14: getInputStream
import java.util.jar.JarFile; //导入依赖的package包/类
public static InputStream getInputStream(String fname, JarFile jarFile,
JspCompilationContext ctxt, ErrorDispatcher err)
throws JasperException, IOException {
InputStream in = null;
if (jarFile != null) {
String jarEntryName = fname.substring(1, fname.length());
ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
if (jarEntry == null) {
throw new FileNotFoundException(Localizer.getMessage(
"jsp.error.file.not.found", fname));
}
in = jarFile.getInputStream(jarEntry);
} else {
in = ctxt.getResourceAsStream(fname);
}
if (in == null) {
throw new FileNotFoundException(Localizer.getMessage(
"jsp.error.file.not.found", fname));
}
return in;
}
示例15: checkTimestamp
import java.util.jar.JarFile; //导入依赖的package包/类
static void checkTimestamp(String file, String policyId, String digestAlg)
throws Exception {
try (JarFile jf = new JarFile(file)) {
JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
try (InputStream is = jf.getInputStream(je)) {
byte[] content = IOUtils.readFully(is, -1, true);
PKCS7 p7 = new PKCS7(content);
SignerInfo[] si = p7.getSignerInfos();
if (si == null || si.length == 0) {
throw new Exception("Not signed");
}
PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
.getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
TimestampToken tt =
new TimestampToken(tsToken.getContentInfo().getData());
if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
throw new Exception("Digest alg different");
}
if (!tt.getPolicyID().equals(policyId)) {
throw new Exception("policyId different");
}
}
}
}