Search in sources :

Example 1 with ZipFile

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);
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 2 with ZipFile

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();
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ArrayList(java.util.ArrayList) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) IOException(java.io.IOException) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 3 with ZipFile

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);
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile)

Example 4 with ZipFile

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);
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ZipException(net.lingala.zip4j.exception.ZipException) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 5 with ZipFile

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();
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ArrayList(java.util.ArrayList) ZipException(net.lingala.zip4j.exception.ZipException) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Aggregations

ZipFile (net.lingala.zip4j.core.ZipFile)44 File (java.io.File)22 ZipException (net.lingala.zip4j.exception.ZipException)19 ZipParameters (net.lingala.zip4j.model.ZipParameters)16 IOException (java.io.IOException)10 FileHeader (net.lingala.zip4j.model.FileHeader)8 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Nonnull (javax.annotation.Nonnull)4 WorldException (com.voxelgameslib.voxelgameslib.exception.WorldException)3 ByteArrayOutputStream (com.codeforces.commons.io.ByteArrayOutputStream)2 Map (com.voxelgameslib.voxelgameslib.map.Map)2 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileMeta (org.molgenis.data.file.model.FileMeta)2 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Subcommand (co.aikar.commands.annotation.Subcommand)1