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

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

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

ZipFile.getEntry介绍

[英]Returns a named entry - or null if no entry by that name exists.

If multiple entries with the same name exist the first entry in the archive's central directory by that name is returned.
[中]返回一个命名条目——如果不存在同名条目,则返回null。
如果存在多个同名条目,则会返回存档中心目录中同名的第一个条目。

代码示例

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

@Override
public ZipArchiveEntry getEntry(String path) {
  return zipFile.getEntry(path);
}

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

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

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

private static MediaType detectIWork13(ZipFile zip) {
  if (zip.getEntry(IWork13PackageParser.IWORK13_COMMON_ENTRY) != null) {
    return IWork13PackageParser.IWork13DocumentType.detect(zip);
  }
  return null;
}

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

private static MediaType detectJar(ZipFile zip) {
  if (zip.getEntry("META-INF/MANIFEST.MF") != null) {
   // It's a Jar file, or something based on Jar
   
   // Is it an Android APK?
   if (zip.getEntry("AndroidManifest.xml") != null) {
     return MediaType.application("vnd.android.package-archive");
   }
   
   // Check for WAR and EAR
   if (zip.getEntry("WEB-INF/") != null) {
     return MediaType.application("x-tika-java-web-archive");
   }
   if (zip.getEntry("META-INF/application.xml") != null) {
     return MediaType.application("x-tika-java-enterprise-archive");
   }
   
   // Looks like a regular Jar Archive
   return MediaType.application("java-archive");
  } else {
   // Some Android APKs miss the default Manifest
   if (zip.getEntry("AndroidManifest.xml") != null) {
     return MediaType.application("vnd.android.package-archive");
   }
   
   return null;
  }
}

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

private static MediaType detectIWork(ZipFile zip) {
  if (zip.getEntry(IWorkPackageParser.IWORK_COMMON_ENTRY) != null) {
    // Locate the appropriate index file entry, and reads from that
    // the root element of the document. That is used to the identify
    // the correct type of the keynote container.
    for (String entryName : IWorkPackageParser.IWORK_CONTENT_ENTRIES) {
      IWORKDocumentType type = IWORKDocumentType.detectType(zip.getEntry(entryName), zip); 
      if (type != null) {
       return type.getType();
      }
    }
    
    // Not sure, fallback to the container type
    return MediaType.application("vnd.apple.iwork");
  } else {
    return null;
  }
}

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

/**
 * OpenDocument files, along with EPub files and ASiC ones, have a 
 *  mimetype entry in the root of their Zip file. This entry contains
 *  the mimetype of the overall file, stored as a single string.  
 */
private static MediaType detectOpenDocument(ZipFile zip) {
  try {
    ZipArchiveEntry mimetype = zip.getEntry("mimetype");
    if (mimetype != null) {
      try (InputStream stream = zip.getInputStream(mimetype)) {
        return MediaType.parse(IOUtils.toString(stream, UTF_8));
      }
    } else {
      return null;
    }
  } catch (IOException e) {
    return null;
  }
}

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

protected String readArchiveText(InputStream inputStream) throws IOException {
  Path tempFile = writeTemporaryArchiveFile(inputStream, "zip");
  ZipFile zip = new ZipFile(tempFile.toFile());
  zip.getEntry(UnpackerResource.TEXT_FILENAME);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos);
  zip.close();
  Files.delete(tempFile);
  return bos.toString(UTF_8.name());
}

代码示例来源:origin: org.apache.wookie/wookie-parser

/**
 * Checks for the existence of the Manifest.
 * TODO not sure if this properly handles case-sensitive entries?
 * @param zipfile
 * @return true if the zip file has a manifest
 */
public static boolean hasManifest(ZipFile zipfile){
  return zipfile.getEntry(IW3CXMLConfiguration.MANIFEST_FILE)!=null;
}

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

@Override
public ZipArchiveEntry getEntry(String path) {
  return zipFile.getEntry(path);
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

public static MediaType detect(ZipFile zipFile) {
    ZipArchiveEntry entry = zipFile.getEntry("Index/MasterSlide.iwa");
    if (zipFile.getEntry("Index/MasterSlide.iwa") != null ||
        zipFile.getEntry("Index/Slide.iwa") != null) {
      return KEYNOTE13.getType();
    }
    //TODO: figure out how to distinguish numbers from pages
    return UNKNOWN13.getType();
  }
}

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

private static MediaType detectIWork13(ZipFile zip) {
  if (zip.getEntry(IWork13PackageParser.IWORK13_COMMON_ENTRY) != null) {
    return IWork13PackageParser.IWork13DocumentType.detect(zip);
  }
  return null;
}

代码示例来源:origin: org.apache.wookie/wookie-parser

/**
 * Retrieves the Manifest entry as a String
 * @param zipFile the zip file from which to extract the manifest
 * @return a String representing the manifest contents
 * @throws IOException
 */
public static String extractManifest(ZipFile zipFile) throws IOException{
  ZipArchiveEntry entry = zipFile.getEntry(IW3CXMLConfiguration.MANIFEST_FILE);
  return IOUtils.toString(zipFile.getInputStream(entry), "UTF-8");
}

代码示例来源:origin: unchartedsoftware/aperture-tiles

@Override
  protected InputStream getSourceMetaDataStream (String basePath) throws IOException {
    String location = basePath+"/"+PyramidIO.METADATA_FILENAME;
    ZipArchiveEntry entry = _tileSetArchive.getEntry(location);
    return _tileSetArchive.getInputStream(entry);
  }
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

private static MediaType detectIWork13(ZipFile zip) {
  if (zip.getEntry(IWork13PackageParser.IWORK13_COMMON_ENTRY) != null) {
    return IWork13PackageParser.IWork13DocumentType.detect(zip);
  }
  return null;
}

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

@Override
  public InputStream asStream(ArchiveEntry entry) throws IOException {
    return zFile.getInputStream(zFile.getEntry(entry.getName()));
  }
}

代码示例来源:origin: flapdoodle-oss/de.flapdoodle.embed.process

@Override
  public InputStream asStream(ArchiveEntry entry) throws IOException {
    return zFile.getInputStream(zFile.getEntry(entry.getName()));
  }
}

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

@Override
public boolean canReadEntryData(ArchiveEntry entry) {
  return zFile.canReadEntryData(zFile.getEntry(entry.getName()));
}

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

/**
 * @param reference the reference of the page
 * @return an input stream to the page XML
 * @throws IOException when failing to open a stream to the page XML
 */
public InputStream getInputStream(LocalDocumentReference reference) throws IOException
{
  XarEntry entry = this.xarPackage.getEntry(reference);
  if (entry == null) {
    throw new IOException("Failed to find entry for referenc [" + reference + "]");
  }
  return this.zipFile.getInputStream(this.zipFile.getEntry(entry.getEntryName()));
}

代码示例来源:origin: unchartedsoftware/aperture-tiles

@Override
protected InputStream getSourceTileStream (String basePath, TileIndex tile) throws IOException {
  String tileLocation = String.format("%s/"+PyramidIO.TILES_FOLDERNAME+"/%d/%d/%d." + _tileExtension, basePath, tile.getLevel(), tile.getX(), tile.getY());
  ZipArchiveEntry entry = _tileSetArchive.getEntry(tileLocation);
  return _tileSetArchive.getInputStream(entry);
}

相关文章