Esempio n. 1
0
  public static void main(String[] args) throws Throwable {
    if (args.length < 1) {
      print("Usage: java ZipInfo zfname");
    } else {
      Map<String, ?> env = Collections.emptyMap();
      ZipFileSystem zfs =
          (ZipFileSystem) (new ZipFileSystemProvider().newFileSystem(Paths.get(args[0]), env));
      byte[] cen = zfs.cen;
      if (cen == null) {
        print("zip file is empty%n");
        return;
      }
      int pos = 0;
      byte[] buf = new byte[1024];
      int no = 1;
      while (pos + CENHDR < cen.length) {
        print("----------------#%d--------------------%n", no++);
        printCEN(cen, pos);

        // use size CENHDR as the extra bytes to read, just in case the
        // loc.extra is bigger than the cen.extra, try to avoid to read
        // twice
        long len = LOCHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENHDR;
        if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
          zfs.zerror("read loc header failed");
        if (LOCEXT(buf) > CENEXT(cen, pos) + CENHDR) {
          // have to read the second time;
          len = LOCHDR + LOCNAM(buf) + LOCEXT(buf);
          if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
            zfs.zerror("read loc header failed");
        }
        printLOC(buf);
        pos += CENHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENCOM(cen, pos);
      }
      zfs.close();
    }
  }