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 import jdk.internal.jimage.PreviewMode;
67
68 /**
69 * jrt file system implementation built on System jimage files.
70 *
71 * @implNote This class needs to maintain JDK 8 source compatibility.
72 *
73 * It is used internally in the JDK to implement jimage/jrtfs access,
74 * but also compiled and delivered as part of the jrtfs.jar to support access
75 * to the jimage file provided by the shipped JDK by tools running on JDK 8.
76 */
77 class JrtFileSystem extends FileSystem {
78
79 private final JrtFileSystemProvider provider;
80 private final JrtPath rootPath = new JrtPath(this, "/");
81 private volatile boolean isOpen;
82 private volatile boolean isClosable;
83 private SystemImage image;
84
85 JrtFileSystem(JrtFileSystemProvider provider, Map<String, ?> env)
86 throws IOException
87 {
88 this.provider = provider;
89 // TODO: Obtain and pass correct preview mode flag value here.
90 this.image = SystemImage.open(PreviewMode.DISABLED); // open image file
91 this.isOpen = true;
92 this.isClosable = env != null;
93 }
94
95 // FileSystem method implementations
96 @Override
97 public boolean isOpen() {
98 return isOpen;
99 }
100
101 @Override
102 public void close() throws IOException {
103 if (!isClosable)
104 throw new UnsupportedOperationException();
105 cleanup();
106 }
107
108 @Override
109 public FileSystemProvider provider() {
110 return provider;
111 }
112
|
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
|