1 /*
2 * Copyright (c) 2016, 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
48 *
49 * @implNote This class needs to maintain JDK 8 source compatibility.
50 *
51 * It is used internally in the JDK to implement jimage/jrtfs access,
52 * but also compiled and delivered as part of the jrtfs.jar to support access
53 * to the jimage file provided by the shipped JDK by tools running on JDK 8.
54 */
55 public final class JrtFileSystemProvider extends FileSystemProvider {
56
57 private volatile FileSystem theFileSystem;
58
59 public JrtFileSystemProvider() {
60 }
61
62 @Override
63 public String getScheme() {
64 return "jrt";
65 }
66
67 /**
68 * Need FilePermission ${java.home}/-", "read" to create or get jrt:/
69 */
70 private void checkPermission() {
71 SecurityManager sm = System.getSecurityManager();
72 if (sm != null) {
73 String home = SystemImage.RUNTIME_HOME;
74 FilePermission perm
75 = new FilePermission(home + File.separator + "-", "read");
76 sm.checkPermission(perm);
77 }
78 }
79
80 private void checkUri(URI uri) {
81 if (!uri.getScheme().equalsIgnoreCase(getScheme())) {
82 throw new IllegalArgumentException("URI does not match this provider");
83 }
84 if (uri.getAuthority() != null) {
85 throw new IllegalArgumentException("Authority component present");
86 }
87 if (uri.getPath() == null) {
88 throw new IllegalArgumentException("Path component is undefined");
89 }
90 if (!uri.getPath().equals("/")) {
91 throw new IllegalArgumentException("Path component should be '/'");
92 }
93 if (uri.getQuery() != null) {
94 throw new IllegalArgumentException("Query component present");
95 }
|
1 /*
2 * Copyright (c) 2016, 2017, 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
48 *
49 * @implNote This class needs to maintain JDK 8 source compatibility.
50 *
51 * It is used internally in the JDK to implement jimage/jrtfs access,
52 * but also compiled and delivered as part of the jrtfs.jar to support access
53 * to the jimage file provided by the shipped JDK by tools running on JDK 8.
54 */
55 public final class JrtFileSystemProvider extends FileSystemProvider {
56
57 private volatile FileSystem theFileSystem;
58
59 public JrtFileSystemProvider() {
60 }
61
62 @Override
63 public String getScheme() {
64 return "jrt";
65 }
66
67 /**
68 * Need RuntimePermission "accessSystemModules" to create or get jrt:/
69 */
70 private void checkPermission() {
71 SecurityManager sm = System.getSecurityManager();
72 if (sm != null) {
73 RuntimePermission perm = new RuntimePermission("accessSystemModules");
74 sm.checkPermission(perm);
75 }
76 }
77
78 private void checkUri(URI uri) {
79 if (!uri.getScheme().equalsIgnoreCase(getScheme())) {
80 throw new IllegalArgumentException("URI does not match this provider");
81 }
82 if (uri.getAuthority() != null) {
83 throw new IllegalArgumentException("Authority component present");
84 }
85 if (uri.getPath() == null) {
86 throw new IllegalArgumentException("Path component is undefined");
87 }
88 if (!uri.getPath().equals("/")) {
89 throw new IllegalArgumentException("Path component should be '/'");
90 }
91 if (uri.getQuery() != null) {
92 throw new IllegalArgumentException("Query component present");
93 }
|