當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipFile.addFolder方法代碼示例

本文整理匯總了Java中net.lingala.zip4j.core.ZipFile.addFolder方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.addFolder方法的具體用法?Java ZipFile.addFolder怎麽用?Java ZipFile.addFolder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.lingala.zip4j.core.ZipFile的用法示例。


在下文中一共展示了ZipFile.addFolder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compress

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public void compress(Transformation transformation) {
    File inputFile = transformation.getTransformedApplicationLocation().getAbsoluteFile();
    File compressedFile = new File(transformation.getTransformedApplicationLocation().getAbsolutePath() + ".zip");

    logger.info("Compressing transformed application");

    try {
        ZipFile zipFile = new ZipFile(compressedFile);
        ZipParameters parameters = new ZipParameters();

        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

        zipFile.addFolder(inputFile, parameters);
        FileUtils.deleteDirectory(transformation.getTransformedApplicationLocation());

        logger.info("Transformed application has been compressed to {}", compressedFile.getAbsoluteFile());
    } catch (Exception e) {
        logger.error("Error when compressing transformed application", e);
    }
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:22,代碼來源:CompressionHandler.java

示例2: zip

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static void zip(String targetPath, String destinationFilePath, String password) {
    try {
        ZipParameters parameters = new ZipParameters();
        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

        if (password.length() > 0) {
            parameters.setEncryptFiles(true);
            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
            parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
            parameters.setPassword(password);
        }

        ZipFile zipFile = new ZipFile(destinationFilePath);

        File targetFile = new File(targetPath);
        if (targetFile.isFile()) {
            zipFile.addFile(targetFile, parameters);
        } else if (targetFile.isDirectory()) {
            zipFile.addFolder(targetFile, parameters);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:ghost1372,項目名稱:Mzip-Android,代碼行數:27,代碼來源:ZipArchive.java

示例3: generateZipFile

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private void generateZipFile() {
	try {
		File outputFile = new File(this.workFolder.getName() + ".zip");
		if (outputFile.exists()) {
			Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting.");
			outputFile.delete();
		}
		ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile);
		Logger.info("Generating " + output.getFile().getAbsolutePath());

		ZipParameters params = new ZipParameters();
		params.setIncludeRootFolder(false);
		params.setRootFolderInZip("");
		output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params);
		params.setRootFolderInZip("classes");
		output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params);
	} catch (Throwable t) {
		Logger.error("Unable to generate final zip file.", t);
	}
}
 
開發者ID:dwatling,項目名稱:apk-decompiler,代碼行數:21,代碼來源:GenerateFinalZip.java

示例4: AddFolder

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public AddFolder() {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFolder.zip");
		
		// Folder to add
		String folderToAdd = "c:\\FolderToAdd";
		
		// 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);
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:27,代碼來源:AddFolder.java

示例5: compile

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static void compile(String pkgroot){
	
	try {
		File parent = new File(pkgroot).getParentFile();
		String name = new File(pkgroot).getName() + ".atomx";
		ZipFile zipFile = new ZipFile(new File(parent, name));
		ZipParameters parameters = new ZipParameters();
		parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
		parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
		parameters.setIncludeRootFolder(false);
		zipFile.addFolder(pkgroot, parameters);
		
	} catch (ZipException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
 
開發者ID:arjay07,項目名稱:AtomScript,代碼行數:19,代碼來源:ASPackage.java

示例6: performNeo4jBackup

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private void performNeo4jBackup() {
    InputStream zipInput = null;
    try {
        String backupDirPath = System.getProperty("java.io.tmpdir") + "/neo4jbackup";
        File backupDir = new File(backupDirPath);
        //FileUtils.deleteRecursively(backupDir);
        FileUtils.deleteDirectory(backupDir);
        backupDir.mkdirs();
        FileUtils.copyDirectory(new File(graphDb.getStoreDir()), backupDir);
        String fileName = "graph-backup-" + DATE_TIME_FORMAT.print(new DateTime()) + ".zip";
        File backupFile = new File(System.getProperty("java.io.tmpdir") + fileName);
        ZipFile zip = new ZipFile(backupFile);
        ZipParameters params = new ZipParameters();
        zip.addFolder(backupDir, params);
        zipInput = new FileInputStream(backupFile);
        byte[] bytes = IOUtils.toByteArray(zipInput);
        fileStorageService.storeFile(finalBackupDir + fileName, bytes);
        FileUtils.deleteQuietly(backupFile);
    } catch (Exception e) {
        log.error("Error in graph db bckup", e);
    } finally {
        IOUtils.closeQuietly(zipInput);
    }

}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:26,代碼來源:BackupJob.java

示例7: example3

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * 示例3 添加文件夾到壓縮包中
 */
@Test
public void example3(){
	try {
           
           ZipFile zipFile = new ZipFile("src/main/resources/AddFolder.zip");
           String folderToAdd = "src/main/resources";
        
           ZipParameters parameters = new ZipParameters();
            
           parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
           parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
           zipFile.addFolder(folderToAdd, parameters);
            
       } catch (ZipException e) {
           e.printStackTrace();
       }
}
 
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:21,代碼來源:Zip4j.java

示例8: zip

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * 使用給定密碼壓縮指定文件或文件夾到指定位置.
 * <p>
 * dest可傳最終壓縮文件存放的絕對路徑,也可以傳存放目錄,也可以傳null或者"".<br />
 * 如果傳null或者""則將壓縮文件存放在當前目錄,即跟源文件同目錄,壓縮文件名取源文件名,以.zip為後綴;<br />
 * 如果以路徑分隔符(File.separator)結尾,則視為目錄,壓縮文件名取源文件名,以.zip為後綴,否則視為文件名.
 * @param src 要壓縮的文件或文件夾路徑
 * @param dest 壓縮文件存放路徑
 * @param isCreateDir 是否在壓縮文件裏創建目錄,僅在壓縮文件為目錄時有效.<br />
 * 如果為false,將直接壓縮目錄下文件到壓縮文件.
 * @param passwd 壓縮使用的密碼
 * @return 最終的壓縮文件存放的絕對路徑,如果為null則說明壓縮失敗.
 */
public static String zip(String src, String dest, boolean isCreateDir, String passwd) {
    File srcFile = new File(src);
    File destFile = new File(dest);
    dest = buildDestinationZipFilePath(srcFile, dest);
    ZipParameters parameters = new ZipParameters();
    parameters.setFileNameInZip(destFile.getName().substring(0,destFile.getName().lastIndexOf("."))+".log");
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);           // 壓縮方式
    parameters.setSourceExternalStream(true);
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);    // 壓縮級別
    if (!TextUtils.isEmpty(passwd)) {
        parameters.setEncryptFiles(true);
        parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD); // 加密方式
        parameters.setPassword(passwd.toCharArray());
    }
    try {
        ZipFile zipFile = new ZipFile(dest);
        if (srcFile.isDirectory()) {
            // 如果不創建目錄的話,將直接把給定目錄下的文件壓縮到壓縮文件,即沒有目錄結構
            if (!isCreateDir) {
                File [] subFiles = srcFile.listFiles();
                ArrayList<File> temp = new ArrayList<File>();
                Collections.addAll(temp, subFiles);
                zipFile.addFiles(temp, parameters);
                return dest;
            }
            zipFile.addFolder(srcFile, parameters);
        } else {
            zipFile.addFile(srcFile, parameters);
        }
        return dest;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:49,代碼來源:ZipUtil.java

示例9: repackCert

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * Jar sign creates CERT SF & RSA but some apk have different name like
 * ABC.SF This module will rename the CERT.SF & CERT.RSA to the new
 * certificate name
 * 
 * @param newAPKPath
 *            Path of the modified apk
 */
public static void repackCert(String newAPKPath) {

	try {
		ZipFile zipFile = new ZipFile(newAPKPath);
		zipFile.extractFile("META-INF" + File.separator + "CERT.RSA",
				getProjectPath());
		zipFile.extractFile("META-INF" + File.separator + "CERT.SF",
				getProjectPath());
		zipFile.removeFile("META-INF" + File.separator + "CERT.SF");
		zipFile.removeFile("META-INF" + File.separator + "CERT.RSA");
		File rsaFile = new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + "CERT.RSA");
		File sfFile = new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + "CERT.SF");
		File newCertFolder = new File(getProjectPath() + File.separator
				+ "META-INF");
		rsaFile.renameTo(new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + certificateName + ".RSA"));
		sfFile.renameTo(new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + certificateName + ".SF"));
		ZipParameters parameters = new ZipParameters();
		parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
		parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
		zipFile.addFolder(newCertFolder, parameters);

	} catch (ZipException e) {
		e.printStackTrace();
	}
}
 
