use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.
the class ZipUtils method unzip.
public static List<String> unzip(final File zipFile, final String destination, String encoding, Map<String, ZipEntry> zipEntryMethodMap, boolean isRelativePath) {
List<String> fileNames = new ArrayList<String>();
String dest = destination;
if (!destination.endsWith(File.separator)) {
dest = destination + File.separator;
}
ZipFile file;
try {
file = null;
if (null == encoding)
file = new ZipFile(zipFile);
else
file = new ZipFile(zipFile, encoding);
Enumeration<ZipArchiveEntry> en = file.getEntries();
ZipArchiveEntry ze = null;
while (en.hasMoreElements()) {
ze = en.nextElement();
File f = new File(dest, ze.getName());
if (ze.isDirectory()) {
f.mkdirs();
continue;
} else {
f.getParentFile().mkdirs();
InputStream is = file.getInputStream(ze);
OutputStream os = new FileOutputStream(f);
IOUtils.copy(is, os);
is.close();
os.close();
fileNames.add(f.getAbsolutePath());
if (zipEntryMethodMap != null && ze.getMethod() == STORED) {
zipEntryMethodMap.put(isRelativePath ? ze.getName() : f.getAbsolutePath(), ze);
}
}
}
file.close();
} catch (IOException e) {
e.printStackTrace();
}
return fileNames;
}
use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.
the class ZipUtils method listZipEntries.
public static List<String> listZipEntries(File zipFile) {
List<String> list = new ArrayList<String>();
ZipFile zip;
try {
zip = new ZipFile(zipFile);
Enumeration<ZipArchiveEntry> en = zip.getEntries();
ZipArchiveEntry ze = null;
while (en.hasMoreElements()) {
ze = en.nextElement();
String name = ze.getName();
name = StringUtils.replace(name, "/", ".");
if (name.endsWith(".class")) {
list.add(name);
}
}
if (null != zip)
ZipFile.closeQuietly(zip);
} catch (IOException e) {
}
return list;
}
use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.
the class PatchUtils method isBundleFile.
/**
* 判断当前so文件是否为bundle
*
* @param soFile
* @return
*/
public static boolean isBundleFile(File soFile) {
ZipFile zf = null;
try {
zf = new ZipFile(soFile);
Enumeration<ZipArchiveEntry> en = zf.getEntries();
if (en.hasMoreElements()) {
for (String name : BUNDLE_FILES) {
ZipArchiveEntry zipArchiveEntry = zf.getEntry(name);
if (null == zipArchiveEntry) {
return false;
}
}
return true;
}
return false;
} catch (IOException e) {
return false;
} finally {
if (null != zf) {
try {
zf.close();
} catch (IOException e) {
}
}
}
}
use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.
the class ZipUtils method unzip.
/**
* <p>
* unzip.
* </p>
*
* @param zipFile a {@link File} object.
* @param destination a {@link String} object.
* @param encoding a {@link String} object.
* @return a {@link List} object.
*/
public static List<String> unzip(final File zipFile, final String destination, String encoding) {
List<String> fileNames = new ArrayList<String>();
String dest = destination;
if (!destination.endsWith(File.separator)) {
dest = destination + File.separator;
}
ZipFile file;
try {
file = null;
if (null == encoding)
file = new ZipFile(zipFile);
else
file = new ZipFile(zipFile, encoding);
Enumeration<ZipArchiveEntry> en = file.getEntries();
ZipArchiveEntry ze = null;
while (en.hasMoreElements()) {
ze = en.nextElement();
File f = new File(dest, ze.getName());
if (ze.isDirectory()) {
f.mkdirs();
continue;
} else {
f.getParentFile().mkdirs();
InputStream is = file.getInputStream(ze);
OutputStream os = new FileOutputStream(f);
IOUtils.copy(is, os);
is.close();
os.close();
fileNames.add(f.getAbsolutePath());
}
}
file.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return fileNames;
}
use of org.apache.commons.compress.archivers.zip.ZipArchiveEntry in project atlas by alibaba.
the class ZipUtils method isFolderExist.
/**
* 判断在指定的zip目录下,指定的文件夹是否存在
*
* @param zipFile
* @param pathName
* @return
*/
public static boolean isFolderExist(File zipFile, String pathName) {
ZipFile file = null;
try {
file = new ZipFile(zipFile);
Enumeration<ZipArchiveEntry> en = file.getEntries();
while (en.hasMoreElements()) {
ZipArchiveEntry entry = en.nextElement();
String name = entry.getName();
if (name.startsWith(pathName)) {
return true;
}
}
return false;
} catch (IOException e) {
} finally {
if (null != file) {
try {
file.close();
} catch (IOException e) {
}
}
}
return false;
}
Aggregations