gpt4 book ai didi

org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.setUseZip64()方法的使用及代码示例

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

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

ZipArchiveOutputStream.setUseZip64介绍

[英]Whether Zip64 extensions will be used.

When setting the mode to Zip64Mode#Never, #putArchiveEntry, #closeArchiveEntry, #finish or #close may throw a Zip64RequiredException if the entry's size or the total size of the archive exceeds 4GB or there are more than 65536 entries inside the archive. Any archive created in this mode will be readable by implementations that don't support Zip64.

When setting the mode to Zip64Mode#Always, Zip64 extensions will be used for all entries. Any archive created in this mode may be unreadable by implementations that don't support Zip64 even if all its contents would be.

When setting the mode to Zip64Mode#AsNeeded, Zip64 extensions will transparently be used for those entries that require them. This mode can only be used if the uncompressed size of the ZipArchiveEntry is known when calling #putArchiveEntry or the archive is written to a seekable output (i.e. you have used the #ZipArchiveOutputStream(java.io.File)) - this mode is not valid when the output stream is not seekable and the uncompressed size is unknown when #putArchiveEntry is called.

If no entry inside the resulting archive requires Zip64 extensions then Zip64Mode#Never will create the smallest archive. Zip64Mode#AsNeeded will create a slightly bigger archive if the uncompressed size of any entry has initially been unknown and create an archive identical to Zip64Mode#Never otherwise. Zip64Mode#Always will create an archive that is at least 24 bytes per entry bigger than the one Zip64Mode#Never would create.

Defaults to Zip64Mode#AsNeeded unless #putArchiveEntry is called with an entry of unknown size and data is written to a non-seekable stream - in this case the default is Zip64Mode#Never.
[中]是否将使用Zip64扩展。
将模式设置为Zip64Mode时,如果条目大小或归档文件的总大小超过4GB,或者归档文件中的条目超过65536条,则“从不”、“putArchiveEntry”、“closeArchiveEntry”、“完成”或“关闭”可能会引发Zip64RequiredException。在这种模式下创建的任何存档都可以被不支持Zip64的实现读取。
将模式设置为Zip64Mode#Always时,所有条目都将使用Zip64扩展名。不支持Zip64的实现可能无法读取在此模式下创建的任何存档,即使其所有内容都将被删除。
根据需要将模式设置为Zip64Mode#时,Zip64扩展将透明地用于需要它们的条目。只有在调用#putArchiveEntry时ZipArchiveEntry的未压缩大小已知,或者将存档写入可查找的输出(即,您使用了#ZipArchiveOutputStream(java.io.File)),才能使用此模式。当输出流不可查找时,此模式无效;当#putArchiveEntry被删除时,未压缩大小未知打电话。
如果生成的存档中没有条目需要Zip64扩展,那么Zip64Mode#永远不会创建最小的存档。如果任何条目的未压缩大小最初未知,Zip64Mode#根据需要将创建稍大的存档,并创建与Zip64Mode#完全相同的存档。Zip64Mode#总是会创建一个存档,每个条目至少有24字节,比Zip64Mode#永远不会创建的大。
默认值为Zip64Mode#根据需要,除非使用未知大小的条目调用#putArchiveEntry,并将数据写入不可查找的流——在这种情况下,默认值为Zip64Mode#Never。

代码示例

代码示例来源:origin: com.github.duanxinyuan/library-util-common

try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new File(zipFilePath))) {
  zipArchiveOutputStream.setUseZip64(Zip64Mode.AsNeeded);

代码示例来源:origin: com.github.duanxinyuan/library-util-common

/**
 * 把文件压缩成zip格式
 * @param files 需要压缩的文件集合
 * @param zipFilePath 压缩后的zip文件路径 ,如"D:/test/aa.zip";
 */
public static void zip(File[] files, String zipFilePath) {
  if (files != null && files.length > 0) {
    if (isZip(zipFilePath)) {
      try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new File(zipFilePath))) {
        //使用Zip64扩展
        zipArchiveOutputStream.setUseZip64(Zip64Mode.AsNeeded);
        // 将每个文件用ZipArchiveEntry封装,再用ZipArchiveOutputStream写到压缩文件中
        for (File file : files) {
          if (file.exists()) {
            ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, file.getName());
            zipArchiveOutputStream.putArchiveEntry(zipArchiveEntry);
            if (file.isDirectory()) {
              continue;
            }
            IOUtils.copy(new FileInputStream(file), zipArchiveOutputStream);
            zipArchiveOutputStream.closeArchiveEntry();
          }
        }
        zipArchiveOutputStream.finish();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
}

代码示例来源:origin: org.alfresco/alfresco-repository

public void startExport()
{
  // ALF-2016
  zipStream = new ZipArchiveOutputStream(outputStream);
  // NOTE: This encoding allows us to workaround bug...
  //       http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
  zipStream.setEncoding("UTF-8");
  zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
  zipStream.setUseLanguageEncodingFlag(true);
  zipStream.setFallbackToUTF8(true);
  zipStream.setUseZip64(Zip64Mode.Always);
}

代码示例来源:origin: Alfresco/alfresco-repository

public void startExport()
{
  // ALF-2016
  zipStream = new ZipArchiveOutputStream(outputStream);
  // NOTE: This encoding allows us to workaround bug...
  //       http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
  zipStream.setEncoding("UTF-8");
  zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
  zipStream.setUseLanguageEncodingFlag(true);
  zipStream.setFallbackToUTF8(true);
  zipStream.setUseZip64(Zip64Mode.Always);
}

代码示例来源:origin: org.apache.ant/ant-compress

private void configure(ZipArchiveOutputStream o) {
  o.setLevel(level);
  o.setComment(comment);
  o.setFallbackToUTF8(fallBackToUTF8);
  o.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
  o.setCreateUnicodeExtraFields(createUnicodeExtraFields.getPolicy());
  o.setUseZip64(zip64Mode.getPolicy());
}

代码示例来源:origin: com.atlassian.jira/jira-core

try
  zip.setUseZip64(Zip64Mode.AsNeeded);
  zip.putArchiveEntry(new ZipArchiveEntry(ENTITIES_XML));
  exportJIRA(loggedInUser, style, zip);

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