開發者ID:csanuragjain,項目名稱:APKRepatcher,代碼行數:38,代碼來源:Utility.java

示例10: zip

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/** 
 * 使用給定密碼壓縮指定文件或文件夾到指定位置. 
 * <p> 
 * dest可傳最終壓縮文件存放的絕對路徑,也可以傳存放目錄,也可以傳null或者"".<br /> 
 * 如果傳null或者""則將壓縮文件存放在當前目錄,即跟源文件同目錄,壓縮文件名取源文件名,以.zip為後綴;<br /> 
 * 如果以路徑分隔符(File.separator)結尾,則視為目錄,壓縮文件名取源文件名,以.zip為後綴,否則視為文件名. 
 * @param src 要壓縮的文件或文件夾路徑 
 * @param dest 壓縮文件存放路徑 
 * @param isCreateDir 是否在壓縮文件裏創建目錄,僅在壓縮文件為目錄時有效.<br /> 
 * 如果為false,將直接壓縮目錄下文件到壓縮文件. 
 * @param passwd 壓縮使用的密碼 
 * @return 最終的壓縮文件存放的絕對路徑,如果為null則說明壓縮失敗. 
 */  
public static String zip(String src, String dest, boolean isCreateDir, String passwd) {  
    File srcFile = new File(src);  
    dest = buildDestinationZipFilePath(srcFile, dest);  
    ZipParameters parameters = new ZipParameters();  
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);           // 壓縮方式  
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);    // 壓縮級別  
    if (!StringUtils.isEmpty(passwd)) {  
        parameters.setEncryptFiles(true);  
        parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD); // 加密方式  
        parameters.setPassword(passwd.toCharArray());  
    }  
    try {  
        ZipFile zipFile = new ZipFile(dest);  
        if (srcFile.isDirectory()) {  
            // 如果不創建目錄的話,將直接把給定目錄下的文件壓縮到壓縮文件,即沒有目錄結構  
            if (!isCreateDir) {  
                File [] subFiles = srcFile.listFiles();  
                ArrayList<File> temp = new ArrayList<File>();  
                Collections.addAll(temp, subFiles);  
                zipFile.addFiles(temp, parameters);  
                return dest;  
            }  
            zipFile.addFolder(srcFile, parameters);  
        } else {  
            zipFile.addFile(srcFile, parameters);  
        }  
        return dest;  
    } catch (ZipException e) {  
        e.printStackTrace();  
    }  
    return null;  
}
 
