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


Java ZipException類代碼示例

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


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

示例1: ExtractSingleFile

import net.lingala.zip4j.exception.ZipException; //導入依賴的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

示例2: loadJar

import net.lingala.zip4j.exception.ZipException; //導入依賴的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

示例3: defineClass

import net.lingala.zip4j.exception.ZipException; //導入依賴的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

示例4: tryCreateParser

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
private void tryCreateParser(File selectedFile) {
    currentParser = new APKGParser(selectedFile);
    try {
        currentParser.tryOpenFile();

        onValidParserSelected();
    } catch (ZipException | SQLException | IOException | AnkiDatabaseNotFoundException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
                this,
                "An error occurred when trying to open Anki archive\n" +
                        "Please check that the selected archive is valid. If necessary re-export it again and retry.\n" +
                        "Technical error: " + e.getMessage(),
                "An error occurred when trying to open Anki archive",
                JOptionPane.ERROR_MESSAGE
        );

        currentParser.clear();
        currentParser = null;
    }
}
 
開發者ID:slavetto,項目名稱:anki-cards-web-browser,代碼行數:22,代碼來源:MainFrame.java

示例5: unzipfile

import net.lingala.zip4j.exception.ZipException; //導入依賴的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

示例6: doInBackground

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
@Override
protected Integer doInBackground(RestoreRequest... restoreRequests) {
    RestoreRequest request = restoreRequests[0];
    try {
        BackupManager.restoreBackup(mContext, request.file, request.password);
        if (request.deleteFile)
            request.file.delete();
        return RESULT_OK;
    } catch (IOException e) {
        e.printStackTrace();
        if (e.getCause() != null && e.getCause() instanceof ZipException &&
                ((ZipException) e.getCause()).getCode() == ZipExceptionConstants.WRONG_PASSWORD)
            return RESULT_INVALID_PASSWORD;
        if (request.deleteFile)
            request.file.delete();
        return RESULT_ERROR;
    }
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:19,代碼來源:BackupProgressActivity.java

示例7: startSearchPassword

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
/**運行*/
	public static void startSearchPassword(List<String>Lib){
		boolean flag = true;
		int size = Lib.size();
		int index = 0;
		while(flag){
			flag = false;

			try {
				String temp = Lib.get(index);
				index++;
				if(index%51==0) System.out.println("已經嘗試"+index);
//				System.out.println(temp);
				CompressUtil.unzip("F:\\Tool\\ui.zip", "F:\\Tool\\ui", temp);
			} catch (ZipException e) {
				flag = true;
				//			e.printStackTrace();
			}
			if(index>=size)flag = false;
		}
		System.out.println("運行完畢");
	}
 
開發者ID:Kuangcp,項目名稱:JavaToolKit,代碼行數:23,代碼來源:PoZip.java

示例8: loadWorld

import net.lingala.zip4j.exception.ZipException; //導入依賴的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: unzip

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
@ProtoMethod(description = "Unzip a file into a folder", example = "")
@ProtoMethodParam(params = {"zipFile", "folder"})
public void unzip(final String src, final String dst, final ReturnInterface callback) {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                FileIO.unZipFile(getAppRunner().getProject().getFullPathForFile(src), getAppRunner().getProject().getFullPathForFile(dst));
                returnValues(null, callback);
            } catch (ZipException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:17,代碼來源:PFileIO.java

示例10: removeFile

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
/**
 * Removes the file provided in the input paramters from the zip file.
 * This method first finds the file header and then removes the file.
 * If file does not exist, then this method throws an exception.
 * If zip file is a split zip file, then this method throws an exception as
 * zip specification does not allow for updating split zip archives.
 * @param fileName
 * @throws ZipException
 */
public void removeFile(String fileName) throws ZipException {
	
	if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileName)) {
		throw new ZipException("file name is empty or null, cannot remove file");
	}
	
	if (zipModel == null) {
		if (Zip4jUtil.checkFileExists(file)) {
			readZipInfo();
		}
	}
	
	if (zipModel.isSplitArchive()) {
		throw new ZipException("Zip file format does not allow updating split/spanned files");
	}
	
	FileHeader fileHeader = Zip4jUtil.getFileHeader(zipModel, fileName);
	if (fileHeader == null) {
		throw new ZipException("could not find file header for file: " + fileName);
	}
	
	removeFile(fileHeader);
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:33,代碼來源:ZipFile.java

示例11: unzip

import net.lingala.zip4j.exception.ZipException; //導入依賴的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: isEncrypted

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
/**
 * Checks to see if the zip file is encrypted
 * @return true if encrypted, false if not
 * @throws ZipException
 */
public boolean isEncrypted() throws ZipException {
	if (zipModel == null) {
		readZipInfo();
		if (zipModel == null) {
			throw new ZipException("Zip Model is null");
		}
	}
	
	if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
		throw new ZipException("invalid zip file");
	}
	
	ArrayList fileHeaderList = zipModel.getCentralDirectory().getFileHeaders();
	for (int i = 0; i < fileHeaderList.size(); i++) {
		FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
		if (fileHeader != null) {
			if (fileHeader.isEncrypted()) {
				isEncrypted = true;
				break;
			}
		}
	}
	
	return isEncrypted;
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:31,代碼來源:ZipFile.java

示例13: expandArtifact

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void expandArtifact(File artifactFile) throws IOException {
    try {
        ZipFile zipFile = new ZipFile(artifactFile);
        for (FileHeader each : (List<FileHeader>) zipFile.getFileHeaders()) {
            if (each.getFileName().startsWith("META-INF")) {
                continue;
            }
            if (each.isDirectory()) {
                continue;
            }
            this.archive.add(new ZipFileHeaderAsset(zipFile, each), each.getFileName());
        }
    } catch (ZipException e) {
        throw new IOException(e);
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:18,代碼來源:BuildTool.java

示例14: AddFolder

import net.lingala.zip4j.exception.ZipException; //導入依賴的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

示例15: decompressZipFile

import net.lingala.zip4j.exception.ZipException; //導入依賴的package包/類
public void decompressZipFile(String appName, String filename, String password) {
    String filePath = Environment.getExternalStorageDirectory() + "/" + appName;

    try {
        File src = new File(filePath, filename);
        ZipFile zipFile = new ZipFile(src);

        if (zipFile.isEncrypted())
            zipFile.setPassword(password);

        zipFile.extractAll(filePath);

    } catch (ZipException e) {
        e.printStackTrace();
    }
}
 
開發者ID:sanidhya09,項目名稱:androidprojectbase,代碼行數:17,代碼來源:UtilityClass.java


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