Exemplo n.º 1
0
  /**
   * Constructs a new ZipHandle corresponding to the given entry of the specified Zip file.
   *
   * @throws HandleException if the given file is not a Zip file.
   */
  public ZipHandle(String file, ZipEntry entry) throws IOException {
    super();
    this.file = file;

    in = openStream(file);
    zip = new ZipInputStream(in);
    entryName = entry.getName();
    entryCount = 1;

    seekToEntry();
    resetStream();
    length = entry.getSize();
    if (length <= 0) {
      populateLength();
    }
  }
Exemplo n.º 2
0
  public ZipHandle(String file) throws IOException {
    super();
    this.file = file;

    in = openStream(file);
    zip = new ZipInputStream(in);
    entryName = null;
    entryCount = 0;

    // strip off .zip extension and directory prefix
    String innerFile = file.substring(0, file.length() - 4);
    int slash = innerFile.lastIndexOf(File.separator);
    if (slash < 0) slash = innerFile.lastIndexOf("/");
    if (slash >= 0) innerFile = innerFile.substring(slash + 1);

    // look for Zip entry with same prefix as the Zip file itself
    boolean matchFound = false;
    length = 0;
    while (true) {
      ZipEntry ze = zip.getNextEntry();
      if (ze == null) break;
      if (entryName == null) entryName = ze.getName();
      if (!matchFound && ze.getName().startsWith(innerFile)) {
        // found entry with matching name
        entryName = ze.getName();
        matchFound = true;
      }
      entryCount++;
      length += ze.getSize();
    }
    resetStream();

    if (length <= 0) {
      populateLength();
    }
  }