開發者ID:Kuangcp,項目名稱:JavaToolKit,代碼行數:46,代碼來源:CompressUtil.java

示例11: createZip

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
 * Creates a zip from all files and folders in the specified folder. DOES NOT INCLUDE THE FOLDER ITSELF!
 *
 * @param file the folder which content should be zipped
 * @return the created zip
 * @throws ZipException if something goes wrong
 */
@Nonnull
public static ZipFile createZip(@Nonnull File file, @Nonnull String name) throws ZipException {
    ZipFile zip = new ZipFile(new File(file.getParent(), name + ".zip"));

    ZipParameters params = new ZipParameters();
    params.setIncludeRootFolder(false);
    zip.addFolder(file, params);

    return zip;
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLibv2,代碼行數:18,代碼來源:ZipUtil.java

示例12: zipFolder

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
static public void zipFolder(String src, String dst) throws Exception {
    File f = new File(dst);
    //make dirs if necessary
    f.getParentFile().mkdirs();

    ZipFile zipfile = new ZipFile(f.getAbsolutePath());
    ZipParameters parameters = new ZipParameters();
    parameters.setIncludeRootFolder(false);
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
    zipfile.addFolder(src, parameters);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:13,代碼來源:FileIO.java

示例13: zip

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/** 
 * 使用給定密碼壓縮指定文件或文件夾到指定位置. 
 * <p> 
 * dest可傳最終壓縮文件存放的絕對路徑,也可以傳存放目錄,也可以傳null或者"".<br /> 
 * 如果傳null或者""則將壓縮文件存放在當前目錄,即跟源文件同目錄,壓縮文件名取源文件名,以.zip為後綴;<br /> 
 * 如果以路徑分隔符(File.separator)結尾,則視為目錄,壓縮文件名取源文件名,以.zip為後綴,否則視為文件名. 
 * @param src 要壓縮的文件或文件夾路徑 
 * @param dest 壓縮文件存放路徑 
 * @param isCreateDir 是否在壓縮文件裏創建目錄,僅在壓縮文件為目錄時有效.<br /> 
 * 如果為false,將直接壓縮目錄下文件到壓縮文件. 
 * @param passwd 壓縮使用的密碼 
 * @return 最終的壓縮文件存放的絕對路徑,如果為null則說明壓縮失敗. 
 */  
public static String zip(String src, String dest, boolean isCreateDir, String passwd) {  
    File srcFile = new File(src);  
    dest = buildDestinationZipFilePath(srcFile, dest);  
    ZipParameters parameters = new ZipParameters();  
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);           // 壓縮方式  
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);    // 壓縮級別  
    if (!StringUtils.isEmpty(passwd)) {
        parameters.setEncryptFiles(true);  
        parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD); // 加密方式  
        parameters.setPassword(passwd.toCharArray());  
    }  
    try {  
        ZipFile zipFile = new ZipFile(dest);
        zipFile.setFileNameCharset(Constants.GBK); //不可隨意更換位置
        if (srcFile.isDirectory()) {  
            // 如果不創建目錄的話,將直接把給定目錄下的文件壓縮到壓縮文件,即沒有目錄結構  
            if (!isCreateDir) {  
                File [] subFiles = srcFile.listFiles();  
                ArrayList<File> temp = new ArrayList<File>();
                if(null != subFiles && subFiles.length > 0)
                    Collections.addAll(temp, subFiles);
                zipFile.addFiles(temp, parameters);  
                return dest;  
            }  
            zipFile.addFolder(srcFile, parameters);  
        } else {  
            zipFile.addFile(srcFile, parameters);  
        }  
        return dest;  
    } catch (ZipException e) {  
        Exceptions.printException(e);;  
    }  
    return null;  
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:48,代碼來源:CompressUtil.java

