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


Java ZipFile類代碼示例

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


ZipFile類屬於net.lingala.zip4j.core包,在下文中一共展示了ZipFile類的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: ExtractSingleFile

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
public ExtractSingleFile() {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractSingleFile.zip");
		
		// Check to see if the zip file is password protected 
		if (zipFile.isEncrypted()) {
			// if yes, then set the password for the zip file
			zipFile.setPassword("test123!");
		}
		
		// Specify the file name which has to be extracted and the path to which
		// this file has to be extracted
		zipFile.extractFile("Ronan_Keating_-_In_This_Life.mp3", "c:\\ZipTest\\");
		
		// Note that the file name is the relative file name in the zip file.
		// For example if the zip file contains a file "mysong.mp3" in a folder 
		// "FolderToAdd", then extraction of this file can be done as below:
		zipFile.extractFile("FolderToAdd\\myvideo.avi", "c:\\ZipTest\\");
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:27,代碼來源:ExtractSingleFile.java

示例3: loadJar

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
public void loadJar(File jar) throws IOException {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipFile jarFile = new ZipFile(jar);
        //noinspection unchecked
        for (FileHeader header : (List<FileHeader>) jarFile.getFileHeaders()) {
            if (!header.isDirectory()) {
                final ZipParameters parameters = new ZipParameters();
                parameters.setFileNameInZip(header.getFileName());
                parameters.setSourceExternalStream(true);
                zipFile.addStream(jarFile.getInputStream(header), parameters);
            }
        }
        dexJar();
    } catch (ZipException e) {
        IOException exception = new IOException();
        //noinspection UnnecessaryInitCause
        exception.initCause(e);
        throw exception;
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:22,代碼來源:AndroidClassLoader.java

示例4: 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

示例5: defineClass

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipParameters parameters = new ZipParameters();
        parameters.setFileNameInZip(name.replace('.', '/') + ".class");
        parameters.setSourceExternalStream(true);
        zipFile.addStream(new ByteArrayInputStream(data), parameters);
        return dexJar().loadClass(name, parent);
    } catch (IOException | ZipException e) {
        throw new FatalLoadingException(e);
    } finally {
        dexFile.delete();
        odexOatFile.delete();
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:20,代碼來源:AndroidClassLoader.java

示例6: recreatePristineSiad

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
private static File recreatePristineSiad() throws IOException {
    doTimed(() -> {
        File zipFile = new File("../../sia-preloaded.zip");
        ZipFile preloaded = new ZipFile(zipFile);
        final File extractTo = new File("junit/sia").getCanonicalFile();
        FileUtils.deleteDirectory(extractTo);

        preloaded.extractAll(extractTo.getCanonicalPath());
        return null;
    });
    final String siadDir = JUNIT_SIA + "Sia-v1.3.0-linux-amd64/";
    final File siadDirectoryFile = new File(siadDir).getCanonicalFile();
    final boolean result = new File(siadDirectoryFile, "siad").setExecutable(true);
    Assert.assertTrue("unable to set siad executable", result);
    return siadDirectoryFile;
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:17,代碼來源:SiaHostedDownloadTest.java

示例7: unzipfile

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
public  void unzipfile(File zipfile, String dest, String passwd) throws ZipException {
	ZipFile zfile = new ZipFile(zipfile);
	// zfile.setFileNameCharset("GBK");//在GBK係統中需要設置
	if (!zfile.isValidZipFile()) {
		throw new ZipException("壓縮文件不合法,可能已經損壞!");
	}
	File file = new File(dest);
	if (file.isDirectory() && !file.exists()) {
		file.mkdirs();
	}
	if (zfile.isEncrypted()) {
		zfile.setPassword(passwd.toCharArray());
	}
	zfile.extractAll(dest);

}
 
開發者ID:jiashiwen,項目名稱:elasticbak,代碼行數:17,代碼來源:ZipUtilities.java

示例8: loadWorld

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
/**
 * Loads a world. Needs to copy the file from the repo, unzip it and let the implementation load it <br><b>Always
 * needs to call super! Super needs to be called first (because it copies the world)</b>
 *
 * @param map    the map that should be loaded
 * @param gameid the id of the game this map belongs to
 * @return the loaded world
 * @throws WorldException something goes wrong
 */
@Nonnull
public World loadWorld(@Nonnull Map map, @Nonnull UUID gameid, boolean replaceMarkers) {
    map.load(gameid, "TEMP_" + map.getWorldName() + "_" + gameid.toString().split("-")[0]);
    log.finer("Loading map " + map.getInfo().getName() + " as " + map.getLoadedName(gameid));

    File file = new File(worldContainer, map.getLoadedName(gameid));

    try {
        ZipFile zip = new ZipFile(new File(worldsFolder, map.getWorldName() + ".zip"));
        zip.extractAll(file.getAbsolutePath());
        FileUtils.delete(new File(file, "uid.dat"));
    } catch (ZipException e) {
        throw new WorldException("Could not unzip world " + map.getInfo().getName() + ".", e);
    }

    World world = loadLocalWorld(map.getLoadedName(gameid));

    if (replaceMarkers) {
        replaceMarkers(world, map);
    }

    return world;
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLibv2,代碼行數:33,代碼來源:WorldHandler.java

示例9: 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) throws ZipException {
    ZipFile zip = new ZipFile(new File(file.getParent(), file.getName() + ".zip"));
    ArrayList<File> fileList = new ArrayList<>();

    File[] files = file.listFiles();
    if (files == null) {
        return zip;
    }

    Arrays.stream(files).forEach(fileList::add);

    zip.createZipFile(fileList, new ZipParameters());

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

示例10: compress

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
/**
 * Compress.
 *
 * @param fileName
 *            the file name
 * @param compressedFileName
 *            the compressed file name
 * @param password
 *            the password
 */
public static void compress(String fileName, String compressedFileName, String password) {
	try {
		ZipParameters zipParameters = new ZipParameters();
		zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
		zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
		if (password != null) {
			zipParameters.setEncryptFiles(true);
			zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
			zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
			zipParameters.setPassword(password);
		}
		String destinationZipFilePath = compressedFileName;
		ZipFile zipFile = new ZipFile(destinationZipFilePath);
		zipFile.addFile(new File(fileName), zipParameters);
	} catch (ZipException e) {
		JKExceptionUtil.handle(e);
	}
}
 
開發者ID:kiswanij,項目名稱:jk-util,代碼行數:29,代碼來源:JKCompressionUtil.java

示例11: unzip

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
/**
 * 解壓文件到指定目錄
 *
 * @param zipFile      壓縮文件
 * @param outDir       輸出路徑
 * @param isClean      是否清理目錄
 * @return
 */
public static boolean unzip(File zipFile, File outDir, boolean isClean){
    try {
        if(!FileHelper.exists(zipFile)){
            return false;
        }
        ZipFile zip = new ZipFile(zipFile);
        if(isClean && outDir.exists()){
            FileHelper.delete(outDir);
        }
        zip.setRunInThread(false);
        zip.extractAll(outDir.getPath());
        return true;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:linchaolong,項目名稱:ApkToolPlus,代碼行數:26,代碼來源:ZipUtils.java

示例12: list

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
/**
 * 解壓文件,注意該法方法並不是異步的
 *
 * @param zipFile      壓縮文件
 * @param filter
 * @return
 */
public static void list(File zipFile, FileFilter filter){
    try {
        if(!FileHelper.exists(zipFile)){
            return;
        }
        ZipFile zip = new ZipFile(zipFile);
        zip.setRunInThread(false);

        // Get the list of file headers from the zip file
        List fileHeaderList = zip.getFileHeaders();

        // Loop through the file headers
        for (int i = 0; i < fileHeaderList.size(); i++) {
            // Extract the file to the specified destination
            filter.handle(zip, (FileHeader) fileHeaderList.get(i));
        }
    } catch (ZipException e) {
        e.printStackTrace();
    }
}
 
開發者ID:linchaolong,項目名稱:ApkToolPlus,代碼行數:28,代碼來源:ZipUtils.java

示例13: unzipDexList

import net.lingala.zip4j.core.ZipFile; //導入依賴的package包/類
protected List<File> unzipDexList(File apk, File tempDir){
    List<FileHeader> dexFileHeaders = MultDexSupport.getDexFileHeaders(apk);
    if(dexFileHeaders.isEmpty()){
        return new ArrayList<>(0);
    }
    // 解壓dex文件
    tempDir.mkdirs();
    List<File> dexFileList = new ArrayList<>(dexFileHeaders.size());
    try {
        for(FileHeader dexFileHeader : dexFileHeaders){
            ZipFile zipFile = new ZipFile(apk);
            boolean unzip = ZipUtils.unzip(zipFile, dexFileHeader, tempDir);
            if(unzip){
                dexFileList.add(new File(tempDir,dexFileHeader.getFileName()));
            }
        }
        return dexFileList;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return new ArrayList<>(0);
}
 
開發者ID:linchaolong,項目名稱:ApkToolPlus,代碼行數:23,代碼來源:MultDexSupport.java

示例14: 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

示例15: 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


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