/**
  * Closes this output stream and releases any system resources associated with the stream.
  *
  * @exception IOException if an I/O error occurs.
  * @throws Zip64RequiredException if the archive's size exceeds 4 GByte or there are more than
  *     65535 entries inside the archive and {@link #setUseZip64} is {@link Zip64Mode#Never}.
  */
 @Override
 public void close() throws IOException {
   if (!finished) {
     finish();
   }
   destroy();
 }
  public static void compress(
      File[] srcFiles, File zipFile, String compressPath, String encoding, String comment) {

    ZipArchiveOutputStream zaos = null;
    try {
      zaos = new ZipArchiveOutputStream(zipFile);

      CompressUtilsHelper.config(zaos, encoding, comment);

      if (ValidateUtilsHelper.isBlank(compressPath)) {
        compressPath = CommonsConstants.EMPTY;
      }

      for (File file : srcFiles) {
        String zipFilePath = FilenameUtils.concat(compressPath, file.getName());
        CompressUtilsHelper.compress(file, zaos, zipFilePath);
      }

      zaos.closeArchiveEntry();
      zaos.finish();
    } catch (Exception e) {
      throw new CommonsException("Compress files to " + zipFile.getPath() + " failed!", e);
    } finally {
      IOUtils.closeQuietly(zaos);
    }
  }
Beispiel #3
0
  public String export(OutputStream os, XWikiContext context) throws IOException, XWikiException {
    if (this.files.size() == 0) {
      return "No Selected file";
    }

    ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
    zos.setEncoding(XAR_FILENAME_ENCODING);
    // By including the unicode extra fields, it is possible to extract XAR-files
    // containing documents with non-ascii characters in the document name using InfoZIP,
    // and the filenames will be correctly converted to the character set of the local
    // file system.
    zos.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
    for (int i = 0; i < this.files.size(); i++) {
      DocumentInfo docinfo = this.files.get(i);
      XWikiDocument doc = docinfo.getDoc();
      addToZip(doc, zos, this.withVersions, context);
    }
    addInfosToZip(zos, context);
    zos.finish();
    zos.flush();

    return "";
  }
  public static void compress(
      File srcFile, File zipFile, String compressPath, String encoding, String comment) {

    ZipArchiveOutputStream zaos = null;
    try {
      zaos = new ZipArchiveOutputStream(zipFile);

      CompressUtilsHelper.config(zaos, encoding, comment);

      if (ValidateUtilsHelper.isBlank(compressPath)) {
        compressPath = srcFile.getName();
      }

      CompressUtilsHelper.compress(srcFile, zaos, compressPath);

      zaos.closeArchiveEntry();
      zaos.finish();
    } catch (Exception e) {
      throw new CommonsException(
          "Compress " + srcFile.getPath() + " to " + zipFile.getPath() + " failed!", e);
    } finally {
      IOUtils.closeQuietly(zaos);
    }
  }