gpt4 book ai didi

org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 20:10:40 25 4
gpt4 key购买 nike

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

ZipArchiveOutputStream介绍

[英]Reimplementation of java.util.zip.ZipOutputStream that does handle the extended functionality of this package, especially internal/external file attributes and extra fields with different layouts for local file data and central directory entries.

This class will try to use java.nio.channels.SeekableByteChannel when it knows that the output is going to go to a file.

If SeekableByteChannel cannot be used, this implementation will use a Data Descriptor to store size and CRC information for #DEFLATED entries, this means, you don't need to calculate them yourself. Unfortunately this is not possible for the #STORED method, here setting the CRC and uncompressed size information is required before #putArchiveEntry(ArchiveEntry) can be called.

As of Apache Commons Compress 1.3 it transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more than 65536 entries in most cases but explicit control is provided via #setUseZip64. If the stream can not use SeekableByteChannel and you try to write a ZipArchiveEntry of unknown size then Zip64 extensions will be disabled by default.
[中]java的重新实现。util。拉链ZipOutputStream,它可以处理这个包的扩展功能,尤其是内部/外部文件属性,以及本地文件数据和中心目录条目的不同布局的额外字段。
这个类将尝试使用java。尼奥。频道。seekablebytechnel,当它知道输出将进入文件时。
如果SeekableByteChannel无法使用,此实现将使用数据描述符存储#DEFLATED条目的大小和CRC信息,这意味着,您不需要自己计算它们。不幸的是,对于#存储方法,这是不可能的,在调用#putArchiveEntry(ArchiveEntry)之前,需要设置CRC和未压缩的大小信息。
从Apache Commons Compress 1.3开始,它透明地支持Zip64扩展,因此单个条目和归档大于4 GB,或者在大多数情况下超过65536个条目,但通过#setUseZip64提供显式控制。如果流无法使用SeekableByteChannel,并且您尝试写入大小未知的ZipArchiveEntry,则默认情况下将禁用Zip64扩展。

代码示例

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

ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos);
  ZipArchiveEntry zeNew = new ZipArchiveEntry(ze.getName());
  zeNew.setComment(ze.getComment());
  zeNew.setExtra(ze.getExtra());
  zeNew.setTime(ze.getTime());
  zos.putArchiveEntry(zeNew);
  FilterOutputStream fos2 = new FilterOutputStream(zos) {
  cos.close();
  fos2.close();
  zos.closeArchiveEntry();
zos.close();
fos.close();
zis.close();

代码示例来源:origin: plutext/docx4j

zos.putArchiveEntry(new ZipArchiveEntry(targetName));
        part.getPartName().getName().substring(1) );
    if (bytes == null) throw new IOException("part '" + part.getPartName() + "' not found");
    zos.write( bytes.getBytes() );
      zos.write(bytes, 0, read);
zos.closeArchiveEntry();

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

ZipArchiveOutputStream ostream = ...; // Your initialization code here
ostream.setEncoding("Cp437"); // This should handle your "special" characters
ostream.setFallbackToUTF8(true); // For "unknown" characters!
ostream.setUseLanguageEncodingFlag(true);                               
ostream.setCreateUnicodeExtraFields(
  ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);

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

/**
 * Adds an archive entry with a raw input stream.
 *
 * If crc, size and compressed size are supplied on the entry, these values will be used as-is.
 * Zip64 status is re-established based on the settings in this stream, and the supplied value
 * is ignored.
 *
 * The entry is put and closed immediately.
 *
 * @param entry The archive entry to add
 * @param rawStream The raw input stream of a different entry. May be compressed/encrypted.
 * @throws IOException If copying fails
 */
public void addRawArchiveEntry(final ZipArchiveEntry entry, final InputStream rawStream)
    throws IOException {
  final ZipArchiveEntry ae = new ZipArchiveEntry(entry);
  if (hasZip64Extra(ae)) {
    // Will be re-added as required. this may make the file generated with this method
    // somewhat smaller than standard mode,
    // since standard mode is unable to remove the zip 64 header.
    ae.removeExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
  }
  final boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN
      && ae.getSize() != ArchiveEntry.SIZE_UNKNOWN
      && ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN;
  putArchiveEntry(ae, is2PhaseSource);
  copyFromZipInputStream(rawStream);
  closeCopiedEntry(is2PhaseSource);
}

