src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java

Print this page




 382             ensureOpen();
 383             return getInode(path) != null;
 384         } finally {
 385             endRead();
 386         }
 387     }
 388 
 389     boolean isDirectory(byte[] path)
 390         throws IOException
 391     {
 392         beginRead();
 393         try {
 394             IndexNode n = getInode(path);
 395             return n != null && n.isDir();
 396         } finally {
 397             endRead();
 398         }
 399     }
 400 
 401     // returns the list of child paths of "path"
 402     Iterator<Path> iteratorOf(byte[] path,
 403                               DirectoryStream.Filter<? super Path> filter)
 404         throws IOException
 405     {
 406         beginWrite();    // iteration of inodes needs exclusive lock
 407         try {
 408             ensureOpen();

 409             IndexNode inode = getInode(path);
 410             if (inode == null)
 411                 throw new NotDirectoryException(getString(path));
 412             List<Path> list = new ArrayList<>();
 413             IndexNode child = inode.child;
 414             while (child != null) {
 415                 // assume all path from zip file itself is "normalized"
 416                 ZipPath zp = new ZipPath(this, child.name, true);
 417                 if (filter == null || filter.accept(zp))
 418                     list.add(zp);








 419                 child = child.sibling;
 420             }
 421             return list.iterator();
 422         } finally {
 423             endWrite();
 424         }
 425     }
 426 
 427     void createDirectory(byte[] dir, FileAttribute<?>... attrs)
 428         throws IOException
 429     {
 430         checkWritable();
 431         //  dir = toDirectoryPath(dir);
 432         beginWrite();
 433         try {
 434             ensureOpen();
 435             if (dir.length == 0 || exists(dir))  // root dir, or exiting dir
 436                 throw new FileAlreadyExistsException(getString(dir));
 437             checkParents(dir);
 438             Entry e = new Entry(dir, Entry.NEW, true, METHOD_STORED);




 382             ensureOpen();
 383             return getInode(path) != null;
 384         } finally {
 385             endRead();
 386         }
 387     }
 388 
 389     boolean isDirectory(byte[] path)
 390         throws IOException
 391     {
 392         beginRead();
 393         try {
 394             IndexNode n = getInode(path);
 395             return n != null && n.isDir();
 396         } finally {
 397             endRead();
 398         }
 399     }
 400 
 401     // returns the list of child paths of "path"
 402     Iterator<Path> iteratorOf(ZipPath dir,
 403                               DirectoryStream.Filter<? super Path> filter)
 404         throws IOException
 405     {
 406         beginWrite();    // iteration of inodes needs exclusive lock
 407         try {
 408             ensureOpen();
 409             byte[] path = dir.getResolvedPath();
 410             IndexNode inode = getInode(path);
 411             if (inode == null)
 412                 throw new NotDirectoryException(getString(path));
 413             List<Path> list = new ArrayList<>();
 414             IndexNode child = inode.child;
 415             while (child != null) {
 416                 // (1) assume all path from zip file itself is "normalized"
 417                 // (2) IndexNode.name is absolute. see IndexNode(byte[],int,int)
 418                 // (3) if parent "dir" is relative when ZipDirectoryStream
 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);
 428                 child = child.sibling;
 429             }
 430             return list.iterator();
 431         } finally {
 432             endWrite();
 433         }
 434     }
 435 
 436     void createDirectory(byte[] dir, FileAttribute<?>... attrs)
 437         throws IOException
 438     {
 439         checkWritable();
 440         //  dir = toDirectoryPath(dir);
 441         beginWrite();
 442         try {
 443             ensureOpen();
 444             if (dir.length == 0 || exists(dir))  // root dir, or exiting dir
 445                 throw new FileAlreadyExistsException(getString(dir));
 446             checkParents(dir);
 447             Entry e = new Entry(dir, Entry.NEW, true, METHOD_STORED);