gpt4 book ai didi

net.lingala.zip4j.core.ZipFile类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 15:00:40 27 4
gpt4 key购买 nike

本文整理了Java中net.lingala.zip4j.core.ZipFile类的一些代码示例,展示了ZipFile类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile类的具体详情如下:
包路径:net.lingala.zip4j.core.ZipFile
类名称:ZipFile

ZipFile介绍

[英]Base class to handle zip files. Some of the operations supported in this class are:

  • Create Zip File
  • Add files to zip file
  • Add folder to zip file
  • Extract files from zip files
  • Remove files from zip file
    [中]处理zip文件的基类。此类支持的一些操作包括:
    *创建Zip文件
    *将文件添加到zip文件
    *将文件夹添加到zip文件
    *从zip文件中提取文件
    *从zip文件中删除文件

代码示例

代码示例来源:origin: io.leopard/leopard-util

/**
 * 解压zip格式压缩包
 */
public static void unzip(String sourceZip, String destDir) throws Exception {
  ZipFile zipFile = new ZipFile(sourceZip);
  zipFile.extractAll(destDir);
}

代码示例来源:origin: org.apache.apex/apex-engine

public static void createAppPackageFile(File fileToBeCreated, File directory) throws ZipException
{
 ZipFile zipFile = new ZipFile(fileToBeCreated);
 ZipParameters params = new ZipParameters();
 params.setIncludeRootFolder(false);
 zipFile.addFolder(directory, params);
}

代码示例来源:origin: com.jalalkiswani/jk-util

/**
 * 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);
  }
}

代码示例来源:origin: sunhapper/SpEditTool

public static void unzipAllFile(File zip, String dir) throws Exception {
 ZipFile zipFile = new ZipFile(zip);
 zipFile.setFileNameCharset("utf-8");
 zipFile.extractAll(dir);
}

代码示例来源:origin: MCMrARM/revolution-irc

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;
  }
}

代码示例来源:origin: org.integratedmodelling/klab-common

/**
 * 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);
  }
}

代码示例来源:origin: Nepxion/Skeleton

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) {

代码示例来源:origin: org.apache.apex/apex-engine

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"));

代码示例来源:origin: SpringCloud/spring-cloud-codegen

ZipFile zipFile = new ZipFile(destPath);
if (srcFile.isDirectory()) {
    ArrayList<File> subFileList = new ArrayList<File>();
    Collections.addAll(subFileList, subFiles);
    zipFile.addFiles(subFileList, parameters);
  zipFile.addFolder(srcFile, parameters);
} else {
  zipFile.addFile(srcFile, parameters);

代码示例来源:origin: org.molgenis/molgenis-apps

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);

代码示例来源:origin: StannyBing/ZXUtils

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) {//此时与上次相同,就不反复监听了

代码示例来源:origin: MCMrARM/revolution-irc

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,

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

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);

代码示例来源:origin: org.wildfly.swarm/tools

@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);
  }
}

代码示例来源:origin: de.alpharogroup/file-worker

/**
 * 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());
}

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * 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);
  
}

代码示例来源:origin: io.macgyver/macgyver-core

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);

代码示例来源:origin: jclehner/rxdroid

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;
}

代码示例来源:origin: dwatling/apk-decompiler

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);
  }
}

代码示例来源:origin: jclehner/rxdroid

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);

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com