代码示例来源:origin: plutext/docx4j

public void saveContentTypes(ContentTypeManager ctm) throws Docx4JException {
  try {
    zos.putArchiveEntry(new ZipArchiveEntry("[Content_Types].xml"));
    ctm.marshal(zos);
    zos.closeArchiveEntry();
  } catch (Exception e) {
    throw new Docx4JException("Error marshalling Content_Types ", e);
  }
}

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

@SuppressWarnings("resource")
  @Override
  public boolean saveImpl(Document content, OutputStream out) {
    final ZipArchiveOutputStream zos = (out instanceof ZipArchiveOutputStream)
        ? (ZipArchiveOutputStream) out : new ZipArchiveOutputStream(out);

    ZipArchiveEntry partEntry = new ZipArchiveEntry(CONTENT_TYPES_PART_NAME);
    try {
      // Referenced in ZIP
      zos.putArchiveEntry(partEntry);
      try {
        // Saving data in the ZIP file
        return StreamHelper.saveXmlInStream(content, zos);
      } finally {
        zos.closeArchiveEntry();
      }
    } catch (IOException ioe) {
      logger.log(POILogger.ERROR, "Cannot write: " + CONTENT_TYPES_PART_NAME
          + " in Zip !", ioe);
      return false;
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
  if (!logFile.exists()) {
    throw new FileNotFoundException();
  }
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
  zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
  zipOutputStream.setEncoding(ZIP_ENCODING);
  byte[] content = getTailBytes(logFile);
  ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
  zipOutputStream.putArchiveEntry(archiveEntry);
  zipOutputStream.write(content);
  zipOutputStream.closeArchiveEntry();
  zipOutputStream.close();
}

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

protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
  ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out);
  try {
    Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
    while (en.hasMoreElements()) {
      ZipArchiveEntry ze = en.nextElement();
      ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
      zeOut.setSize(ze.getSize());
      zeOut.setTime(ze.getTime());
      zos.putArchiveEntry(zeOut);
      try (final InputStream is = zipEntrySource.getInputStream(ze)) {
        if (is instanceof ZipArchiveThresholdInputStream) {
        zos.closeArchiveEntry();
    zos.finish();
    zipEntrySource.close();

代码示例来源:origin: plutext/docx4j

ZipArchiveEntry ze = new ZipArchiveEntry(resolvedPartUri);
  ze.setMethod(ZipArchiveOutputStream.STORED);
  ze.setSize(bytes.length);
  ze.setCompressedSize(bytes.length);
  ze.setCrc(crc.getValue());
  zos.putArchiveEntry(ze);				
} else {
  zos.putArchiveEntry(new ZipArchiveEntry(resolvedPartUri));
zos.write( bytes );
zos.closeArchiveEntry();

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

byte[] zip(byte[] data, String filename) {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos);
   ZipArchiveEntry entry = new ZipArchiveEntry(filename);
   entry.setSize(data.length);
   zos.putArchiveEntry(entry);
   zos.write(data);
   zos.closeArchiveEntry();
   zos.close();
   bos.close();
   return bos.toByteArray();       
 }

代码示例来源:origin: naver/ngrinder

ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setEncoding(charsetName);
FileInputStream fis = null;
    ze = new ZipArchiveEntry(name);
    zos.putArchiveEntry(ze);
    try {
      fis = new FileInputStream(f);
      while ((length = fis.read(buf, 0, buf.length)) >= 0) {
        zos.write(buf, 0, length);
    zos.closeArchiveEntry();
zos.close();

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

import java.io.*;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
public class ZipFiles {  
  public static void main(String[] args) throws Exception{
    ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(new FileOutputStream("测试.zip"));
    zipOut.setEncoding("Cp437"); // This should handle your "special" characters
    zipOut.setFallbackToUTF8(true); // For "unknown" characters!
    zipOut.setUseLanguageEncodingFlag(true);                               
    zipOut.setCreateUnicodeExtraFields(
    ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
    zipOut.putArchiveEntry(new ZipArchiveEntry("测试.xml"));
    zipOut.putArchiveEntry(new ZipArchiveEntry("test.xml"));
    zipOut.closeArchiveEntry();
    zipOut.flush();
    zipOut.close();
  }
}

代码示例来源: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: apache/tika

private static void repairCopy(File brokenZip, File fixedZip) {
  try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(fixedZip)) {
    try (InputStream is = new FileInputStream(brokenZip)) {
      ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is);
      while (zae != null) {
        try {
          if (!zae.isDirectory() && zipArchiveInputStream.canReadEntryData(zae)) {
            outputStream.putArchiveEntry(zae);
            outputStream.flush();
            outputStream.closeArchiveEntry();
            if (!successfullyCopied) {
              break;
      outputStream.flush();
      outputStream.finish();
      outputStream.close();

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

try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(targetFile)) {
  zip.setLevel(9);
  appendRecursively(sourceDirectory, artifactBase, zip);
    ZipArchiveEntry entry = new ZipArchiveEntry(artifactBase + '/' + LIB_DIRECTORY + '/' + file.getName());
    zip.putArchiveEntry(entry);
    appendJAR(file, zip, nativeFiles);
    zip.closeArchiveEntry();
    ZipArchiveEntry entry = new ZipArchiveEntry(artifactBase + '/' + LIB_DIRECTORY + '/' + nf.getKey());
    entry.setUnixMode(0555);        // Readable and executable for all, but not writable.
    zip.putArchiveEntry(entry);
    zip.write(nf.getValue());
    zip.closeArchiveEntry();
    nf.setValue(null);

代码示例来源:origin: plutext/docx4j

/**
 * @param zipOutputStream the zipOutputStream to set
 */
public void setOutputStream(OutputStream os) {
  this.zos = new ZipArchiveOutputStream(os);
}

代码示例来源:origin: USPTO/PatentPublicData

@Override
public void open() throws IOException {
  outputZip = new ZipArchiveOutputStream(filePath.toFile());
  outputZip.setEncoding("UTF-8");
  outputZip.setLevel(9);
  ZipArchiveEntry zipEntry = new ZipArchiveEntry("corpus.xml");
  outputZip.putArchiveEntry(zipEntry);
}

代码示例来源:origin: Zlika/reproducible-build-maven-plugin

final ZipArchiveOutputStream zout = new ZipArchiveOutputStream(out))
   stripper.strip(tmp, tmp2);
   final byte[] fileContent = Files.readAllBytes(tmp2.toPath());
   strippedEntry.setSize(fileContent.length);
   zout.putArchiveEntry(strippedEntry);
   zout.write(fileContent);
   zout.closeArchiveEntry();
   zout.addRawArchiveEntry(strippedEntry, zip.getRawInputStream(entry));

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

// Obtain reference to file
 HttpGet httpGet = new HttpGet("http://blahblablah.com/file.txt");
 HttpResponse httpResponse = httpclient.execute(httpGet);
 HttpEntity httpEntity = httpResponse.getEntity();
 // Create the output ZIP file
 ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile);
 try {
   // Write a file header in the .zip file
   ArchiveEntry entry = new ZipArchiveEntry("file.txt");
   zip.putArchiveEntry(entry);
   // Download the file and write it to a compressed file
   IOUtils.copy(httpEntity.getContent(), zip);
   // The file is now written
   zip.closeArchiveEntry();
 } finally {
   // Ensure output file is closed
   zip.close();
 }

代码示例来源:origin: org.openengsb.connector/org.openengsb.connector.git

@Override
public File export() {
  try {
    if (repository == null) {
      initRepository();
    }
    LOGGER.debug("Exporting repository to archive");
    File tmp = File.createTempFile("repository", ".zip");
    ZipArchiveOutputStream zos = new ZipArchiveOutputStream(tmp);
    packRepository(localWorkspace, zos);
    zos.close();
    return tmp;
  } catch (IOException e) {
    throw new ScmException(e);
  }
}

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