/** * 解压zip格式压缩包 */ public static void unzip(String sourceZip, String destDir) throws Exception { ZipFile zipFile = new ZipFile(sourceZip); zipFile.extractAll(destDir); }
/** * 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); } }
public static void unzipAllFile(File zip, String dir) throws Exception { ZipFile zipFile = new ZipFile(zip); zipFile.setFileNameCharset("utf-8"); zipFile.extractAll(dir); }
public static boolean verifyBackupFile(File file) { try { ZipFile zipFile = new ZipFile(file); FileHeader preferences = zipFile.getFileHeader(BACKUP_PREFERENCES_PATH); FileHeader notificationRules = zipFile.getFileHeader(BACKUP_NOTIFICATION_RULES_PATH); FileHeader commandAliases = zipFile.getFileHeader(BACKUP_COMMAND_ALIASES_PATH); return preferences != null && notificationRules != null && commandAliases != null; } catch (ZipException e) { e.printStackTrace(); return false; } }
/** * Unzip the contents of the zip file in the passed destination directory. If the directory * does not exist, create it. * * @param zipFile * @param destDir * @throws KlabException */ public static void unzip(File zipFile, File destDir) throws KlabException { ZipFile zFile; try { zFile = new ZipFile(zipFile); if (!zFile.isValidZipFile()) { throw new KlabIOException("file " + zipFile + " is not a valid archive"); } if (!destDir.exists()) { destDir.mkdirs(); } // if (zFile.isEncrypted()) { // zFile.setPassword(passwd.toCharArray()); // } zFile.extractAll(destDir.toString()); } catch (ZipException e) { throw new KlabIOException(e); } }
ZipFile zFile = new ZipFile(zipFile); zFile.setFileNameCharset(SkeletonConstant.ENCODING_UTF_8); if (!zFile.isValidZipFile()) { throw new ZipException("Invalid zip files, it may be damaged"); if (zFile.isEncrypted()) { if (StringUtils.isEmpty(password)) { throw new ZipException("Password can't be empty with encryption mode"); zFile.setPassword(password.toCharArray()); zFile.extractAll(destPath); List<FileHeader> headerList = zFile.getFileHeaders(); List<File> extractedFileList = new ArrayList<File>(); for (FileHeader fileHeader : headerList) {
ZipFile zipFile = new ZipFile(file); if (zipFile.isEncrypted()) { throw new ZipException("Encrypted conf package not supported yet"); newDirectory.mkdirs(); directory = newDirectory.getAbsolutePath(); zipFile.extractAll(directory); processPropertiesXml(); processAppDirectory(new File(directory, "app"));
ZipFile zipFile = new ZipFile(fileStoreFile); if (!app.getUseFreemarkerTemplate()) FileHeader fileHeader = zipFile.getFileHeader("index.html"); if (fileHeader == null) zipFile.extractAll( fileStore.getStorageDir() + separatorChar + FILE_STORE_PLUGIN_APPS_PATH + separatorChar + app.getId() + separatorChar);
try { sendHandle(0, ""); ZipFile zipFile = new ZipFile(zipFilePath); if (!ZXFileUtil.isFileExists(zipFilePath)) { sendHandle(3, "文件不存在"); return; zipFile.setFileNameCharset("UTF-8"); if (!zipFile.isValidZipFile()) { sendHandle(3, "文件不合法"); return; final int total = zipFile.getFileHeaders().size(); int progressNow = -1; for (int i = 0; i < zipFile.getFileHeaders().size(); i++) { fileHeader = (FileHeader) zipFile.getFileHeaders().get(i); zipFile.extractFile(fileHeader, outputPath); int progress = (int) ((i + 1) * 1.0 * 100 / total); if (progress == progressNow) {//此时与上次相同,就不反复监听了
public static void restoreBackup(Context context, File file, String password) throws IOException { try { ZipFile zipFile = new ZipFile(file); zipFile.setPassword(password); Reader reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream( zipFile.getFileHeader(BACKUP_PREFERENCES_PATH)))); importPreferencesFromJson(context, reader); reader.close(); for (Object header : zipFile.getFileHeaders()) { if (!(header instanceof FileHeader)) continue; if (fileHeader.getFileName().startsWith(BACKUP_SERVER_PREFIX) && fileHeader.getFileName().endsWith(BACKUP_SERVER_SUFFIX)) { reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream( fileHeader))); ServerConfigData data = SettingsHelper.getGson().fromJson(reader, UUID.fromString(uuid)); try { helper.loadKeyStore(zipFile.getInputStream(fileHeader)); helper.saveKeyStore(); } catch (GeneralSecurityException exception) { if (iof != -1) name = name.substring(iof + 1); zipFile.extractFile(fileHeader,
Files.mkdirs(zipFile.getParentFile()); try { final ZipFile zip = new ZipFile(zipFile); if (content.files != null) { for (final File f : content.files) { zip.addFile(f, parameters); parameters.setSourceExternalStream(true); parameters.setFileNameInZip(c.name); zip.addStream(stream, parameters); } catch (final IOException e) { // more than unlikely throw new IllegalStateException(e);
@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); } }
/** * Extract. * * @param zipFile4j * the zip file4j * @param destination * the destination * @param password * the password * @throws ZipException * the zip exception */ public static void extract(final ZipFile zipFile4j, final File destination, final String password) throws ZipException { if (zipFile4j.isEncrypted()) { zipFile4j.setPassword(password); } zipFile4j.extractAll(destination.getAbsolutePath()); }
/** * Extracts all the files in the given zip file to the input destination path. * If zip file does not exist or destination path is invalid then an * exception is thrown. * @param destPath * @throws ZipException */ public void extractAll(String destPath) throws ZipException { extractAll(destPath, null); }
ZipFile z = new ZipFile(f); zp.setFileNameInZip(it.getName().replace(".", "/") + ".class"); z.addStream(new ByteArrayInputStream(b), zp); } catch (IOException | net.lingala.zip4j.exception.ZipException e) { throw new RuntimeException(e); ZipFile mj = new ZipFile(generatedJar); ZipParameters zp = new ZipParameters(); zp.setFileNameInZip("collected-cli-classes.jar"); mj.removeFile("collected-cli-classes.jar"); } catch (Exception e) { mj.addFile(f, zp);
public BackupFile(String path) { mPath = path; try { mZip = new ZipFile(path); mIsEncrypted = mZip.isEncrypted(); if(mZip.getComment() == null) return; mInfo = mZip.getComment().split(":"); } catch(ZipException e) { Log.w(TAG, e); return; } if(mInfo.length < 2 || !mInfo[0].startsWith("rxdbak") || mInfo[0].equals("rxdbak")) return; mVersion = Integer.parseInt(mInfo[0].substring("rxdbak".length())); mTimestamp = new Date(Long.parseLong(mInfo[1])); if(mInfo.length >= 3) mDbVersion = Integer.parseInt(mInfo[2].substring("DBv".length())); else mDbVersion = -1; }
private void generateZipFile() { try { File outputFile = new File(this.workFolder.getName() + ".zip"); if (outputFile.exists()) { Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting."); outputFile.delete(); } ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile); Logger.info("Generating " + output.getFile().getAbsolutePath()); ZipParameters params = new ZipParameters(); params.setIncludeRootFolder(false); params.setRootFolderInZip(""); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params); params.setRootFolderInZip("classes"); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params); } catch (Throwable t) { Logger.error("Unable to generate final zip file.", t); } }
final ZipFile zip = new ZipFile(outFile); final File dataDir = new File(RxDroid.getPackageInfo().applicationInfo.dataDir); zip.addFile(file, zp); zip.setComment("rxdbak1:" + System.currentTimeMillis() + ":DBv" + DatabaseHelper.DB_VERSION);