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

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

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

ZipFile.readCentralDir介绍

[英]Find the central directory and read the contents.

The central directory can be followed by a variable-length comment field, so we have to scan through it backwards. The comment is at most 64K, plus we have 18 bytes for the end-of-central-dir stuff itself, plus apparently sometimes people throw random junk on the end just for the fun of it.

This is all a little wobbly. If the wrong value ends up in the EOCD area, we're hosed. This appears to be the way that everybody handles it though, so we're in good company if this fails.
[中]找到中心目录并阅读内容。
中央目录后面可以跟一个可变长度的注释字段,所以我们必须向后扫描它。评论最多64K,加上我们有18个字节作为central dir内容本身的结尾,而且显然有时候人们只是为了好玩而在结尾随意扔垃圾。
这一切都有点不稳定。如果EOCD区域出现错误的值,我们将被冲洗。不过,这似乎是每个人处理问题的方式,所以如果失败了,我们会有很好的伙伴关系。

代码示例

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

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: MobiVM/robovm

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: ibinti/bugvm

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: com.jtransc/jtransc-rt

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 * <p>
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  ras = new RAFile(file);
  readCentralDir();
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Constructs a new {@code ZipFile} allowing access to the given file.
 * The {@code mode} must be either {@code OPEN_READ} or {@code OPEN_READ|OPEN_DELETE}.
 *
 * <p>If the {@code OPEN_DELETE} flag is supplied, the file will be deleted at or before the
 * time that the {@code ZipFile} is closed (the contents will remain accessible until
 * this {@code ZipFile} is closed); it also calls {@code File.deleteOnExit}.
 *
 * @throws IOException if an {@code IOException} occurs.
 */
public ZipFile(File file, int mode) throws IOException {
  filename = file.getPath();
  if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) {
    throw new IllegalArgumentException("Bad mode: " + mode);
  }
  if ((mode & OPEN_DELETE) != 0) {
    fileToDeleteOnClose = file;
    fileToDeleteOnClose.deleteOnExit();
  } else {
    fileToDeleteOnClose = null;
  }
  raf = new RandomAccessFile(filename, "r");
  readCentralDir();
  guard.open("close");
}

相关文章