use of java.util.zip.ZipEntry in project OpenMEAP by OpenMEAP.
the class ZipUtils method getUncompressedSize.
/**
* Determines the uncompressed size of a zip file, without deflating it.
*
* @param zipFile
* @return The size in bytes.
*/
public static Long getUncompressedSize(ZipFile zipFile) {
Enumeration e = zipFile.entries();
long uncompressedSize = 0L;
while (e.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) e.nextElement();
uncompressedSize = uncompressedSize + zipEntry.getSize();
}
return Long.valueOf(uncompressedSize);
}
use of java.util.zip.ZipEntry in project screenbird by adamhub.
the class IOUtils method isZip.
/** Return true if this file is a zip file. */
public static boolean isZip(File file) throws IOException {
if (file.exists() == false)
return false;
InputStream in = null;
try {
in = new FileInputStream(file);
ZipInputStream zipIn = new ZipInputStream(in);
ZipEntry e = zipIn.getNextEntry();
if (e == null)
return false;
int ctr = 0;
while (e != null && ctr < 4) {
e = zipIn.getNextEntry();
ctr++;
}
return true;
} catch (Throwable t) {
return false;
} finally {
try {
in.close();
} catch (Throwable t) {
}
}
}
use of java.util.zip.ZipEntry in project screenbird by adamhub.
the class IOUtils method getZipEntry.
/** Returns an InputStream that will read a specific entry
* from a zip file.
* @param file the zip file.
* @param entryName the name of the entry.
* @return an InputStream that reads that entry.
* @throws IOException
*/
public static InputStream getZipEntry(File file, String entryName) throws IOException {
FileInputStream in = new FileInputStream(file);
ZipInputStream zipIn = new ZipInputStream(in);
ZipEntry e = zipIn.getNextEntry();
while (e != null) {
if (e.getName().equals(entryName))
return zipIn;
e = zipIn.getNextEntry();
}
return null;
}
use of java.util.zip.ZipEntry in project atlas by alibaba.
the class BundleArchiveRevision method installSoLib.
/**
* 安装so库
* @throws IOException
*/
public void installSoLib(File bundle) throws IOException {
ZipFile zip = null;
try {
zip = new ZipFile(bundle);
String extractTag = "lib/armeabi";
if (Build.CPU_ABI.contains("x86")) {
if (zip.getEntry("lib/x86/") != null) {
extractTag = "lib/x86";
}
}
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
ZipEntry zipEntry = (ZipEntry) entries.nextElement();
String entryName = zipEntry.getName();
if (entryName.equalsIgnoreCase("../")) {
continue;
}
if (entryName.indexOf(extractTag) != -1) {
extractEntry(zip, zipEntry);
}
}
} catch (final Exception e) {
e.printStackTrace();
} finally {
if (null != zip) {
zip.close();
}
}
}
use of java.util.zip.ZipEntry in project atlas by alibaba.
the class DexReleaser method releaseDexes.
public static boolean releaseDexes(File bundleFile, File reversionDir) throws IOException {
ZipFile zipFile = new ZipFile(bundleFile);
boolean hasDexFile = hasDexFile(zipFile);
if (!hasDexFile) {
return true;
}
if (!isArt()) {
Enumeration entryEnumeration = zipFile.entries();
while (entryEnumeration.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) entryEnumeration.nextElement();
if (zipEntry.getName().endsWith(DEX_SUFFIX)) {
File dexFile = new File(reversionDir, zipEntry.getName());
FileOutputStream fileOutputStream = new FileOutputStream(dexFile);
copy(zipFile.getInputStream(zipEntry), fileOutputStream);
fileOutputStream.close();
}
}
return true;
} else {
File mergedFile = preProcessPatch(zipFile, bundleFile);
if (mergedFile != null && mergedFile.exists()) {
bundleFile.delete();
boolean success = mergedFile.renameTo(bundleFile);
if (!success || !isNewBundleFileValid(bundleFile)) {
return false;
}
} else {
return false;
}
try {
zipFile.close();
} catch (Throwable e) {
}
}
return true;
}
Aggregations