< prev index next >

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

Print this page
*** 22,10 ***
--- 22,12 ---
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package jdk.internal.jrtfs;
  
+ import jdk.internal.jimage.PreviewMode;
+ 
  import java.io.*;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.nio.channels.*;

*** 42,11 ***
  import java.util.Set;
  import java.util.concurrent.ExecutorService;
  
  /**
   * File system provider for jrt file systems. Conditionally creates jrt fs on
!  * .jimage file or exploded modules directory of underlying JDK.
   *
   * @implNote This class needs to maintain JDK 8 source compatibility.
   *
   * It is used internally in the JDK to implement jimage/jrtfs access,
   * but also compiled and delivered as part of the jrtfs.jar to support access
--- 44,11 ---
  import java.util.Set;
  import java.util.concurrent.ExecutorService;
  
  /**
   * File system provider for jrt file systems. Conditionally creates jrt fs on
!  * a jimage file, or exploded modules directory of underlying JDK.
   *
   * @implNote This class needs to maintain JDK 8 source compatibility.
   *
   * It is used internally in the JDK to implement jimage/jrtfs access,
   * but also compiled and delivered as part of the jrtfs.jar to support access

*** 105,12 ***
          checkPermission();
          checkUri(uri);
          if (env.containsKey("java.home")) {
              return newFileSystem((String)env.get("java.home"), uri, env);
          } else {
!             return new JrtFileSystem(this, env);
          }
      }
  
      private static final String JRT_FS_JAR = "jrt-fs.jar";
      private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
              throws IOException {
--- 107,24 ---
          checkPermission();
          checkUri(uri);
          if (env.containsKey("java.home")) {
              return newFileSystem((String)env.get("java.home"), uri, env);
          } else {
!             return new JrtFileSystem(this, parsePreviewMode(env.get("previewMode")));
+         }
+     }
+ 
+     // Currently this does not support specifying "for runtime", because it is
+     // expected that callers creating non-standard image readers will not be
+     // using them to read resources for the current runtime (they would just
+     // use "jrt:" URLs if they were doing that).
+     private static PreviewMode parsePreviewMode(Object envValue) {
+         if (envValue instanceof String && Boolean.parseBoolean((String) envValue)) {
+             return PreviewMode.ENABLED;
          }
+         // Default (unspecified/null or bad parameter) is to not use preview mode.
+         return PreviewMode.DISABLED;
      }
  
      private static final String JRT_FS_JAR = "jrt-fs.jar";
      private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
              throws IOException {

*** 206,11 ***
          if (fs == null) {
              synchronized (this) {
                  fs = this.theFileSystem;
                  if (fs == null) {
                      try {
!                         this.theFileSystem = fs = new JrtFileSystem(this, null);
                      } catch (IOException ioe) {
                          throw new InternalError(ioe);
                      }
                  }
              }
--- 220,12 ---
          if (fs == null) {
              synchronized (this) {
                  fs = this.theFileSystem;
                  if (fs == null) {
                      try {
!                         // Special constructor call for singleton instance.
+                         this.theFileSystem = fs = new JrtFileSystem(this);
                      } catch (IOException ioe) {
                          throw new InternalError(ioe);
                      }
                  }
              }

*** 224,11 ***
          checkUri(uri);
          return getTheFileSystem();
      }
  
      // Checks that the given file is a JrtPath
!     static final JrtPath toJrtPath(Path path) {
          Objects.requireNonNull(path, "path");
          if (!(path instanceof JrtPath)) {
              throw new ProviderMismatchException();
          }
          return (JrtPath) path;
--- 239,11 ---
          checkUri(uri);
          return getTheFileSystem();
      }
  
      // Checks that the given file is a JrtPath
!     static JrtPath toJrtPath(Path path) {
          Objects.requireNonNull(path, "path");
          if (!(path instanceof JrtPath)) {
              throw new ProviderMismatchException();
          }
          return (JrtPath) path;

*** 255,11 ***
              throws IOException {
          toJrtPath(path).createDirectory(attrs);
      }
  
      @Override
!     public final void delete(Path path) throws IOException {
          toJrtPath(path).delete();
      }
  
      @Override
      public <V extends FileAttributeView> V
--- 270,11 ---
              throws IOException {
          toJrtPath(path).createDirectory(attrs);
      }
  
      @Override
!     public void delete(Path path) throws IOException {
          toJrtPath(path).delete();
      }
  
      @Override
      public <V extends FileAttributeView> V
< prev index next >