< prev index next >

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

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -56,15 +56,15 @@
  import java.nio.file.spi.FileSystemProvider;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
- import java.util.Map;
  import java.util.Objects;
  import java.util.Set;
  import java.util.regex.Pattern;
  import jdk.internal.jimage.ImageReader.Node;
+ import jdk.internal.jimage.PreviewMode;
  
  /**
   * jrt file system implementation built on System jimage files.
   *
   * @implNote This class needs to maintain JDK 8 source compatibility.

@@ -79,17 +79,38 @@
      private final JrtPath rootPath = new JrtPath(this, "/");
      private volatile boolean isOpen;
      private volatile boolean isClosable;
      private SystemImage image;
  
-     JrtFileSystem(JrtFileSystemProvider provider, Map<String, ?> env)
-             throws IOException
-     {
+     /**
+      * Special constructor for the singleton system jrt file system. This creates
+      * a non-closable instance, and should only be called once by {@link
+      * JrtFileSystemProvider}.
+      *
+      * @param provider the provider opening the file system.
+      */
+     JrtFileSystem(JrtFileSystemProvider provider)
+             throws IOException {
          this.provider = provider;
-         this.image = SystemImage.open();  // open image file
+         this.image = SystemImage.open(PreviewMode.FOR_RUNTIME);  // open image file
          this.isOpen = true;
-         this.isClosable = env != null;
+         // Only the system singleton jrt file system is "unclosable".
+         this.isClosable = false;
+     }
+ 
+     /**
+      * Creates a new, non-system, instance of the jrt file system.
+      *
+      * @param provider the provider opening the file system.
+      * @param mode controls whether preview resources are visible.
+      */
+     JrtFileSystem(JrtFileSystemProvider provider, PreviewMode mode)
+             throws IOException {
+         this.provider = provider;
+         this.image = SystemImage.open(mode);  // open image file
+         this.isOpen = true;
+         this.isClosable = true;
      }
  
      // FileSystem method implementations
      @Override
      public boolean isOpen() {
< prev index next >