1 /*
2 * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
37 import java.nio.file.ClosedFileSystemException;
38 import java.nio.file.CopyOption;
39 import java.nio.file.DirectoryStream;
40 import java.nio.file.FileStore;
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.ArrayList;
58 import java.util.Arrays;
59 import java.util.Collections;
60 import java.util.HashSet;
61 import java.util.Iterator;
62 import java.util.Map;
63 import java.util.Objects;
64 import java.util.Set;
65 import java.util.regex.Pattern;
66 import jdk.internal.jimage.ImageReader.Node;
67 import static java.util.stream.Collectors.toList;
68
69 /**
70 * jrt file system implementation built on System jimage files.
71 *
72 * @implNote This class needs to maintain JDK 8 source compatibility.
73 *
74 * It is used internally in the JDK to implement jimage/jrtfs access,
75 * but also compiled and delivered as part of the jrtfs.jar to support access
76 * to the jimage file provided by the shipped JDK by tools running on JDK 8.
77 */
78 class JrtFileSystem extends FileSystem {
79
80 private final JrtFileSystemProvider provider;
81 private final JrtPath rootPath = new JrtPath(this, "/");
82 private volatile boolean isOpen;
83 private volatile boolean isClosable;
84 private SystemImage image;
85
86 JrtFileSystem(JrtFileSystemProvider provider, Map<String, ?> env)
87 throws IOException
208 Node node = checkNode(path);
209 if (node.isLink() && followLinks(options)) {
210 return new JrtFileAttributes(node.resolveLink(true));
211 }
212 return new JrtFileAttributes(node);
213 }
214
215 /**
216 * returns the list of child paths of the given directory "path"
217 *
218 * @param path name of the directory whose content is listed
219 * @return iterator for child paths of the given directory path
220 */
221 Iterator<Path> iteratorOf(JrtPath path, DirectoryStream.Filter<? super Path> filter)
222 throws IOException {
223 Node node = checkNode(path).resolveLink(true);
224 if (!node.isDirectory()) {
225 throw new NotDirectoryException(path.getName());
226 }
227 if (filter == null) {
228 return node.getChildren()
229 .stream()
230 .map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
231 .iterator();
232 }
233 return node.getChildren()
234 .stream()
235 .map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
236 .filter(p -> { try { return filter.accept(p);
237 } catch (IOException x) {}
238 return false;
239 })
240 .iterator();
241 }
242
243 // returns the content of the file resource specified by the path
244 byte[] getFileContent(JrtPath path) throws IOException {
245 Node node = checkNode(path);
246 if (node.isDirectory()) {
247 throw new FileSystemException(path + " is a directory");
248 }
249 //assert node.isResource() : "resource node expected here";
250 return image.getResource(node);
251 }
252
253 /////////////// Implementation details below this point //////////
254
255 // static utility methods
256 static ReadOnlyFileSystemException readOnly() {
257 return new ReadOnlyFileSystemException();
258 }
259
260 // do the supplied options imply that we have to chase symlinks?
|
1 /*
2 * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
37 import java.nio.file.ClosedFileSystemException;
38 import java.nio.file.CopyOption;
39 import java.nio.file.DirectoryStream;
40 import java.nio.file.FileStore;
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
206 Node node = checkNode(path);
207 if (node.isLink() && followLinks(options)) {
208 return new JrtFileAttributes(node.resolveLink(true));
209 }
210 return new JrtFileAttributes(node);
211 }
212
213 /**
214 * returns the list of child paths of the given directory "path"
215 *
216 * @param path name of the directory whose content is listed
217 * @return iterator for child paths of the given directory path
218 */
219 Iterator<Path> iteratorOf(JrtPath path, DirectoryStream.Filter<? super Path> filter)
220 throws IOException {
221 Node node = checkNode(path).resolveLink(true);
222 if (!node.isDirectory()) {
223 throw new NotDirectoryException(path.getName());
224 }
225 if (filter == null) {
226 return node.getChildNames()
227 .map(child -> (Path) (path.resolve(new JrtPath(this, child).getFileName())))
228 .iterator();
229 }
230 return node.getChildNames()
231 .map(child -> (Path) (path.resolve(new JrtPath(this, child).getFileName())))
232 .filter(p -> {
233 try {
234 return filter.accept(p);
235 } catch (IOException x) {}
236 return false;
237 })
238 .iterator();
239 }
240
241 // returns the content of the file resource specified by the path
242 byte[] getFileContent(JrtPath path) throws IOException {
243 Node node = checkNode(path);
244 if (node.isDirectory()) {
245 throw new FileSystemException(path + " is a directory");
246 }
247 //assert node.isResource() : "resource node expected here";
248 return image.getResource(node);
249 }
250
251 /////////////// Implementation details below this point //////////
252
253 // static utility methods
254 static ReadOnlyFileSystemException readOnly() {
255 return new ReadOnlyFileSystemException();
256 }
257
258 // do the supplied options imply that we have to chase symlinks?
|