gpt4 book ai didi

com.publiccms.common.tools.ZipUtils.compress()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 12:23:31 27 4
gpt4 key购买 nike

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

ZipUtils.compress介绍

暂无

代码示例

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param out
 * @param basedir
 * @throws IOException
 */
private static void compress(Path sourceFilePath, ZipOutputStream out, String basedir) throws IOException {
  if (Files.isDirectory(sourceFilePath)) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourceFilePath);) {
      for (Path entry : stream) {
        BasicFileAttributes attrs = Files.readAttributes(entry, BasicFileAttributes.class);
        String fullName = Constants.BLANK.equals(basedir) ? entry.toFile().getName()
            : basedir + Constants.SEPARATOR + entry.toFile().getName();
        if (attrs.isDirectory()) {
          ZipEntry zipEntry = new ZipEntry(fullName + Constants.SEPARATOR);
          out.putNextEntry(zipEntry);
          compress(entry, out, fullName);
        } else {
          compressFile(entry.toFile(), out, fullName);
        }
      }
    } catch (IOException e) {
    }
  } else {
    compressFile(sourceFilePath.toFile(), out, sourceFilePath.toFile().getName());
  }
}

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param sourceFilePath
 * @param zipFilePath
 * @param overwrite
 * @return whether the compression is successful
 * @throws IOException
 */
public static boolean zip(String sourceFilePath, String zipFilePath, boolean overwrite) throws IOException {
  if (CommonUtils.notEmpty(sourceFilePath)) {
    File zipFile = new File(zipFilePath);
    if (zipFile.exists() && !overwrite) {
      return false;
    } else {
      zipFile.getParentFile().mkdirs();
      try (FileOutputStream outputStream = new FileOutputStream(zipFile);
          ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
          FileLock fileLock = outputStream.getChannel().tryLock();) {
        if (null != fileLock) {
          zipOutputStream.setEncoding(Constants.DEFAULT_CHARSET_NAME);
          compress(Paths.get(sourceFilePath), zipOutputStream, Constants.BLANK);
          return true;
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param out
 * @param basedir
 * @throws IOException
 */
private static void compress(Path sourceFilePath, ZipOutputStream out, String basedir) throws IOException {
  if (Files.isDirectory(sourceFilePath)) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourceFilePath);) {
      for (Path entry : stream) {
        BasicFileAttributes attrs = Files.readAttributes(entry, BasicFileAttributes.class);
        String fullName = Constants.BLANK.equals(basedir) ? entry.toFile().getName()
            : basedir + Constants.SEPARATOR + entry.toFile().getName();
        if (attrs.isDirectory()) {
          ZipEntry zipEntry = new ZipEntry(fullName + Constants.SEPARATOR);
          out.putNextEntry(zipEntry);
          compress(entry, out, fullName);
        } else {
          compressFile(entry.toFile(), out, fullName);
        }
      }
    } catch (IOException e) {
    }
  } else {
    compressFile(sourceFilePath.toFile(), out, sourceFilePath.toFile().getName());
  }
}

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param sourceFilePath
 * @param zipFilePath
 * @param overwrite
 * @return whether the compression is successful
 * @throws IOException
 */
public static boolean zip(String sourceFilePath, String zipFilePath, boolean overwrite) throws IOException {
  if (CommonUtils.notEmpty(sourceFilePath)) {
    File zipFile = new File(zipFilePath);
    if (zipFile.exists() && !overwrite) {
      return false;
    } else {
      zipFile.getParentFile().mkdirs();
      try (FileOutputStream outputStream = new FileOutputStream(zipFile);
          ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
          FileLock fileLock = outputStream.getChannel().tryLock();) {
        if (null != fileLock) {
          zipOutputStream.setEncoding(Constants.DEFAULT_CHARSET_NAME);
          compress(Paths.get(sourceFilePath), zipOutputStream, Constants.BLANK);
          return true;
        }
      }
    }
  }
  return false;
}

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