Java Code Examples for net.lingala.zip4j.core.ZipFile#isEncrypted()
The following examples show how to use
net.lingala.zip4j.core.ZipFile#isEncrypted() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipManager.java From AndroidZip with Apache License 2.0 | 6 votes |
/** * 解压 * * @param targetZipFilePath 待解压目标文件地址 * @param destinationFolderPath 解压后文件夹地址 * @param password 解压密码 * @param callback 回调 */ public static void unzip(String targetZipFilePath, String destinationFolderPath, String password, final IZipCallback callback) { if (!Zip4jUtil.isStringNotNullAndNotEmpty(targetZipFilePath) || !Zip4jUtil.isStringNotNullAndNotEmpty(destinationFolderPath)) { if (callback != null) callback.onFinish(false); return; } ZipLog.debug("unzip: targetZipFilePath=" + targetZipFilePath + " , destinationFolderPath=" + destinationFolderPath + " , password=" + password); try { ZipFile zipFile = new ZipFile(targetZipFilePath); if (zipFile.isEncrypted() && Zip4jUtil.isStringNotNullAndNotEmpty(password)) { zipFile.setPassword(password); } zipFile.setRunInThread(true); zipFile.extractAll(destinationFolderPath); timerMsg(callback, zipFile); } catch (Exception e) { if (callback != null) callback.onFinish(false); ZipLog.debug("unzip: Exception=" + e.getMessage()); } }
Example 2
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 从zip中删除文件 * @param inPath * @param storagePath * @param password * @return */ public static boolean removeFileInZip(String inPath,String storagePath,String password) { try { ZipFile zipFile = new ZipFile(inPath); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } List fileHeaderList = zipFile.getFileHeaders(); storagePath = storagePath.replaceAll("\\\\", "/"); for (int i =fileHeaderList.size() -1; i>0 ; i--) { FileHeader fileHeader = (FileHeader)fileHeaderList.get(i); if(fileHeader.getFileName().indexOf(storagePath)==0){ System.out.println("Name: " + fileHeader.getFileName()); zipFile.removeFile(fileHeader.getFileName()); } } return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 3
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 查看压缩包的文件列表 * @param inPath * @param password * @return */ public static boolean getNameFromZip(String inPath,String password) { try { ZipFile zipFile = new ZipFile(inPath); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } List fileHeaderList = zipFile.getFileHeaders(); for (int i = 0; i < fileHeaderList.size(); i++) { FileHeader fileHeader = (FileHeader)fileHeaderList.get(i); System.out.println("Name: " + fileHeader.getFileName()); System.out.println("Compressed Size: " + fileHeader.getCompressedSize()); System.out.println("Uncompressed Size: " + fileHeader.getUncompressedSize()); System.out.println("CRC: " + fileHeader.getCrc32()); System.out.println("************************************************************"); } return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 4
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 解压zip里的文件 * @param inPath * @param storagePath * @param outPath * @param password * @return */ public static boolean extractFileFromZip(String inPath,String storagePath,String outPath ,String password) { try { ZipFile zipFile = new ZipFile(inPath); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } List fileHeaderList = zipFile.getFileHeaders(); storagePath = storagePath.replaceAll("\\\\", "/"); for (int i =0;i<fileHeaderList.size() ;i++) { FileHeader fileHeader = (FileHeader)fileHeaderList.get(i); if(fileHeader.getFileName().indexOf(storagePath)==0){ zipFile.extractFile(fileHeader, outPath); zipFile.removeFile(fileHeader.getFileName()); } } return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 5
Source File: Utils.java From sheepit-client with GNU General Public License v2.0 | 6 votes |
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, String password, Log log) throws FermeExceptionNoSpaceLeftOnDevice { try { ZipFile zipFile = new ZipFile(zipFileName_); UnzipParameters unzipParameters = new UnzipParameters(); unzipParameters.setIgnoreDateTimeAttributes(true); if (password != null && zipFile.isEncrypted()) { zipFile.setPassword(password); } zipFile.extractAll(destinationDirectory, unzipParameters); } catch (ZipException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); log.debug("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + destinationDirectory + ") exception " + e + " stacktrace: " + sw.toString()); return -1; } return 0; }
Example 6
Source File: Zip4j.java From maven-framework-project with MIT License | 6 votes |
/** * 示例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(); } }
Example 7
Source File: ConfigPackage.java From Bats with Apache License 2.0 | 5 votes |
/** * 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")); }
Example 8
Source File: ZipArchive.java From Mzip-Android with Apache License 2.0 | 5 votes |
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(); } }
Example 9
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 5 votes |
/** * 解压zip里的所有文件 * @param inPath * @param outPath * @param password * @return */ public static boolean extractZip(String inPath,String outPath ,String password) { try { ZipFile zipFile = new ZipFile(inPath); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } zipFile.extractAll(outPath); return true; } catch (ZipException e) { e.printStackTrace(); } return false; }
Example 10
Source File: GtfsFeedImpl.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
protected String unzip(String compressedZip) { String unzippedFolder = compressedZip.substring(0, compressedZip.length() - 4) + "/"; log.info("Unzipping " + compressedZip + " to " + unzippedFolder); try { ZipFile zipFile = new ZipFile(compressedZip); if(zipFile.isEncrypted()) { throw new RuntimeException("Zip file is encrypted"); } zipFile.extractAll(unzippedFolder); } catch (ZipException e) { e.printStackTrace(); } return unzippedFolder; }
Example 11
Source File: ConfigPackage.java From attic-apex-core with Apache License 2.0 | 5 votes |
/** * 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")); }
Example 12
Source File: CompressUtil.java From maven-framework-project with MIT License | 5 votes |
/** * 使用给定密码解压指定的ZIP压缩文件到指定目录 * <p> * 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出 * * @param zip * 指定的ZIP压缩文件 * @param dest * 解压目录 * @param passwd * ZIP文件的密码 * @param charset * ZIP文件的编码 * @return 解压后文件数组 * @throws ZipException * 压缩文件有损坏或者解压缩失败抛出 */ public static File[] unzip(File zipFile, String dest, String passwd, String charset) throws ZipException { ZipFile zFile = new ZipFile(zipFile); if (null != charset || !"".equals(charset)) { zFile.setFileNameCharset(charset); } 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; }