本文整理匯總了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;
}