gpt4 book ai didi

com.googlecode.d2j.util.zip.ZipEntry类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 10:19:31 26 4
gpt4 key购买 nike

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

ZipEntry介绍

[英]An entry within a zip file. An entry has attributes such as its name (which is actually a path) and the uncompressed size of the corresponding data. An entry does not contain the data itself, but can be used as a key with java.util.zip.ZipFile#getInputStream. The class documentation for java.util.zip.ZipInputStream and java.util.zip.ZipOutputStream shows how android.ZipEntry is used in conjunction with those two classes.
[中]zip文件中的条目。条目具有名称(实际上是路径)和相应数据的未压缩大小等属性。条目本身不包含数据,但可以在java中用作密钥。util。拉链ZipFile#getInputStream。java类文档。util。拉链ZipInputStream和java。util。拉链ZipOutputStream展示了android是如何实现的。ZipEntry与这两个类一起使用。

代码示例

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

private ZipEntry findFirstEntry0(String entryName) {
  for (ZipEntry e : entries) {
    if (e.getName().equals(entryName)) {
      return e;
    }
  }
  return null;
}

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

entries = new ArrayList<>(numEntries);
for (int i = 0; i < numEntries; ++i) {
  ZipEntry newEntry = new ZipEntry(buf, skipCommentsAndExtra);
  if (newEntry.localHeaderRelOffset >= centralDirOffset) {

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

@Override
  public int available() throws IOException {
    return super.available() == 0 ? 0 : (int) (entry.getSize() - bytesRead);
  }
}

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

try(com.googlecode.d2j.util.zip.ZipFile zipFile = new com.googlecode.d2j.util.zip.ZipFile(data)) {
  for (com.googlecode.d2j.util.zip.ZipEntry e : zipFile.entries()) {
    ZipEntry nEntry = new ZipEntry(e.getName());
    nEntry.setMethod(e.getMethod() == com.googlecode.d2j.util.zip.ZipEntry.STORED ? ZipEntry.STORED
        : ZipEntry.DEFLATED);
    zos.putNextEntry(nEntry);

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

@Test
public void test0() throws IOException {
  byte[] data = ZipUtil.toByteArray(BadZipEntryFlagTest.class.getResourceAsStream("/bad.zip"));
  try (ZipFile zip = new ZipFile(data)) {
    for (com.googlecode.d2j.util.zip.ZipEntry e : zip.entries()) {
      System.out.println(e);
      if (!e.isDirectory()) {
        zip.getInputStream(e).read();
      }
    }
  }
}

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

@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
  final int i;
  try {
    i = super.read(buffer, byteOffset, byteCount);
  } catch (IOException e) {
    throw new IOException("Error reading data for " + entry.getName() + " near offset " + bytesRead, e);
  }
  if (i == -1) {
    if (entry.size != bytesRead) {
      throw new IOException("Size mismatch on inflated file: " + bytesRead + " vs " + entry.size);
    }
  } else {
    bytesRead += i;
  }
  return i;
}

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

/**
 * Returns an input stream on the data of the specified {@code android.ZipEntry}.
 * 
 * @param entry
 *            the android.ZipEntry.
 * @return an input stream of the data contained in the {@code android.ZipEntry}.
 * @throws java.io.IOException
 *             if an {@code IOException} occurs.
 * @throws IllegalStateException
 *             if this zip file has been closed.
 */
public InputStream getInputStream(ZipEntry entry) throws IOException {
  long entryDataStart = getEntryDataStart(entry);
  ByteBuffer is = (ByteBuffer) raf.duplicate().position((int) entryDataStart);
  if (entry.compressionMethod == ZipEntry.STORED) {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.size);
    return new ByteBufferBackedInputStream(buf);
  } else {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN)
        .limit((int) entry.compressedSize);
    int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
    return new ZipInflaterInputStream(new ByteBufferBackedInputStream(buf), new Inflater(true), bufSize, entry);
  }
}

代码示例来源:origin: SparkInLee/dexdiff