示例14: compress

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public void compress(){
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//設置日期格式
    String suffix =  df.format(new Date());
    try {
        destinationZipFile = new ZipFile(destination + suffix + ".zip");
        destinationZipFile.addFolder(source, parameters);
    } catch (ZipException e) {
        e.printStackTrace();
    }

}
 
開發者ID:tztztztztz,項目名稱:bookish-meme,代碼行數:12,代碼來源:CompressTask.java

示例15: zipFiles

import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
@Override
public String zipFiles(String zipFilePath, List<File> files, String filesRootPath, boolean includeRootPath) {

    String errorMessage = null;
    ZipParameters parameters = new ZipParameters();
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FAST);
    parameters.setEncryptionMethod(Zip4jConstants.ENC_NO_ENCRYPTION);
    parameters.setDefaultFolderPath(filesRootPath);
    parameters.setIncludeRootFolder(includeRootPath);

    try {
        ZipFile zipFile = new ZipFile(zipFilePath);

        for (int i = 0; i < files.size(); i++) {
            File file = files.get(i);
            if (file.isFile()) {
                zipFile.addFile(file, parameters);
            }
            if (file.isDirectory()) {
                zipFile.addFolder(file, parameters);
            }
        }
    } catch (ZipException e) {
        errorMessage = e.getMessage();
    }

    return errorMessage;
}
 
開發者ID:rndsolutions,項目名稱:hawkcd,代碼行數:30,代碼來源:FileManagementService.java


注:本文中的net.lingala.zip4j.core.ZipFile.addFolder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。