本文整理汇总了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();
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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;
}
}
示例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"));
}
示例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);
}
}
示例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");
}
}
示例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;
}