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

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

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

ZipArchiveOutputStream.finish介绍

暂无

代码示例

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

/**
 * Closes this output stream and releases any system resources
 * associated with the stream.
 *
 * @throws  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 {
  try {
    if (!finished) {
      finish();
    }
  } finally {
    destroy();
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

zos.finish();
zipEntrySource.close();

代码示例来源:origin: org.apache.poi/poi-ooxml

zos.finish();
} catch (OpenXML4JRuntimeException e) {

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

outputStream.finish();
outputStream.close();

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Closes this output stream and releases any system resources
 * associated with the stream.
 *
 * @throws  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();
}

代码示例来源:origin: stackoverflow.com

public static void createZip(String directoryPath, String zipPath) throws IOException {
   FileOutputStream fOut = null;
   BufferedOutputStream bOut = null;
   ZipArchiveOutputStream tOut = null;
   try {
     fOut = new FileOutputStream(new File(zipPath));
     bOut = new BufferedOutputStream(fOut);
     tOut = new ZipArchiveOutputStream(bOut);
     addFileToZip(tOut, directoryPath, "");
   } finally {
     tOut.finish();
     tOut.close();
     bOut.close();
     fOut.close();
   }
}

代码示例来源:origin: DSpace-Labs/SAFBuilder

/**
 * Creates a zip file at the specified path with the contents of the specified directory.
 * NB:
 *
 * @param directoryPath The path of the directory where the archive will be created. eg. c:/temp
 * @param zipPath The full path of the archive to create. eg. c:/temp/archive.zip
 * @throws IOException If anything goes wrong
 */
public static void createZip(String directoryPath, String zipPath) throws IOException {
  FileOutputStream fOut = null;
  BufferedOutputStream bOut = null;
  ZipArchiveOutputStream tOut = null;
  try {
    fOut = new FileOutputStream(new File(zipPath));
    bOut = new BufferedOutputStream(fOut);
    tOut = new ZipArchiveOutputStream(bOut);
    addFileToZip(tOut, directoryPath, "");
  } finally {
    tOut.finish();
    tOut.close();
    bOut.close();
    fOut.close();
  }
}

代码示例来源:origin: org.sakaiproject.common/archive-impl2

FileUtils.writeStringToFile(new File(hashPath), hash);
} finally {
  zOut.finish();
  zOut.close();
  bOut.close();

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

zipArchiveOutputStream.finish();
} catch (Exception e) {
  throw new RuntimeException(e);

代码示例来源: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: stackoverflow.com

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import java.util.Arrays;

public class Test {

public static void main(String[] args) throws Exception {
   ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(System.out);
   byte[] data = new byte[1024*1024];
   for(byte i=49; i<120; i++) {
     Arrays.fill(data, i);
     ArchiveEntry file1 = new ZipArchiveEntry("file" + i + ".txt");
     zipOut.putArchiveEntry(file1);
     zipOut.write(data);
     zipOut.closeArchiveEntry();
    }
    zipOut.finish();
    zipOut.close();
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

zos.finish();
zipEntrySource.close();

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

zos.finish();
} catch (OpenXML4JRuntimeException e) {

代码示例来源:origin: core-lib/xjar

@Override
public void decrypt(XKey key, InputStream in, OutputStream out) throws IOException {
  ZipArchiveInputStream zis = null;
  ZipArchiveOutputStream zos = null;
  try {
    zis = new ZipArchiveInputStream(in);
    zos = new ZipArchiveOutputStream(out);
    zos.setLevel(level);
    XUnclosedOutputStream nos = new XUnclosedOutputStream(zos);
    ZipArchiveEntry entry;
    while ((entry = zis.getNextZipEntry()) != null) {
      if (entry.isDirectory()) {
        continue;
      }
      zos.putArchiveEntry(new ZipArchiveEntry(entry.getName()));
      XDecryptor decryptor = filtrate(entry) ? this : xNopDecryptor;
      try (OutputStream eos = decryptor.decrypt(key, nos)) {
        XKit.transfer(zis, eos);
      }
      zos.closeArchiveEntry();
    }
    zos.finish();
  } finally {
    XKit.close(zis);
    XKit.close(zos);
  }
}

代码示例来源:origin: core-lib/xjar

@Override
  public void encrypt(XKey key, InputStream in, OutputStream out) throws IOException {
    ZipArchiveInputStream zis = null;
    ZipArchiveOutputStream zos = null;
    try {
      zis = new ZipArchiveInputStream(in);
      zos = new ZipArchiveOutputStream(out);
      zos.setLevel(level);
      XUnclosedOutputStream nos = new XUnclosedOutputStream(zos);
      ZipArchiveEntry entry;
      while ((entry = zis.getNextZipEntry()) != null) {
        if (entry.isDirectory()) {
          continue;
        }
        zos.putArchiveEntry(new ZipArchiveEntry(entry.getName()));
        XEncryptor encryptor = filtrate(entry) ? this : xNopEncryptor;
        try (OutputStream eos = encryptor.encrypt(key, nos)) {
          XKit.transfer(zis, eos);
        }
        zos.closeArchiveEntry();
      }
      zos.finish();
    } finally {
      XKit.close(zis);
      XKit.close(zos);
    }
  }
}

相关文章

ZipArchiveOutputStream类方法