java.util.zip.ZipFile.getEntry()方法的使用及代码示例

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

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

ZipFile.getEntry介绍

[英]Returns the zip entry with the given name, or null if there is no such entry.
[中]返回具有给定名称的zip条目,如果没有此类条目,则返回null。

代码示例

代码示例来源:origin: libgdx/libgdx

private InputStream getFromJar (String jarFile, String sharedLibrary) throws IOException {
  ZipFile file = new ZipFile(nativesJar);
  ZipEntry entry = file.getEntry(sharedLibrary);
  return file.getInputStream(entry);
}

代码示例来源:origin: pxb1988/dex2jar

@Override
  public InputStream _newInputStream() throws IOException {
    ZipEntry e = zipFile.getEntry(path);
    return e != null ? zipFile.getInputStream(e) : null;
  }
}

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

try{
  ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0);
  ZipFile zf = new ZipFile(ai.sourceDir);
  ZipEntry ze = zf.getEntry("classes.dex");
  long time = ze.getTime();
  String s = SimpleDateFormat.getInstance().format(new java.util.Date(time));
  zf.close();
}catch(Exception e){
}

代码示例来源:origin: Tencent/tinker

public static String getZipEntryMd5(File file, String entryName) {
  ZipFile zipFile = null;
  try {
    zipFile = new ZipFile(file);
    ZipEntry entry = zipFile.getEntry(entryName);
    if (entry == null) {
      return null;
    }
    return MD5.getMD5(zipFile.getInputStream(entry), 1024 * 100);
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (zipFile != null) {
      try {
        zipFile.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  return null;
}

代码示例来源:origin: konsoletyper/teavm

private Supplier<InputStream> findSourceFileInZip(File zipFile, String fileName) {
  try (ZipFile zip = new ZipFile(zipFile)) {
    ZipEntry entry = zip.getEntry(fileName);
    if (entry == null) {
      return null;
    }
    return () -> {
      try {
        ZipInputStream input = new ZipInputStream(new FileInputStream(zipFile));
        while (true) {
          ZipEntry e = input.getNextEntry();
          if (e == null) {
            return null;
          }
          if (e.getName().equals(fileName)) {
            return input;
          }
        }
      } catch (IOException e) {
        return null;
      }
    };
  } catch (IOException e) {
    return null;
  }
}

代码示例来源:origin: ankidroid/Anki-Android

List<Object[]> media = new ArrayList<>();
  JSONObject meta = new JSONObject(Utils.convertStreamToString(z.getInputStream(z.getEntry("_meta"))));
      Utils.writeToFile(z.getInputStream(i), destPath);
      String csum = Utils.fileChecksum(destPath);
  throw new RuntimeException(e);
} finally {
  z.close();

代码示例来源:origin: com.h2database/h2

@Override
public FileChannel open(String mode) throws IOException {
  ZipFile file = openZipFile();
  ZipEntry entry = file.getEntry(getEntryName());
  if (entry == null) {
    file.close();
    throw new FileNotFoundException(name);
  }
  return new FileZip(file, entry);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static LexicalizedParser loadModelFromZip(String zipFilename,
                         String modelName) {
 LexicalizedParser parser = null;
 try {
  File file = new File(zipFilename);
  if (file.exists()) {
   ZipFile zin = new ZipFile(file);
   ZipEntry zentry = zin.getEntry(modelName);
   if (zentry != null) {
    InputStream in = zin.getInputStream(zentry);
    // gunzip it if necessary
    if (modelName.endsWith(".gz")) {
     in = new GZIPInputStream(in);
    }
    ObjectInputStream ois = new ObjectInputStream(in);
    parser = loadModel(ois);
    ois.close();
    in.close();
   }
   zin.close();
  } else {
   throw new FileNotFoundException("Could not find " + modelName +
                   " inside " + zipFilename);
  }
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
 return parser;
}

代码示例来源:origin: libgdx/libgdx

private InputStream getFromJar (String jarFile, String sharedLibrary) throws IOException {
  ZipFile file = new ZipFile(nativesJar);
  ZipEntry entry = file.getEntry(sharedLibrary);
  return file.getInputStream(entry);
}

代码示例来源:origin: Tencent/tinker

public static String getZipEntryCrc(File file, String entryName) {
  ZipFile zipFile = null;
  try {
    zipFile = new ZipFile(file);
    ZipEntry entry = zipFile.getEntry(entryName);
    if (entry == null) {
      return null;
    }
    return String.valueOf(entry.getCrc());
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (zipFile != null) {
      try {
        zipFile.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  return null;
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public InputStream openStream(String resourceName) throws IOException {
  ZipEntry zipEntry = zipFile.getEntry(resourceName);
  if (zipEntry == null) {
    return null;
  }
  return zipFile.getInputStream(zipEntry);
}

代码示例来源:origin: org.apache.ant/ant

try (ZipFile zipFile = new ZipFile(element)) {
  if (zipFile.getEntry(resourceLocation) != null) {
    return element;

代码示例来源:origin: lealone/Lealone

@Override
public long size() {
  try {
    ZipFile file = openZipFile();
    try {
      ZipEntry entry = file.getEntry(getEntryName());
      return entry == null ? 0 : entry.getSize();
    } finally {
      file.close();
    }
  } catch (IOException e) {
    return 0;
  }
}

代码示例来源:origin: javamelody/javamelody

private String getSourceFromJar(Class<?> clazz, File srcJarFile)
    throws ZipException, IOException {
  final ZipFile zipFile = new ZipFile(srcJarFile);
  try {
    final String entryName = clazz.getName().replace('.', '/') + ".java";
    ZipEntry entry = zipFile.getEntry(entryName);
    if (entry == null) {
    final InputStream inputStream = zipFile.getInputStream(entry);
    try {
      final Reader reader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
    zipFile.close();

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

ZipFile zipFile = new ZipFile("file.zip");
ZipEntry zipEntry = zipFile.getEntry("fileName.txt");       
InputStream inputStream = zipFile.getInputStream(zipEntry);

代码示例来源:origin: Tencent/tinker

private void getCompressMethodFromApk() {
  ZipFile zipFile = null;
  try {
    zipFile = new ZipFile(config.mNewApkFile);
    ArrayList<String> sets = new ArrayList<>();
    sets.addAll(modifiedSet);
    sets.addAll(addedSet);
    ZipEntry zipEntry;
    for (String name : sets) {
      zipEntry = zipFile.getEntry(name);
      if (zipEntry != null && zipEntry.getMethod() == ZipEntry.STORED) {
        storedSet.add(name);
      }
    }
  } catch (Throwable throwable) {
  } finally {
    if (zipFile != null) {
      try {
        zipFile.close();
      } catch (IOException e) {
      }
    }
  }
}

代码示例来源:origin: Tencent/tinker

private static ByteBuffer getZipEntryData(ZipFile zf, String entryPath) throws IOException {
  final ZipEntry entry = zf.getEntry(entryPath);
  InputStream is = null;
  try {
    is = new BufferedInputStream(zf.getInputStream(entry));
    final byte[] data = Utils.toByteArray(is);
    return ByteBuffer.wrap(data);
  } finally {
    if (is != null) {
      try {
        is.close();
      } catch (Throwable ignored) {
        // Ignored.
      }
    }
  }
}

代码示例来源:origin: fesh0r/fernflower

@Override
public byte[] getBytecode(String externalPath, String internalPath) throws IOException {
 File file = new File(externalPath);
 if (internalPath == null) {
  return InterpreterUtil.getBytes(file);
 }
 else {
  try (ZipFile archive = new ZipFile(file)) {
   ZipEntry entry = archive.getEntry(internalPath);
   if (entry == null) throw new IOException("Entry not found: " + internalPath);
   return InterpreterUtil.getBytes(archive, entry);
  }
 }
}

代码示例来源:origin: lealone/Lealone

@Override
public boolean exists() {
  try {
    String entryName = getEntryName();
    if (entryName.length() == 0) {
      return true;
    }
    ZipFile file = openZipFile();
    try {
      return file.getEntry(entryName) != null;
    } finally {
      file.close();
    }
  } catch (IOException e) {
    return false;
  }
}

代码示例来源:origin: Tencent/tinker

ZipFile zipFile = null;
try {
  zipFile = new ZipFile(file);
  ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
  if (entry != null) {
    InputStream inputStream = null;
    try {
      inputStream = zipFile.getInputStream(entry);
      loadFrom(inputStream, (int) entry.getSize());
    } finally {
  if (zipFile != null) {
    try {
      zipFile.close();
    } catch (Exception e) {

相关文章