コード例 #1
0
 private void populateLength() throws IOException {
   length = -1;
   while (stream.available() > 0) {
     stream.skip(1);
     length++;
   }
   resetStream();
 }
コード例 #2
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();
    }
  }
コード例 #3
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();
    }
  }