Esempio n. 1
0
  /**
   * Creates an input stream to read the file content from. Is only called if {@link #doGetType}
   * returns {@link FileType#FILE}. The input stream returned by this method is guaranteed to be
   * closed before this method is called again.
   */
  @Override
  protected InputStream doGetInputStream() throws Exception {
    // VFS-210: zip allows to gather an input stream even from a directory and will
    // return -1 on the first read. getType should not be expensive and keeps the tests
    // running
    if (!getType().hasContent()) {
      throw new FileSystemException("vfs.provider/read-not-file.error", getName());
    }

    return fs.getZipFile().getInputStream(entry);
  }
Esempio n. 2
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();
    }
  }