use of java.util.zip.ZipFile in project tinker by Tencent.
the class FileOperation method getZipEntryMd5.
public static String getZipEntryMd5(File file, String entryName) {
ZipFile zipFile = null;
try {
zipFile = new ZipFile(file);
ZipEntry entry = zipFile.getEntry(entryName);
if (entry == null) {
return null;
}
return MD5.getMD5(zipFile.getInputStream(entry), 1024 * 100);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
use of java.util.zip.ZipFile in project tinker by Tencent.
the class FileUtil method mergeZip.
/**
* merge zip file
*
* @param zipOutputFullFilename
* @param mergeZipFullFilenameList
*/
public static void mergeZip(String zipOutputFullFilename, List<String> mergeZipFullFilenameList) {
FileUtil.createFile(zipOutputFullFilename);
ZipOutputStream zipOutputStream = null;
try {
zipOutputStream = new ZipOutputStream(new FileOutputStream(zipOutputFullFilename));
if (mergeZipFullFilenameList != null) {
for (String zipFullFilename : mergeZipFullFilenameList) {
if (isExist(zipFullFilename)) {
ZipFile zipFile = new ZipFile(zipFullFilename);
Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
while (enumeration.hasMoreElements()) {
ZipEntry zipEntry = enumeration.nextElement();
InputStream inputStream = zipFile.getInputStream(zipEntry);
addZipEntry(zipOutputStream, zipEntry, inputStream);
}
zipFile.close();
}
}
}
} catch (Exception e) {
throw new FileUtilException(e);
} finally {
try {
if (zipOutputStream != null) {
zipOutputStream.close();
}
} catch (Exception e) {
throw new FileUtilException(e);
}
}
}
use of java.util.zip.ZipFile in project sonarqube by SonarSource.
the class ZipUtilsTest method zip_directory.
@Test
public void zip_directory() throws IOException {
File foo = FileUtils.toFile(getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldZipDirectory/foo.txt"));
File dir = foo.getParentFile();
File zip = temp.newFile();
ZipUtils.zipDir(dir, zip);
assertThat(zip).exists().isFile();
assertThat(zip.length()).isGreaterThan(1L);
Iterator<? extends ZipEntry> zipEntries = Iterators.forEnumeration(new ZipFile(zip).entries());
assertThat(zipEntries).hasSize(4);
File unzipDir = temp.newFolder();
ZipUtils.unzip(zip, unzipDir);
assertThat(new File(unzipDir, "bar.txt")).exists().isFile();
assertThat(new File(unzipDir, "foo.txt")).exists().isFile();
assertThat(new File(unzipDir, "dir1/hello.properties")).exists().isFile();
}
use of java.util.zip.ZipFile 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.ZipFile 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