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

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

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

ZipArchiveOutputStream.putArchiveEntry介绍

暂无

代码示例

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

/**
 * {@inheritDoc}
 * @throws ClassCastException if entry is not an instance of ZipArchiveEntry
 * @throws Zip64RequiredException if the entry's uncompressed or
 * compressed size is known to exceed 4 GByte and {@link #setUseZip64}
 * is {@link Zip64Mode#Never}.
 */
@Override
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws IOException {
  putArchiveEntry(archiveEntry, false);
}

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

@Override
  public void putArchiveEntry(final ArchiveEntry ze) throws IOException {
    if (!jarMarkerAdded) {
      ((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance());
      jarMarkerAdded = true;
    }
    super.putArchiveEntry(ze);
  }
}

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

public void saveXmlPart(XmlPart part) throws Docx4JException {
  String targetName = part.getPartName().getName().substring(1);
  try {
    // Add ZIP entry to output stream.
    zos.putArchiveEntry(new ZipArchiveEntry(targetName));
    Document doc =  part.getDocument();
    /*
     * With Crimson, this gives:
     *
      Exception in thread "main" java.lang.AbstractMethodError: org.apache.crimson.tree.XmlDocument.getXmlStandalone()Z
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
        at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:662)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
        at org.docx4j.model.datastorage.CustomXmlDataStorageImpl.writeDocument(CustomXmlDataStorageImpl.java:174)
     *
     */
    DOMSource source = new DOMSource(doc);
     XmlUtils.getTransformerFactory().newTransformer().transform(source,
         new StreamResult(zos) );
    // Complete the entry
    zos.closeArchiveEntry();
  } catch (Exception e) {
    throw new Docx4JException("Error marshalling XmlPart " + part.getPartName(), e);
  }
}

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

public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException {
  String targetName = part.getPartName().getName().substring(1);
  try {
    // Add ZIP entry to output stream.
    zos.putArchiveEntry(new ZipArchiveEntry(targetName));
    part.getData().writeDocument( zos );
    // Complete the entry
    zos.closeArchiveEntry();
  } catch (Exception e) {
    throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e);
  }
}

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

@Override
  public boolean marshall(PackagePart part, OutputStream out)
      throws OpenXML4JException {
    if (!(out instanceof ZipArchiveOutputStream)) {
      throw new IllegalArgumentException("ZipOutputStream expected!");
    }
    ZipArchiveOutputStream zos = (ZipArchiveOutputStream) out;

    // Saving the part in the zip file
    ZipArchiveEntry ctEntry = new ZipArchiveEntry(ZipHelper
        .getZipItemNameFromOPCName(part.getPartName().getURI()
            .toString()));
    try {
      // Save in ZIP
      zos.putArchiveEntry(ctEntry); // Add entry in ZIP
      try {
        super.marshall(part, out); // Marshall the properties inside a XML
        // Document
        return StreamHelper.saveXmlInStream(xmlDoc, out);
      } finally {
        zos.closeArchiveEntry();
      }
    } catch (IOException e) {
      throw new OpenXML4JException(e.getLocalizedMessage(), e);
    }
  }
}

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

relPartName.getURI().toASCIIString()).getPath());
try {
  zos.putArchiveEntry(ctEntry);
  try {
    return StreamHelper.saveXmlInStream(xmlOutDoc, zos);

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

ze.setCrc(crc.getValue());
  zos.putArchiveEntry(ze);				
} else {
  zos.putArchiveEntry(new ZipArchiveEntry(resolvedPartUri));

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

zos.putArchiveEntry(new ZipArchiveEntry(targetName));

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

zeNew.setTime(ze.getTime());
zos.putArchiveEntry(zeNew);
FilterOutputStream fos2 = new FilterOutputStream(zos) {

代码示例来源: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: org.apache.poi/poi-ooxml

try {
  zos.putArchiveEntry(partEntry);

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

zeOut.setSize(ze.getSize());
zeOut.setTime(ze.getTime());
zos.putArchiveEntry(zeOut);
try (final InputStream is = zipEntrySource.getInputStream(ze)) {
  if (is instanceof ZipArchiveThresholdInputStream) {

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

private static void zipStoreBuffer(ZipArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException {
  ZipEntry zipEntry = new ZipEntry(name != null ? name : UUID.randomUUID().toString());
  zipEntry.setMethod(ZipOutputStream.STORED);
  zipEntry.setSize(dataBuffer.length);
  CRC32 crc32 = new CRC32();
  crc32.update(dataBuffer);
  zipEntry.setCrc(crc32.getValue());
  try {
    zip.putArchiveEntry(new ZipArchiveEntry(zipEntry));
  } catch (ZipException ex) {
    if (name != null) {
      zipStoreBuffer(zip, "x-" + name, dataBuffer);
      return;
    }
  }
  zip.write(dataBuffer);
  zip.closeArchiveEntry();
}

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

zos.putArchiveEntry(ze);
try {
  fis = new FileInputStream(f);

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

try {
  if (!zae.isDirectory() && zipArchiveInputStream.canReadEntryData(zae)) {
    outputStream.putArchiveEntry(zae);

代码示例来源: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: 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: org.docx4j/docx4j

public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException {
  String targetName = part.getPartName().getName().substring(1);
  try {
    // Add ZIP entry to output stream.
    zos.putArchiveEntry(new ZipArchiveEntry(targetName));
    part.getData().writeDocument( zos );
    // Complete the entry
    zos.closeArchiveEntry();
  } catch (Exception e) {
    throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e);
  }
}

相关文章

ZipArchiveOutputStream类方法