org.apache.tools.zip.ZipOutputStream.<init>()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(172)

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

ZipOutputStream.<init>介绍

[英]Creates a new ZIP OutputStream writing to a File. Will use random access if possible.
[中]创建写入文件的新ZIP输出流。如果可能,将使用随机访问。

代码示例

代码示例来源:origin: jenkinsci/jenkins

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
  zip.setUseZip64(Zip64Mode.AsNeeded);
}

代码示例来源:origin: apache/hive

public static void zip(String parentDir, String[] inputFiles, String outputFile)
  throws IOException {
 ZipOutputStream output = null;
 try {
  output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
  for (int i = 0; i < inputFiles.length; i++) {
   File f = new File(parentDir, inputFiles[i]);
   FileInputStream input = new FileInputStream(f);
   output.putNextEntry(new ZipEntry(inputFiles[i]));
   try {
    IOUtils.copy(input, output);
   } finally {
    input.close();
   }
  }
 } finally {
  org.apache.hadoop.io.IOUtils.closeStream(output);
 }
}

代码示例来源:origin: jenkinsci/jenkins

private static void zip(StaplerResponse rsp, VirtualFile root, VirtualFile dir, String glob) throws IOException, InterruptedException {
  OutputStream outputStream = rsp.getOutputStream();
  try (ZipOutputStream zos = new ZipOutputStream(outputStream)) {
    zos.setEncoding(System.getProperty("file.encoding")); // TODO JENKINS-20663 make this overridable via query parameter

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

+ getDestFile().getAbsolutePath());
try (ZipOutputStream zOut = new ZipOutputStream(getDestFile())) {
  zOut.setEncoding(getEncoding());
  zOut.setUseZip64(getZip64Mode().getMode());

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

try {
  if (!skipWriting) {
    zOut = new ZipOutputStream(zipFile);

代码示例来源: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 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: org.eclipse.hudson.main/hudson-core

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
}

代码示例来源:origin: hudson/hudson-2.x

ZipArchiver(OutputStream out) {
  zip = new ZipOutputStream(out);
  zip.setEncoding(System.getProperty("file.encoding"));
}

代码示例来源:origin: com.bbossgroups.pdp/pdp-system

public static void jar(String inputFileName, String outputFileName)
    throws Exception {
  ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
      outputFileName));
  out.setEncoding("GBK"); // ###### 这句话是关键,指定输出的编码方式
  File f = new File(inputFileName);
  jar(out, f, "");
  out.close();
}

代码示例来源:origin: com.github.javahaohao/utils

public static boolean doZip(String srcStr, String targetStr, String targetName) {
  File zipDir = new File(srcStr);
  // 未指定压缩文件名,默认为"ZipFile"
  if (StringUtils.isBlank(targetName))
    targetName = "ZipFile";
  // 添加".zip"后缀
  if (!targetName.endsWith(".zip"))
    targetName += ".zip";
  try {
    zipOut = new ZipOutputStream(new FileOutputStream(new File(targetStr + File.separator + targetName)));
    // 压缩文件
    compressFile(zipDir, "", zipOut);
    zipOut.close();
  } catch (IOException e) {
    flag = false;
    e.printStackTrace();
  }
  return flag;
}
/**

代码示例来源:origin: org.gradle/gradle-core

public ZipOutputStream createArchiveOutputStream(File destination) throws IOException {
  ZipOutputStream outStream = new ZipOutputStream(destination);
  try {
    outStream.setUseZip64(zip64Mode);
    outStream.setMethod(entryCompressionMethod);
    return outStream;
  } catch (Exception e) {
    IOUtils.closeQuietly(outStream);
    String message = String.format("Unable to create ZIP output stream for file %s.", destination);
    throw new UncheckedIOException(message, e);
  }
}

代码示例来源:origin: org.apache.hive/hive-common

public static void zip(String parentDir, String[] inputFiles, String outputFile)
  throws IOException {
 ZipOutputStream output = null;
 try {
  output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
  for (int i = 0; i < inputFiles.length; i++) {
   File f = new File(parentDir, inputFiles[i]);
   FileInputStream input = new FileInputStream(f);
   output.putNextEntry(new ZipEntry(inputFiles[i]));
   try {
    IOUtils.copy(input, output);
   } finally {
    input.close();
   }
  }
 } finally {
  org.apache.hadoop.io.IOUtils.closeStream(output);
 }
}

代码示例来源:origin: com.github.tianjing/tgtools.core

/**
 * 初始化 设置输出流
 *
 * @param p_OutputStream
 */
public void init(OutputStream p_OutputStream) {
  if (null != p_OutputStream) {
    m_ZipOutputStream = new ZipOutputStream(new CheckedOutputStream(p_OutputStream,
        new CRC32()));
  } else {
    m_ZipOutputStream = new ZipOutputStream(new CheckedOutputStream(new ByteArrayOutputStream(), new CRC32()));
  }
  // 支持中文
  m_ZipOutputStream.setEncoding(m_Encode);
  // 启用压缩
  m_ZipOutputStream.setMethod(ZipOutputStream.DEFLATED);
  // 压缩级别为最强压缩,但时间要花得多一点
  m_ZipOutputStream.setLevel(m_ZipLevel);
}

代码示例来源:origin: gradle.plugin.com.bettycc.umengauto/core

private static void writePack(Map<ZipEntry, byte[]> readZipAllEntry, ZipFile file, String path, String channel)
    throws Exception {
  ZipOutputStream zot = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path)));
  Iterator<ZipEntry> iterator = readZipAllEntry.keySet().iterator();
  while (iterator.hasNext()) {
    ZipEntry entry = iterator.next();
    zot.putNextEntry(entry);
    byte[] data = readZipAllEntry.get(entry);
    zot.write(data, 0, data.length);
    // System.out.println(entry);
    // System.out.println(entry.getSize() + " ," +
    // entry.getCompressedSize() + "," + data.length);
    zot.closeEntry();
  }
  zot.putNextEntry(new ZipEntry("META-INF/channel_" + channel));
  zot.closeEntry();
  zot.close();
}

代码示例来源:origin: com.github.tianjing/tgtools.core

private static ZipOutputStream createZipOutputStream(OutputStream p_OutputSteam,String p_Comment)
{
  CheckedOutputStream csum = new CheckedOutputStream(p_OutputSteam,
      new CRC32());
  ZipOutputStream zos = new ZipOutputStream(csum);
  // 支持中文
  zos.setEncoding("GBK");
  // 设置压缩包注释
  zos.setComment(p_Comment);
  // 启用压缩
  zos.setMethod(ZipOutputStream.DEFLATED);
  // 压缩级别为最强压缩,但时间要花得多一点
  zos.setLevel(Deflater.BEST_COMPRESSION);
  return zos;
}

代码示例来源:origin: org.hudsonci.plugins/cvs

public Void invoke(File ws, VirtualChannel channel) throws IOException {
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os));
    if (flatten) {
      archive(ws, getModuleLocations()[0].getModule(), zos, true);
    } else {
      for (ModuleLocation moduleLocation : getModuleLocations()) {
        File mf = new File(ws, moduleLocation.getLocalDir());
        if (!mf.exists()) {
          // directory doesn't exist. This happens if a directory that was checked out
          // didn't include any file.
          continue;
        }
        archive(mf, ModuleLocationImpl.DEFAULT_LOCAL_DIR.equals(moduleLocation.getLocalDir())
            ? ModuleLocationImpl.TAGGING_SUBDIR : moduleLocation.getLocalDir(), zos, true);
      }
    }
    zos.close();
    return null;
  }
});

相关文章