use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.
the class RecoverySystem method getTrustedCerts.
/** @return the set of certs that can be used to sign an OTA package. */
private static HashSet<Certificate> getTrustedCerts(File keystore) throws IOException, GeneralSecurityException {
HashSet<Certificate> trusted = new HashSet<Certificate>();
if (keystore == null) {
keystore = DEFAULT_KEYSTORE;
}
ZipFile zip = new ZipFile(keystore);
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
InputStream is = zip.getInputStream(entry);
try {
trusted.add(cf.generateCertificate(is));
} finally {
is.close();
}
}
} finally {
zip.close();
}
return trusted;
}
use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.
the class PackageHelper method extractPublicFiles.
public static int extractPublicFiles(String packagePath, File publicZipFile) throws IOException {
final FileOutputStream fstr;
final ZipOutputStream publicZipOutStream;
if (publicZipFile == null) {
fstr = null;
publicZipOutStream = null;
} else {
fstr = new FileOutputStream(publicZipFile);
publicZipOutStream = new ZipOutputStream(fstr);
}
int size = 0;
try {
final ZipFile privateZip = new ZipFile(packagePath);
try {
// Copy manifest, resources.arsc and res directory to public zip
for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) {
final String zipEntryName = zipEntry.getName();
if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) {
size += zipEntry.getSize();
if (publicZipFile != null) {
copyZipEntry(zipEntry, privateZip, publicZipOutStream);
}
}
}
} finally {
try {
privateZip.close();
} catch (IOException e) {
}
}
if (publicZipFile != null) {
publicZipOutStream.finish();
publicZipOutStream.flush();
FileUtils.sync(fstr);
publicZipOutStream.close();
FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1);
}
} finally {
IoUtils.closeQuietly(publicZipOutStream);
}
return size;
}
use of java.util.zip.ZipFile in project OpenRefine by OpenRefine.
the class FileHistoryEntryManager method loadChange.
protected void loadChange(HistoryEntry historyEntry, File file) throws Exception {
ZipFile zipFile = new ZipFile(file);
try {
Pool pool = new Pool();
ZipEntry poolEntry = zipFile.getEntry("pool.txt");
if (poolEntry != null) {
pool.load(new InputStreamReader(zipFile.getInputStream(poolEntry)));
}
// else, it's a legacy project file
historyEntry.setChange(History.readOneChange(zipFile.getInputStream(zipFile.getEntry("change.txt")), pool));
} finally {
zipFile.close();
}
}
use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.
the class ClassPathPackageInfoSource method getJarEntries.
/**
* Gets the class and package entries from a Jar.
*/
private Set<String> getJarEntries(File jarFile) throws IOException {
Set<String> entryNames = jarFiles.get(jarFile);
if (entryNames == null) {
entryNames = Sets.newHashSet();
ZipFile zipFile = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
String entryName = entries.nextElement().getName();
if (entryName.endsWith(CLASS_EXTENSION)) {
// add the entry name of the class
entryNames.add(entryName);
// add the entry name of the classes package, i.e. the entry name of
// the directory that the class is in. Used to quickly skip jar files
// if they do not contain a certain package.
//
// Also add parent packages so that a JAR that contains
// pkg1/pkg2/Foo.class will be marked as containing pkg1/ in addition
// to pkg1/pkg2/ and pkg1/pkg2/Foo.class. We're still interested in
// JAR files that contains subpackages of a given package, even if
// an intermediate package contains no direct classes.
//
// Classes in the default package will cause a single package named
// "" to be added instead.
int lastIndex = entryName.lastIndexOf('/');
do {
String packageName = entryName.substring(0, lastIndex + 1);
entryNames.add(packageName);
lastIndex = entryName.lastIndexOf('/', lastIndex - 1);
} while (lastIndex > 0);
}
}
jarFiles.put(jarFile, entryNames);
}
return entryNames;
}
use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.
the class AsmAnalyzer method parseZip.
/**
* Parses a JAR file and returns a list of all classes founds using a map
* class name => ASM ClassReader. Class names are in the form "android.view.View".
*/
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
for (String jarPath : jarPathList) {
ZipFile zip = new ZipFile(jarPath);
Enumeration<? extends ZipEntry> entries = zip.entries();
ZipEntry entry;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
ClassReader cr = new ClassReader(zip.getInputStream(entry));
String className = classReaderToClassName(cr);
classes.put(className, cr);
}
}
}
return classes;
}
Aggregations