< prev index next >

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

Print this page

 41 import java.nio.file.FileSystem;
 42 import java.nio.file.FileSystemException;
 43 import java.nio.file.InvalidPathException;
 44 import java.nio.file.LinkOption;
 45 import java.nio.file.NoSuchFileException;
 46 import java.nio.file.NotDirectoryException;
 47 import java.nio.file.OpenOption;
 48 import java.nio.file.Path;
 49 import java.nio.file.PathMatcher;
 50 import java.nio.file.ReadOnlyFileSystemException;
 51 import java.nio.file.StandardOpenOption;
 52 import java.nio.file.WatchService;
 53 import java.nio.file.attribute.FileAttribute;
 54 import java.nio.file.attribute.FileTime;
 55 import java.nio.file.attribute.UserPrincipalLookupService;
 56 import java.nio.file.spi.FileSystemProvider;
 57 import java.util.Arrays;
 58 import java.util.Collections;
 59 import java.util.HashSet;
 60 import java.util.Iterator;
 61 import java.util.Map;
 62 import java.util.Objects;
 63 import java.util.Set;
 64 import java.util.regex.Pattern;
 65 import jdk.internal.jimage.ImageReader.Node;

 66 
 67 /**
 68  * jrt file system implementation built on System jimage files.
 69  *
 70  * @implNote This class needs to maintain JDK 8 source compatibility.
 71  *
 72  * It is used internally in the JDK to implement jimage/jrtfs access,
 73  * but also compiled and delivered as part of the jrtfs.jar to support access
 74  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 75  */
 76 class JrtFileSystem extends FileSystem {
 77 
 78     private final JrtFileSystemProvider provider;
 79     private final JrtPath rootPath = new JrtPath(this, "/");
 80     private volatile boolean isOpen;
 81     private volatile boolean isClosable;
 82     private SystemImage image;
 83 
 84     JrtFileSystem(JrtFileSystemProvider provider, Map<String, ?> env)
 85             throws IOException
 86     {






 87         this.provider = provider;
 88         this.image = SystemImage.open();  // open image file
 89         this.isOpen = true;
 90         this.isClosable = env != null;















 91     }
 92 
 93     // FileSystem method implementations
 94     @Override
 95     public boolean isOpen() {
 96         return isOpen;
 97     }
 98 
 99     @Override
100     public void close() throws IOException {
101         if (!isClosable)
102             throw new UnsupportedOperationException();
103         cleanup();
104     }
105 
106     @Override
107     public FileSystemProvider provider() {
108         return provider;
109     }
110 

 41 import java.nio.file.FileSystem;
 42 import java.nio.file.FileSystemException;
 43 import java.nio.file.InvalidPathException;
 44 import java.nio.file.LinkOption;
 45 import java.nio.file.NoSuchFileException;
 46 import java.nio.file.NotDirectoryException;
 47 import java.nio.file.OpenOption;
 48 import java.nio.file.Path;
 49 import java.nio.file.PathMatcher;
 50 import java.nio.file.ReadOnlyFileSystemException;
 51 import java.nio.file.StandardOpenOption;
 52 import java.nio.file.WatchService;
 53 import java.nio.file.attribute.FileAttribute;
 54 import java.nio.file.attribute.FileTime;
 55 import java.nio.file.attribute.UserPrincipalLookupService;
 56 import java.nio.file.spi.FileSystemProvider;
 57 import java.util.Arrays;
 58 import java.util.Collections;
 59 import java.util.HashSet;
 60 import java.util.Iterator;

 61 import java.util.Objects;
 62 import java.util.Set;
 63 import java.util.regex.Pattern;
 64 import jdk.internal.jimage.ImageReader.Node;
 65 import jdk.internal.jimage.PreviewMode;
 66 
 67 /**
 68  * jrt file system implementation built on System jimage files.
 69  *
 70  * @implNote This class needs to maintain JDK 8 source compatibility.
 71  *
 72  * It is used internally in the JDK to implement jimage/jrtfs access,
 73  * but also compiled and delivered as part of the jrtfs.jar to support access
 74  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 75  */
 76 class JrtFileSystem extends FileSystem {
 77 
 78     private final JrtFileSystemProvider provider;
 79     private final JrtPath rootPath = new JrtPath(this, "/");
 80     private volatile boolean isOpen;
 81     private volatile boolean isClosable;
 82     private SystemImage image;
 83 
 84     /**
 85      * Special constructor for the singleton system jrt file system. This creates
 86      * a non-closable instance, and should only be called once by {@link
 87      * JrtFileSystemProvider}.
 88      *
 89      * @param provider the provider opening the file system.
 90      */
 91     JrtFileSystem(JrtFileSystemProvider provider)
 92             throws IOException {
 93         this.provider = provider;
 94         this.image = SystemImage.open(PreviewMode.FOR_RUNTIME);  // open image file
 95         this.isOpen = true;
 96         // Only the system singleton jrt file system is "unclosable".
 97         this.isClosable = false;
 98     }
 99 
100     /**
101      * Creates a new, non-system, instance of the jrt file system.
102      *
103      * @param provider the provider opening the file system.
104      * @param mode controls whether preview resources are visible.
105      */
106     JrtFileSystem(JrtFileSystemProvider provider, PreviewMode mode)
107             throws IOException {
108         this.provider = provider;
109         this.image = SystemImage.open(mode);  // open image file
110         this.isOpen = true;
111         this.isClosable = true;
112     }
113 
114     // FileSystem method implementations
115     @Override
116     public boolean isOpen() {
117         return isOpen;
118     }
119 
120     @Override
121     public void close() throws IOException {
122         if (!isClosable)
123             throw new UnsupportedOperationException();
124         cleanup();
125     }
126 
127     @Override
128     public FileSystemProvider provider() {
129         return provider;
130     }
131 
< prev index next >