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

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

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

ZipArchiveInputStream.close介绍

[英]Closes the current ZIP archive entry and positions the underlying stream to the beginning of the next entry. All per-entry variables and data structures are cleared.

If the compressed size of this entry is included in the entry header, then any outstanding bytes are simply skipped from the underlying stream without uncompressing them. This allows an entry to be safely closed even if the compression method is unsupported.

In case we don't know the compressed size of this entry or have already buffered too much data from the underlying stream to support uncompression, then the uncompression process is completed and the end position of the stream is adjusted based on the result of that process.
[中]关闭当前ZIP存档项,并将基础流定位到下一个项的开头。清除所有每个条目的变量和数据结构。
如果该条目的压缩大小包含在条目头中,则只需从底层流中跳过任何未完成的字节,而无需解压缩它们。这样,即使不支持压缩方法,也可以安全地关闭条目。
如果我们不知道这个条目的压缩大小,或者已经从底层流中缓冲了太多数据以支持解压缩,那么解压缩过程就完成了,并根据该过程的结果调整流的结束位置。

代码示例

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

public ZipPartStore(InputStream is) throws Docx4JException {
  initMaxBytes();
  
  partByteArrays = new HashMap<String, ByteArray>();
  try {
    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
    ArchiveEntry entry = null;
    while ((entry = zis.getNextEntry()) != null) {
      // How to read the data descriptor for length? ie before reading?
      byte[] bytes =  getBytesFromInputStream( zis );
      //log.debug("Extracting " + entry.getName());
      policePartSize(null, bytes.length, entry.getName()); 
      partByteArrays.put(entry.getName(), new ByteArray(bytes) );
    }
    zis.close();
  } catch (PartTooLargeException e) {
    throw e;
  } catch (Exception e) {
    throw new Docx4JException("Error processing zip file (is it a zip file?)", e);
  }
}

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

zis.close();

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

ZipFile zipFile = new ZipFile("C:\\test.zip");
     byte[] buf = new byte[65536];
     Enumeration<?> entries = zipFile.getEntries();
     while (entries.hasMoreElements()) {
       ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement();
       int n;
       InputStream is = zipFile.getInputStream(zipArchiveEntry);
       ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
       if (zis.canReadEntryData(zipArchiveEntry)) {
         while ((n = is.read(buf)) != -1) {
           if (n > 0) {
             System.out.println(new String(buf));
           }
         }
       }
       zis.close();
     }

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

ZipArchiveInputStream zip =
  new ZipArchiveInputStream(inputStream);
try {
  ZipArchiveEntry entry = zip.getNextZipEntry();
  while(entry != null) {
    assertEquals("README", entry.getName());
    ...
    entry = zip.getNextZipEntry();
  }
} finally {
  zip.close();
}

代码示例来源:origin: kriegaex/Galileo-Openbook-Cleaner

try {
  if (zipStream != null)
    zipStream.close();
} catch (IOException ignored) {}

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

try { zis.close(); } catch (Exception e) { }
try { fis.close(); } catch (Exception e) { }
try { if (fos!=null) fos.close(); } catch (Exception e) { }

代码示例来源:origin: com.googlecode.t7mp/maven-t7-common

in.close();

代码示例来源:origin: t7mp/maven-t7-plugin

in.close();

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

private List<String> getDataSetXmlList(final InputStream inputStream) throws IOException {
  List<String> xmlList = new ArrayList<String>();
  if (inputStream == null) {
    return xmlList;
  }
  ZipArchiveInputStream zipInput = new ZipArchiveInputStream(inputStream);
  ZipArchiveEntry entry = null;
  try {
    while ((entry = zipInput.getNextZipEntry()) != null) {
      if (entry.isDirectory() || !entry.getName().endsWith("xml")) {
        continue;
      }
      byte[] buffer = new byte[(int) entry.getSize()];
      IOUtils.read(zipInput, buffer);
      String xml = new String(buffer);
      xmlList.add(xml);
    }
  } finally {
    zipInput.close();
  }
  return xmlList;
}

代码示例来源:origin: de.flapdoodle.embedmongo/de.flapdoodle.embedmongo

zipIn.close();

代码示例来源:origin: michaelmosmann/embedmongo.flapdoodle.de

zipIn.close();

代码示例来源:origin: Alfresco/alfresco-repository

iWorksZip.close();

代码示例来源:origin: org.alfresco/alfresco-repository

iWorksZip.close();

代码示例来源:origin: org.docx4j/docx4j

public ZipPartStore(InputStream is) throws Docx4JException {
  initMaxBytes();
  
  partByteArrays = new HashMap<String, ByteArray>();
  try {
    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
    ArchiveEntry entry = null;
    while ((entry = zis.getNextEntry()) != null) {
      // How to read the data descriptor for length? ie before reading?
      byte[] bytes =  getBytesFromInputStream( zis );
      //log.debug("Extracting " + entry.getName());
      policePartSize(null, bytes.length, entry.getName()); 
      partByteArrays.put(entry.getName(), new ByteArray(bytes) );
    }
    zis.close();
  } catch (PartTooLargeException e) {
    throw e;
  } catch (Exception e) {
    throw new Docx4JException("Error processing zip file (is it a zip file?)", e);
  }
}

代码示例来源:origin: ZuInnoTe/hadoopoffice

zis.close();
IOUtils.closeQuietly(is);
this.zipFile=new ZipFile(this.tmpFile);

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

zis.close();

代码示例来源:origin: org.xwiki.platform/xwiki-platform-xar-model

/**
 * Find and add the entries located in the passed XAR file.
 * 
 * @param xarStream an input stream to a XAR file
 * @throws IOException when failing to read the file
 * @throws XarException when failing to parse the XAR package
 */
public void read(InputStream xarStream) throws IOException, XarException
{
  ZipArchiveInputStream zis = new ZipArchiveInputStream(xarStream, "UTF-8", false);
  try {
    for (ZipArchiveEntry entry = zis.getNextZipEntry(); entry != null; entry = zis.getNextZipEntry()) {
      if (!entry.isDirectory() && zis.canReadEntryData(entry)) {
        readEntry(zis, entry.getName());
      }
    }
  } finally {
    zis.close();
  }
}

代码示例来源:origin: Alfresco/alfresco-repository

@Override
  public Set<String> execute() throws Throwable
  {
    Set<String> entryNames = new TreeSet<String>();
    ContentReader reader = CONTENT_SERVICE.getReader(downloadNode, ContentModel.PROP_CONTENT);
    ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(reader.getContentInputStream());
    try 
    {
      ZipArchiveEntry zipEntry = zipInputStream.getNextZipEntry();
      while (zipEntry != null)
      {
        String name = zipEntry.getName();
        entryNames.add(name);
        zipEntry = zipInputStream.getNextZipEntry();
      }
    }
    finally
    {
      zipInputStream.close();
    }
    return entryNames;
  }
});

代码示例来源:origin: digital-preservation/droid

in.close();

相关文章