src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
changeset 52008 6f04692c7d51
parent 51795 feb4c9e03aed
child 53043 fd2e8f941ded
equal deleted inserted replaced
52007:b16820c2336d 52008:6f04692c7d51
   397             endRead();
   397             endRead();
   398         }
   398         }
   399     }
   399     }
   400 
   400 
   401     // returns the list of child paths of "path"
   401     // returns the list of child paths of "path"
   402     Iterator<Path> iteratorOf(byte[] path,
   402     Iterator<Path> iteratorOf(ZipPath dir,
   403                               DirectoryStream.Filter<? super Path> filter)
   403                               DirectoryStream.Filter<? super Path> filter)
   404         throws IOException
   404         throws IOException
   405     {
   405     {
   406         beginWrite();    // iteration of inodes needs exclusive lock
   406         beginWrite();    // iteration of inodes needs exclusive lock
   407         try {
   407         try {
   408             ensureOpen();
   408             ensureOpen();
       
   409             byte[] path = dir.getResolvedPath();
   409             IndexNode inode = getInode(path);
   410             IndexNode inode = getInode(path);
   410             if (inode == null)
   411             if (inode == null)
   411                 throw new NotDirectoryException(getString(path));
   412                 throw new NotDirectoryException(getString(path));
   412             List<Path> list = new ArrayList<>();
   413             List<Path> list = new ArrayList<>();
   413             IndexNode child = inode.child;
   414             IndexNode child = inode.child;
   414             while (child != null) {
   415             while (child != null) {
   415                 // assume all path from zip file itself is "normalized"
   416                 // (1) assume all path from zip file itself is "normalized"
   416                 ZipPath zp = new ZipPath(this, child.name, true);
   417                 // (2) IndexNode.name is absolute. see IndexNode(byte[],int,int)
   417                 if (filter == null || filter.accept(zp))
   418                 // (3) if parent "dir" is relative when ZipDirectoryStream
   418                     list.add(zp);
   419                 //     is created, the returned child path needs to be relative
       
   420                 //     as well.
       
   421                 byte[] cname = child.name;
       
   422                 if (!dir.isAbsolute()) {
       
   423                     cname = Arrays.copyOfRange(cname, 1, cname.length);
       
   424                 }
       
   425                 ZipPath zpath = new ZipPath(this, cname, true);
       
   426                 if (filter == null || filter.accept(zpath))
       
   427                     list.add(zpath);
   419                 child = child.sibling;
   428                 child = child.sibling;
   420             }
   429             }
   421             return list.iterator();
   430             return list.iterator();
   422         } finally {
   431         } finally {
   423             endWrite();
   432             endWrite();