< prev index next >

src/java.base/share/classes/jdk/internal/jrtfs/JrtExplodedFileSystem.java

Print this page




 276         @Override
 277         boolean isDirectory() {
 278             return true;
 279         }
 280 
 281         @Override
 282         List<Node> getChildren() throws IOException {
 283             return children;
 284         }
 285     }
 286 
 287     private JrtExplodedPath toJrtExplodedPath(String path) {
 288         return toJrtExplodedPath(getBytes(path));
 289     }
 290 
 291     private JrtExplodedPath toJrtExplodedPath(byte[] path) {
 292         return new JrtExplodedPath(this, path);
 293     }
 294 
 295     @Override
 296     boolean isSameFile(AbstractJrtPath p1, AbstractJrtPath p2) throws IOException {
 297         Node n1 = checkNode(p1.getName());
 298         Node n2 = checkNode(p2.getName());
 299         return n1 == n2;
 300     }
 301 
 302     @Override
 303     boolean isLink(AbstractJrtPath jrtPath) throws IOException {
 304         return checkNode(jrtPath.getName()).isLink();
 305     }
 306 
 307     @Override
 308     AbstractJrtPath resolveLink(AbstractJrtPath jrtPath) throws IOException {
 309         String name = checkNode(jrtPath.getName()).resolveLink().getName();
 310         return toJrtExplodedPath(name);
 311     }
 312 
 313     @Override
 314     AbstractJrtFileAttributes getFileAttributes(byte[] path, LinkOption... options) throws IOException {
 315         Node node = checkNode(path);
 316         if (node.isLink() && followLinks(options)) {
 317             node = node.resolveLink(true);
 318         }
 319         return new JrtExplodedFileAttributes(node);
 320     }
 321 
 322     @Override
 323     boolean exists(byte[] path) throws IOException {
 324         try {
 325             checkNode(path);
 326             return true;
 327         } catch (NoSuchFileException nsfe) {
 328             return false;
 329         }
 330     }
 331 
 332     @Override
 333     boolean isDirectory(byte[] path, boolean resolveLinks) throws IOException {
 334         Node node = checkNode(path);
 335         return resolveLinks && node.isLink()
 336                 ? node.resolveLink(true).isDirectory()
 337                 : node.isDirectory();
 338     }
 339 
 340     @Override
 341     Iterator<Path> iteratorOf(byte[] path, String childPrefix) throws IOException {
 342         Node node = checkNode(path).resolveLink(true);
 343         if (!node.isDirectory()) {
 344             throw new NotDirectoryException(getString(path));
 345         }
 346 
 347         Function<Node, Path> f = childPrefix == null
 348                 ? child -> toJrtExplodedPath(child.getName())
 349                 : child -> toJrtExplodedPath(childPrefix + child.getName().substring(1));
 350         return node.getChildren().stream().map(f).collect(toList()).iterator();




 351     }
 352 
 353     @Override
 354     byte[] getFileContent(byte[] path) throws IOException {
 355         return checkNode(path).getContent();




 356     }
 357 
 358     private Node checkNode(byte[] path) throws IOException {
 359         ensureOpen();
 360         return findNode(path);
 361     }
 362 
 363     synchronized Node findNode(byte[] path) throws IOException {
 364         return findNode(getString(path));
 365     }
 366 
 367     // find Node for the given Path
 368     synchronized Node findNode(String str) throws IOException {
 369         Node node = findModulesNode(str);
 370         if (node != null) {
 371             return node;
 372         }
 373 
 374         // lazily created for paths like /packages/<package>/<module>/xyz
 375         // For example /packages/java.lang/java.base/java/lang/




 276         @Override
 277         boolean isDirectory() {
 278             return true;
 279         }
 280 
 281         @Override
 282         List<Node> getChildren() throws IOException {
 283             return children;
 284         }
 285     }
 286 
 287     private JrtExplodedPath toJrtExplodedPath(String path) {
 288         return toJrtExplodedPath(getBytes(path));
 289     }
 290 
 291     private JrtExplodedPath toJrtExplodedPath(byte[] path) {
 292         return new JrtExplodedPath(this, path);
 293     }
 294 
 295     @Override
 296     boolean isSameFile(AbstractJrtPath jrtPath1, AbstractJrtPath jrtPath2) throws IOException {
 297         Node n1 = checkNode(jrtPath1);
 298         Node n2 = checkNode(jrtPath2);
 299         return n1 == n2;
 300     }
 301 
 302     @Override
 303     boolean isLink(AbstractJrtPath jrtPath) throws IOException {
 304         return checkNode(jrtPath).isLink();
 305     }
 306 
 307     @Override
 308     AbstractJrtPath resolveLink(AbstractJrtPath jrtPath) throws IOException {
 309         String name = checkNode(jrtPath).resolveLink().getName();
 310         return toJrtExplodedPath(name);
 311     }
 312 
 313     @Override
 314     AbstractJrtFileAttributes getFileAttributes(AbstractJrtPath jrtPath, LinkOption... options) throws IOException {
 315         Node node = checkNode(jrtPath);
 316         if (node.isLink() && followLinks(options)) {
 317             node = node.resolveLink(true);
 318         }
 319         return new JrtExplodedFileAttributes(node);
 320     }
 321 
 322     @Override
 323     boolean exists(AbstractJrtPath jrtPath) throws IOException {
 324         try {
 325             checkNode(jrtPath);
 326             return true;
 327         } catch (NoSuchFileException nsfe) {
 328             return false;
 329         }
 330     }
 331 
 332     @Override
 333     boolean isDirectory(AbstractJrtPath jrtPath, boolean resolveLinks) throws IOException {
 334         Node node = checkNode(jrtPath);
 335         return resolveLinks && node.isLink()
 336                 ? node.resolveLink(true).isDirectory()
 337                 : node.isDirectory();
 338     }
 339 
 340     @Override
 341     Iterator<Path> iteratorOf(AbstractJrtPath dir) throws IOException {
 342         Node node = checkNode(dir).resolveLink(true);
 343         if (!node.isDirectory()) {
 344             throw new NotDirectoryException(getString(dir.getName()));
 345         }
 346 
 347         Function<Node, Path> nodeToPath =
 348             child -> dir.resolve(
 349                 toJrtExplodedPath(child.getName()).
 350                 getFileName());
 351 
 352         return node.getChildren().stream().
 353                    map(nodeToPath).collect(toList()).
 354                    iterator();
 355     }
 356 
 357     @Override
 358     byte[] getFileContent(AbstractJrtPath jrtPath) throws IOException {
 359         return checkNode(jrtPath).getContent();
 360     }
 361 
 362     private Node checkNode(AbstractJrtPath jrtPath) throws IOException {
 363         return checkNode(jrtPath.getResolvedPath());
 364     }
 365 
 366     private Node checkNode(byte[] path) throws IOException {
 367         ensureOpen();
 368         return findNode(path);
 369     }
 370 
 371     synchronized Node findNode(byte[] path) throws IOException {
 372         return findNode(getString(path));
 373     }
 374 
 375     // find Node for the given Path
 376     synchronized Node findNode(String str) throws IOException {
 377         Node node = findModulesNode(str);
 378         if (node != null) {
 379             return node;
 380         }
 381 
 382         // lazily created for paths like /packages/<package>/<module>/xyz
 383         // For example /packages/java.lang/java.base/java/lang/


< prev index next >