当前位置: 首页>>代码示例>>Java>>正文


Java ZipFile.isEncrypted方法代码示例

本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.isEncrypted方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.isEncrypted方法的具体用法?Java ZipFile.isEncrypted怎么用?Java ZipFile.isEncrypted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.lingala.zip4j.core.ZipFile的用法示例。


在下文中一共展示了ZipFile.isEncrypted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

示例3: decompressZipFile

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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

示例4: example7

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 示例7 解压压缩文件
 */
@Test
public void example7(){
	
	example4();
	
	try {
           ZipFile zipFile = new ZipFile("src/main/resources/AddFilesWithAESZipEncryption.zip");
           if (zipFile.isEncrypted()) {
               // if yes, then set the password for the zip file
               zipFile.setPassword("123456");
               zipFile.extractAll("src/main/resources/zipfile");
           }
       } catch (ZipException e) {
           e.printStackTrace();
       }
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:20,代码来源:Zip4j.java

示例5: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 使用给定密码解压指定的ZIP压缩文件到指定目录
 * <p>
 * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
 * @param dest 解压目录
 * @param passwd ZIP文件的密码
 * @return  解压后文件数组
 * @throws ZipException 压缩文件有损坏或者解压缩失败抛出
 */
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
    ZipFile zFile = new ZipFile(zipFile);
    zFile.setFileNameCharset("GBK");
    if (!zFile.isValidZipFile()) {
        throw new ZipException("压缩文件不合法,可能被损坏.");
    }
    File destDir = new File(dest);
    if (destDir.isDirectory() && !destDir.exists()) {
        destDir.mkdir();
    }
    if (zFile.isEncrypted()) {
        zFile.setPassword(passwd.toCharArray());
    }
    zFile.extractAll(dest);

    List<FileHeader> headerList = zFile.getFileHeaders();
    List<File> extractedFileList = new ArrayList<File>();
    for(FileHeader fileHeader : headerList) {
        if (!fileHeader.isDirectory()) {
            extractedFileList.add(new File(destDir,fileHeader.getFileName()));
        }
    }
    File [] extractedFiles = new File[extractedFileList.size()];
    extractedFileList.toArray(extractedFiles);
    return extractedFiles;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:36,代码来源:ZipUtil.java

示例6: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password) {
    try {
        ZipFile zipFile = new ZipFile(targetZipFilePath);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        zipFile.extractAll(destinationFolderPath);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:ghost1372,项目名称:Mzip-Android,代码行数:13,代码来源:ZipArchive.java

示例7: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/** 
 * 使用给定密码解压指定的ZIP压缩文件到指定目录 
 * <p> 
 * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出 
 * @param zipFile 指定的ZIP压缩文件
 * @param dest 解压目录 
 * @param passwd ZIP文件的密码 
 * @return  解压后文件数组 
 * @throws ZipException 压缩文件有损坏或者解压缩失败抛出 
 */  
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {  
    ZipFile zFile = new ZipFile(zipFile);  
    zFile.setFileNameCharset("GBK");  
    if (!zFile.isValidZipFile()) {  
        throw new ZipException("压缩文件不合法,可能被损坏.");  
    }  
    File destDir = new File(dest);  
    if (destDir.isDirectory() && !destDir.exists()) {  
        destDir.mkdir();  
    }  
    if (zFile.isEncrypted()) {  
        zFile.setPassword(passwd.toCharArray());  
    }  
    zFile.extractAll(dest);  
      
    List<FileHeader> headerList = zFile.getFileHeaders();  
    List<File> extractedFileList = new ArrayList<File>();  
    for(FileHeader fileHeader : headerList) {  
        if (!fileHeader.isDirectory()) {  
            extractedFileList.add(new File(destDir,fileHeader.getFileName()));  
        }  
    }  
    File [] extractedFiles = new File[extractedFileList.size()];  
    extractedFileList.toArray(extractedFiles);  
    return extractedFiles;  
}
 
开发者ID:Kuangcp,项目名称:JavaToolKit,代码行数:37,代码来源:CompressUtil.java

示例8: decompress

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * Decompress.
 *
 * @param sourceZipFilePath
 *            the source zip file path
 * @param extractedZipFilePath
 *            the extracted zip file path
 * @param password
 *            the password
 */
public void decompress(String sourceZipFilePath, String extractedZipFilePath, String password) {
	try {
		ZipFile zipFile = new ZipFile(sourceZipFilePath);
		if (zipFile.isEncrypted()) {
			zipFile.setPassword(password);
		}

		zipFile.extractAll(extractedZipFilePath);
	} catch (Exception e) {
		JKExceptionUtil.handle(e);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:23,代码来源:JKCompressionUtil.java

示例9: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static File[] unzip(String source, String destination, String password){
    try {
        ZipFile zipFile = new ZipFile(source);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        zipFile.extractAll(destination);
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return listFilesIn(destination);
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:13,代码来源:ZipArchiver.java

示例10: ExtractByLoopAllFiles

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public ExtractByLoopAllFiles() {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractByLoopAllFiles.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!");
		}
		
		// Get the list of file headers from the zip file
		List fileHeaderList = zipFile.getFileHeaders();
		
		// Loop through the file headers
		for (int i = 0; i < fileHeaderList.size(); i++) {
			FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
			// Extract the file to the specified destination
			zipFile.extractFile(fileHeader, "c:\\ZipTest\\");
		}
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:28,代码来源:ExtractByLoopAllFiles.java

示例11: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/** 
 * 使用给定密码解压指定的ZIP压缩文件到指定目录 
 * <p> 
 * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出 
 * @param zip 指定的ZIP压缩文件 
 * @param dest 解压目录 
 * @param passwd ZIP文件的密码 
 * @return  解压后文件数组 
 * @throws ZipException 压缩文件有损坏或者解压缩失败抛出 
 * @throws IOException 
 */  
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException, IOException {
    if(StringUtils.isEmpty(dest))
        throw new ZipException("@@@@Error: Unzip destination can not be empty!!!!");
    if(zipFile == null || !zipFile.exists())
        throw new ZipException("@@@@Error: Unzip file not exist!!!!");
    if(AppFileUtils.getContentType(zipFile.getName()).equals("rar")){
        return unrar(zipFile,dest);
    } else {
        File destDir = new File(dest);
        FileUtils.forceMkdir(destDir);
        ZipFile zFile = new ZipFile(zipFile);
        zFile.setFileNameCharset(Constants.GBK); //不可随意更换位置
        if (!zFile.isValidZipFile()) {
            throw new ZipException(String.format("@@@@Error: Unzip file: %s is broken!!!!",zipFile.getAbsolutePath()));
        }
        if (zFile.isEncrypted()) {
            zFile.setPassword(passwd.toCharArray());
        }
        zFile.extractAll(dest);

        @SuppressWarnings("unchecked")
        List<FileHeader> headerList = zFile.getFileHeaders();
        List<File> extractedFileList = new ArrayList<File>();
        for (FileHeader fileHeader : headerList) {
            if (!fileHeader.isDirectory()) {
                File out = new File(destDir, fileHeader.getFileName());
                extractedFileList.add(out);
                log.debug("File to be extracted....." + out.getAbsolutePath());
            }
        }
        File[] extractedFiles = new File[extractedFileList.size()];
        extractedFileList.toArray(extractedFiles);
        return extractedFiles;
    }
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:47,代码来源:CompressUtil.java

示例12: ConfigPackage

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * Creates an Config Package object.
 *
 * @param file
 * @throws java.io.IOException
 * @throws net.lingala.zip4j.exception.ZipException
 */
public ConfigPackage(File file) throws IOException, ZipException
{
  super(file);
  Manifest manifest = getManifest();
  if (manifest == null) {
    throw new IOException("Not a valid config package. MANIFEST.MF is not present.");
  }
  Attributes attr = manifest.getMainAttributes();
  configPackageName = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_NAME);
  appPackageName = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_NAME);
  appPackageGroupId = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID);
  appPackageMinVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MIN_VERSION);
  appPackageMaxVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MAX_VERSION);
  configPackageDescription = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_DESCRIPTION);
  String classPathString = attr.getValue(ATTRIBUTE_CLASS_PATH);
  String filesString = attr.getValue(ATTRIBUTE_FILES);
  if (configPackageName == null) {
    throw new IOException("Not a valid config package.  DT-Conf-Package-Name is missing from MANIFEST.MF");
  }
  if (!StringUtils.isBlank(classPathString)) {
    classPath.addAll(Arrays.asList(StringUtils.split(classPathString, " ")));
  }
  if (!StringUtils.isBlank(filesString)) {
    files.addAll(Arrays.asList(StringUtils.split(filesString, " ")));
  }

  ZipFile zipFile = new ZipFile(file);
  if (zipFile.isEncrypted()) {
    throw new ZipException("Encrypted conf package not supported yet");
  }
  File newDirectory = Files.createTempDirectory("dt-configPackage-").toFile();
  newDirectory.mkdirs();
  directory = newDirectory.getAbsolutePath();
  zipFile.extractAll(directory);
  processPropertiesXml();
  processAppDirectory(new File(directory, "app"));
}
 
开发者ID:apache,项目名称:apex-core,代码行数:45,代码来源:ConfigPackage.java

示例13: BBBEPubZip4J

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public BBBEPubZip4J(String fileUrl, char[] zipPassword) throws ZipException {
	mFileUrl = fileUrl;
	mZipFile = new ZipFile(fileUrl);
	if (mZipFile.isEncrypted()) {
		mZipFile.setPassword(zipPassword);
	}
}
 
开发者ID:blinkboxbooks,项目名称:android-ePub-Library,代码行数:8,代码来源:BBBEPubZip4J.java

示例14: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * Extract given zip file into given directory.
 *
 * @param zipFile
 * @param targetDirectory
 * @throws DPUException
 */
private void unzip(File zipFile, File targetDirectory) throws DPUException{
    try {
        final ZipFile zip = new ZipFile(zipFile);
        if (zip.isEncrypted()) {
            throw ContextUtils.dpuException(ctx, "unzipper.errors.file.encrypted");
        }
        zip.extractAll(targetDirectory.toString());
    } catch (ZipException ex) {
        throw ContextUtils.dpuException(ctx, ex, "unzipper.errors.dpu.extraction.failed");
    }
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:19,代码来源:UnZipper.java

示例15: unzipFileIntoDirectory

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, String password) throws FermeExceptionNoSpaceLeftOnDevice {
	try {
		ZipFile zipFile = new ZipFile(zipFileName_);
		
		if (password != null && zipFile.isEncrypted()) {
			zipFile.setPassword(password);
		}
		zipFile.extractAll(destinationDirectory);
	}
	catch (ZipException e) {
		e.printStackTrace();
		return -1;
	}
	return 0;
}
 
开发者ID:laurent-clouet,项目名称:sheepit-client,代码行数:16,代码来源:Utils.java


注:本文中的net.lingala.zip4j.core.ZipFile.isEncrypted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。