当前位置: 首页>>代码示例>>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;未经允许,请勿转载。