use of net.lingala.zip4j.core.ZipFile in project tdi-studio-se by Talend.
the class Zip method doZip2.
// zip4j impl
private void doZip2(final File source, final List<File> list) throws Exception {
ZipFile zipFile = new ZipFile(targetZip);
if ("UTF-8".equalsIgnoreCase(encoding)) {
encoding = "UTF8";
}
zipFile.setFileNameCharset(encoding);
ZipParameters params = new ZipParameters();
params.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
params.setCompressionLevel(compressLevel);
if (isEncrypted && !"".equals(password)) {
params.setEncryptFiles(true);
params.setEncryptionMethod(encryptionMethod);
if (Zip4jConstants.ENC_METHOD_AES == encryptionMethod) {
params.setAesKeyStrength(aesKeyStrength);
}
params.setPassword(password);
}
params.setDefaultFolderPath(source.getAbsoluteFile().getPath());
zipFile.addFiles((ArrayList) list, params);
}
use of net.lingala.zip4j.core.ZipFile in project ARChon-Packager by bpear96.
the class Step3 method archiveDir.
private void archiveDir(String path) {
try {
// Initiate ZipFile object with the path/name of the zip file.
String zipname = g.getSelectedAppName();
ZipFile zipFile = new ZipFile(Environment.getExternalStorageDirectory() + "/ChromeAPKS/" + zipname + ".zip");
// Folder to add
String folderToAdd = path;
// Initiate Zip Parameters which define various properties such
// as compression method, etc.
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Add folder to the zip file
zipFile.addFolder(folderToAdd, parameters);
ArrayList filesToAdd = new ArrayList();
filesToAdd.add(new File(path + "app_main.html"));
filesToAdd.add(new File(path + "icon.png"));
zipFile.addFiles(filesToAdd, parameters);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.lingala.zip4j.core.ZipFile in project leopard by tanhaichao.
the class ZipUtil method unzip.
/**
* 解压zip格式压缩包
*/
public static void unzip(String sourceZip, String destDir) throws Exception {
ZipFile zipFile = new ZipFile(sourceZip);
zipFile.extractAll(destDir);
}
use of net.lingala.zip4j.core.ZipFile in project pmph by BCSquad.
the class ZipHelper method unZip.
/**
* 解压加密的压缩文件
*
* @param file
* 要解压的文件(目录)
* @param dest
* 解压路径
* @param passwd
* 压缩密码
* @throws ZipException
* 压缩异常
*/
public void unZip(File file, String dest, String passwd) throws ZipException {
ZipFile zipFile = new ZipFile(file);
// zfile.setFileNameCharset("GBK");//在GBK系统中需要设置
if (!zipFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能已经损坏!");
}
File tmp = new File(dest);
if (tmp.isDirectory() && !tmp.exists()) {
tmp.mkdirs();
}
if (zipFile.isEncrypted()) {
zipFile.setPassword(passwd.toCharArray());
}
zipFile.extractAll(dest);
}
use of net.lingala.zip4j.core.ZipFile in project pmph by BCSquad.
the class ZipHelper method zip.
/**
* 压缩文件并加密(压缩密码为空时不加密)
*
* @param src
* 要压缩的源文件(目录)地址
* @param dest
* 目标路径
* @param isCreateDir
* 如果路径不存在是否创建
* @param passwd
* 压缩密码
*/
public void zip(String src, String dest, boolean isCreateDir, String passwd) {
File srcfile = new File(src);
// 创建目标文件
String destname = buildDestFileName(srcfile, dest);
ZipParameters para = new ZipParameters();
para.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
para.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (passwd != null) {
para.setEncryptFiles(true);
para.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
para.setPassword(passwd.toCharArray());
}
try {
ZipFile zipfile = new ZipFile(destname);
if (srcfile.isDirectory()) {
if (!isCreateDir) {
File[] listFiles = srcfile.listFiles();
ArrayList<File> temp = new ArrayList<>();
Collections.addAll(temp, listFiles);
zipfile.addFiles(temp, para);
}
zipfile.addFolder(srcfile, para);
} else {
zipfile.addFile(srcfile, para);
}
} catch (ZipException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
Aggregations