entries = new ArrayList<>(numEntries);
for (int i = 0; i < numEntries; ++i) {
  ZipEntry newEntry = new ZipEntry(buf, skipCommentsAndExtra);
  if (newEntry.localHeaderRelOffset >= centralDirOffset) {

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

public static BaseDexFileReader open(byte[] data) throws IOException {
  if (data.length < 3) {
    throw new IOException("File too small to be a dex/zip");
  }
  if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
    return new DexFileReader(data);
  } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
    TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();
    try (ZipFile zipFile = new ZipFile(data)) {
      for (ZipEntry e : zipFile.entries()) {
        String entryName = e.getName();
        if (entryName.startsWith("classes") && entryName.endsWith(".dex")) {
          if (!dexFileReaders.containsKey(entryName)) { // only the first one
            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));
          }
        }
      }
    }
    if (dexFileReaders.size() == 0) {
      throw new IOException("Can not find classes.dex in zip file");
    } else if (dexFileReaders.size() == 1) {
      return dexFileReaders.firstEntry().getValue();
    } else {
      return new MultiDexFileReader(dexFileReaders.values());
    }
  }
  throw new IOException("the src file not a .dex or zip file");
}

代码示例来源:origin: SparkInLee/dexdiff

@Override
  public int available() throws IOException {
    return super.available() == 0 ? 0 : (int) (entry.getSize() - bytesRead);
  }
}

代码示例来源:origin: SparkInLee/dexdiff

private ZipEntry findFirstEntry0(String entryName) {
  for (ZipEntry e : entries) {
    if (e.getName().equals(entryName)) {
      return e;
    }
  }
  return null;
}

代码示例来源:origin: SparkInLee/dexdiff

/**
 * Returns an input stream on the data of the specified {@code android.ZipEntry}.
 * 
 * @param entry
 *            the android.ZipEntry.
 * @return an input stream of the data contained in the {@code android.ZipEntry}.
 * @throws java.io.IOException
 *             if an {@code IOException} occurs.
 * @throws IllegalStateException
 *             if this zip file has been closed.
 */
public InputStream getInputStream(ZipEntry entry) throws IOException {
  long entryDataStart = getEntryDataStart(entry);
  ByteBuffer is = (ByteBuffer) raf.duplicate().position((int) entryDataStart);
  if (entry.compressionMethod == ZipEntry.STORED) {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.size);
    return new ByteBufferBackedInputStream(buf);
  } else {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN)
        .limit((int) entry.compressedSize);
    int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
    return new ZipInflaterInputStream(new ByteBufferBackedInputStream(buf), new Inflater(true), bufSize, entry);
  }
}

代码示例来源:origin: SparkInLee/dexdiff

@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
  final int i;
  try {
    i = super.read(buffer, byteOffset, byteCount);
  } catch (IOException e) {
    throw new IOException("Error reading data for " + entry.getName() + " near offset " + bytesRead, e);
  }
  if (i == -1) {
    if (entry.size != bytesRead) {
      throw new IOException("Size mismatch on inflated file: " + bytesRead + " vs " + entry.size);
    }
  } else {
    bytesRead += i;
  }
  return i;
}

代码示例来源:origin: SparkInLee/dexdiff

public static BaseDexFileReader open(byte[] data) throws IOException {
  if (data.length < 3) {
    throw new IOException("File too small to be a dex/zip");
  }
  if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
    return new DexFileReader(data);
  } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
    TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();
    try (ZipFile zipFile = new ZipFile(data)) {
      for (ZipEntry e : zipFile.entries()) {
        String entryName = e.getName();
        if (entryName.startsWith("classes") && entryName.endsWith(".dex")) {
          if (!dexFileReaders.containsKey(entryName)) { // only the first one
            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));
          }
        }
      }
    }
    if (dexFileReaders.size() == 0) {
      throw new IOException("Can not find classes.dex in zip file");
    } else if (dexFileReaders.size() == 1) {
      return dexFileReaders.firstEntry().getValue();
    } else {
      return new MultiDexFileReader(dexFileReaders.values());
    }
  }
  throw new IOException("the src file not a .dex or zip file");
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com