< prev index next >

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

Print this page

 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.internal.jrtfs;
 26 
 27 import java.io.IOException;
 28 import java.net.URISyntaxException;
 29 import java.net.URL;
 30 import java.nio.file.Files;
 31 import java.nio.file.FileSystem;
 32 import java.nio.file.FileSystems;
 33 import java.nio.file.FileSystemNotFoundException;
 34 import java.nio.file.Path;
 35 import java.nio.file.Paths;
 36 import java.security.AccessController;
 37 import java.security.CodeSource;
 38 import java.security.PrivilegedAction;
 39 
 40 import jdk.internal.jimage.ImageReader;
 41 import jdk.internal.jimage.ImageReader.Node;

 42 
 43 /**
 44  * @implNote This class needs to maintain JDK 8 source compatibility.
 45  *
 46  * It is used internally in the JDK to implement jimage/jrtfs access,
 47  * but also compiled and delivered as part of the jrtfs.jar to support access
 48  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 49  */
 50 @SuppressWarnings({ "removal", "suppression"} )
 51 abstract class SystemImage {
 52 
 53     abstract Node findNode(String path) throws IOException;
 54     abstract byte[] getResource(Node node) throws IOException;
 55     abstract void close() throws IOException;
 56 
 57     static SystemImage open() throws IOException {
 58         if (modulesImageExists) {
 59             // open a .jimage and build directory structure
 60             final ImageReader image = ImageReader.open(moduleImageFile);
 61             return new SystemImage() {
 62                 @Override
 63                 Node findNode(String path) throws IOException {
 64                     return image.findNode(path);
 65                 }
 66                 @Override
 67                 byte[] getResource(Node node) throws IOException {
 68                     return image.getResource(node);
 69                 }
 70                 @Override
 71                 void close() throws IOException {
 72                     image.close();
 73                 }
 74             };
 75         }

 76         if (Files.notExists(explodedModulesDir))
 77             throw new FileSystemNotFoundException(explodedModulesDir.toString());




 78         return new ExplodedImage(explodedModulesDir);
 79     }
 80 
 81     private static final String RUNTIME_HOME;
 82     // "modules" jimage file Path
 83     private static final Path moduleImageFile;
 84     // "modules" jimage exists or not?
 85     private static final boolean modulesImageExists;
 86     // <JAVA_HOME>/modules directory Path
 87     private static final Path explodedModulesDir;
 88 
 89     static {
 90         PrivilegedAction<String> pa = SystemImage::findHome;
 91         RUNTIME_HOME = AccessController.doPrivileged(pa);
 92 
 93         FileSystem fs = FileSystems.getDefault();
 94         moduleImageFile = fs.getPath(RUNTIME_HOME, "lib", "modules");
 95         explodedModulesDir = fs.getPath(RUNTIME_HOME, "modules");
 96 
 97         modulesImageExists = AccessController.doPrivileged(

 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.internal.jrtfs;
 26 
 27 import java.io.IOException;
 28 import java.net.URISyntaxException;
 29 import java.net.URL;
 30 import java.nio.file.Files;
 31 import java.nio.file.FileSystem;
 32 import java.nio.file.FileSystems;
 33 import java.nio.file.FileSystemNotFoundException;
 34 import java.nio.file.Path;
 35 import java.nio.file.Paths;
 36 import java.security.AccessController;
 37 import java.security.CodeSource;
 38 import java.security.PrivilegedAction;
 39 
 40 import jdk.internal.jimage.ImageReader;
 41 import jdk.internal.jimage.ImageReader.Node;
 42 import jdk.internal.jimage.PreviewMode;
 43 
 44 /**
 45  * @implNote This class needs to maintain JDK 8 source compatibility.
 46  *
 47  * It is used internally in the JDK to implement jimage/jrtfs access,
 48  * but also compiled and delivered as part of the jrtfs.jar to support access
 49  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 50  */
 51 @SuppressWarnings({ "removal", "suppression"} )
 52 abstract class SystemImage {
 53 
 54     abstract Node findNode(String path) throws IOException;
 55     abstract byte[] getResource(Node node) throws IOException;
 56     abstract void close() throws IOException;
 57 
 58     static SystemImage open(PreviewMode mode) throws IOException {
 59         if (modulesImageExists) {
 60             // open a .jimage and build directory structure
 61             final ImageReader image = ImageReader.open(moduleImageFile, mode);
 62             return new SystemImage() {
 63                 @Override
 64                 Node findNode(String path) throws IOException {
 65                     return image.findNode(path);
 66                 }
 67                 @Override
 68                 byte[] getResource(Node node) throws IOException {
 69                     return image.getResource(node);
 70                 }
 71                 @Override
 72                 void close() throws IOException {
 73                     image.close();
 74                 }
 75             };
 76         }
 77 
 78         if (Files.notExists(explodedModulesDir))
 79             throw new FileSystemNotFoundException(explodedModulesDir.toString());
 80         // TODO: Support preview mode in ExplodedImage and remove this check.
 81         if (mode.isPreviewModeEnabled())
 82             throw new UnsupportedOperationException(
 83                     "Preview mode not yet supported for exploded images");
 84         return new ExplodedImage(explodedModulesDir);
 85     }
 86 
 87     private static final String RUNTIME_HOME;
 88     // "modules" jimage file Path
 89     private static final Path moduleImageFile;
 90     // "modules" jimage exists or not?
 91     private static final boolean modulesImageExists;
 92     // <JAVA_HOME>/modules directory Path
 93     private static final Path explodedModulesDir;
 94 
 95     static {
 96         PrivilegedAction<String> pa = SystemImage::findHome;
 97         RUNTIME_HOME = AccessController.doPrivileged(pa);
 98 
 99         FileSystem fs = FileSystems.getDefault();
100         moduleImageFile = fs.getPath(RUNTIME_HOME, "lib", "modules");
101         explodedModulesDir = fs.getPath(RUNTIME_HOME, "modules");
102 
103         modulesImageExists = AccessController.doPrivileged(
< prev index next >