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

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

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

ZipFile.getEntries介绍

[英]Returns all entries.

Entries will be returned in the same order they appear within the archive's central directory.
[中]返回所有条目。
条目将按照它们在存档中心目录中出现的顺序返回。

代码示例

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

/**
 * Note: the file sizes are rounded up to the next cipher block size,
 * so don't rely on file sizes of these custom encrypted zip file entries!
 */
@Override
public Enumeration<? extends ZipArchiveEntry> getEntries() {
  return zipFile.getEntries();
}

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

@Override
public Enumeration<? extends ZipArchiveEntry> getEntries() {
 if (zipArchive == null)
   throw new IllegalStateException("Zip File is closed");
 
 return zipArchive.getEntries();
}

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

/**
 * Expands {@code archive} into {@code targetDirectory}.
 *
 * @param archive the file to expand
 * @param targetDirectory the directory to write to
 * @throws IOException if an I/O error occurs
 * @throws ArchiveException if the archive cannot be read for other reasons
 */
public void expand(final ZipFile archive, File targetDirectory)
  throws IOException, ArchiveException {
  final Enumeration<ZipArchiveEntry> entries = archive.getEntries();
  expand(new ArchiveEntrySupplier() {
    @Override
    public ArchiveEntry getNextReadableEntry() throws IOException {
      ZipArchiveEntry next = entries.hasMoreElements() ? entries.nextElement() : null;
      while (next != null && !archive.canReadEntryData(next)) {
        next = entries.hasMoreElements() ? entries.nextElement() : null;
      }
      return next;
    }
  }, new EntryWriter() {
    @Override
    public void writeEntryDataTo(ArchiveEntry entry, OutputStream out) throws IOException {
      try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) {
        IOUtils.copy(in, out);
      }
    }
  }, targetDirectory);
}

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

@Override
  public ZipArchiveEntry getEntry(final String path) {
   String normalizedPath = path.replace('\\', '/');

   final ZipArchiveEntry entry = zipArchive.getEntry(normalizedPath);
   if (entry != null) {
     return entry;
   }

   // the opc spec allows case-insensitive filename matching (see #49609)
   for (final ZipArchiveEntry ze : asIterable(asIterator(zipArchive.getEntries()))) {
     if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\','/'))) {
      return ze;
     }
   }

   return null;
  }
}

代码示例来源:origin: jeremylong/DependencyCheck

if (zip.getEntry("META-INF/MANIFEST.MF") != null
    || zip.getEntry("META-INF/maven") != null) {
  final Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    final ZipArchiveEntry entry = entries.nextElement();

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

Enumeration entries = zf.getEntries();
while (entries.hasMoreElements()) {
  ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();

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

public static MediaType detect(ZipFile zipFile) {
  MediaType type = null;
  Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
   ZipEntry entry = entries.nextElement();
   type = IWork13DocumentType.detectIfPossible(entry);
   if (type != null) return type;
  }
    // If we get here, we don't know what it is
  return UNKNOWN13.getType();
}

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

@SuppressWarnings("unchecked")
private static MediaType detectIpa(ZipFile zip) {
  // Note - consider generalising this logic, if another format needs many regexp matching
  Set<Pattern> tmpPatterns = (Set<Pattern>)ipaEntryPatterns.clone();
  
  Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = entries.nextElement();
    String name = entry.getName();
    
    Iterator<Pattern> ip = tmpPatterns.iterator();
    while (ip.hasNext()) {
      if (ip.next().matcher(name).matches()) {
        ip.remove();
      }
    }
    if (tmpPatterns.isEmpty()) {
      // We've found everything we need to find
      return MediaType.application("x-itunes-ipa");
    }
  }
  
  // If we get here, not all required entries were found
  return null;
}

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

private static MediaType detectKmz(ZipFile zip) {
  boolean kmlFound = false;
  Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = entries.nextElement();
    String name = entry.getName();
    if (!entry.isDirectory()
        && name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
      if (name.endsWith(".kml") && !kmlFound) {
        kmlFound = true;
      } else {
        return null;
      }
    }
  }
  if (kmlFound) {
    return MediaType.application("vnd.google-earth.kmz");
  } else {
    return null;
  }
}

代码示例来源:origin: org.codehaus.plexus/plexus-archiver

Enumeration<ZipArchiveEntry> entries = zf.getEntries();
HashSet<String> dirSet = new HashSet<String>();
while ( entries.hasMoreElements() )

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

protected Map<String, String> readZipArchive(InputStream inputStream) throws IOException {
  Map<String, String> data = new HashMap<String, String>();
  Path tempFile = writeTemporaryArchiveFile(inputStream, "zip");
  ZipFile zip = new ZipFile(tempFile.toFile());
  Enumeration<ZipArchiveEntry> entries = zip.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = entries.nextElement();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copy(zip.getInputStream(entry), bos);
    data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray()));
  }
  zip.close();
  Files.delete(tempFile);
  return data;
}

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

Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
  ZipEntry entry = entries.nextElement();

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

/**
 * Note: the file sizes are rounded up to the next cipher block size,
 * so don't rely on file sizes of these custom encrypted zip file entries!
 */
@Override
public Enumeration<? extends ZipArchiveEntry> getEntries() {
  return zipFile.getEntries();
}

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

@Override
public Enumeration<? extends ZipArchiveEntry> getEntries() {
 if (zipArchive == null)
   throw new IllegalStateException("Zip File is closed");
 
 return zipArchive.getEntries();
}

代码示例来源:origin: com.atlassian.jira/jira-core

private static boolean zipFileHasExactlyOneEntry(ZipFile file)
{
  Enumeration<ZipArchiveEntry> entries = file.getEntries();
  if (entries.hasMoreElements())
  {
    entries.nextElement();
    return !entries.hasMoreElements();
  }
  else
  {
    return false;
  }
}

代码示例来源:origin: edu.jhu.hlt/acute

/**
 * Wrap a {@link Path} object. 
 * 
 * @throws IOException if there are issues with the underlying archive
 */
public ZipArchiveEntryByteIterator(Path p) throws IOException {
 this.zf = new ZipFile(p.toFile());
 this.iter = this.zf.getEntries();
}

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

public ZipReader open() throws IOException {
  LOGGER.info("Reading zip file: {}", file);
  zipFile = new ZipFile(file);
  entries = zipFile.getEntries();
  return this;
}

代码示例来源:origin: com.comcast.pantry/pantry

public String getContents() throws IOException {
  ZipFile zipFile = new ZipFile(this);
  StringBuffer sb = new StringBuffer();
  /* Get all elements */
  Enumeration entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();
    sb.append(entry.getName());
    sb.append('\n');
  }
  return sb.toString();
}

代码示例来源:origin: com.comcast.pantry/pantry

public void printContents(PrintStream ps) throws IOException {
  ZipFile zipFile = new ZipFile(this);
  /* First create all directories */
  Enumeration entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();
    ps.println(entry.getName());
  }
}

代码示例来源:origin: org.apache.tika/tika-parsers

public static MediaType detect(ZipFile zipFile) {
  MediaType type = null;
  Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
   ZipEntry entry = entries.nextElement();
   type = IWork13DocumentType.detectIfPossible(entry);
   if (type != null) return type;
  }
    // If we get here, we don't know what it is
  return UNKNOWN13.getType();
}

相关文章