|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | +package java.io; |
| 24 | + |
| 25 | +/** |
| 26 | + * Truffle-based implementation of {@link FileSystem}. |
| 27 | + * <p> |
| 28 | + * Its native methods are provided by Espresso's custom {@code libjava} implementation. |
| 29 | + * <p> |
| 30 | + * This file must be compatible with all Java versions supported by Espresso, strict Java 8 |
| 31 | + * compatibility is required. |
| 32 | + * |
| 33 | + */ |
| 34 | +final class TruffleFileSystem extends FileSystem { |
| 35 | + |
| 36 | + static { |
| 37 | + // Ensure the default file system is the correct one. |
| 38 | + FileSystem tfs = DefaultFileSystem.getFileSystem(); |
| 39 | + if (!(tfs instanceof TruffleFileSystem)) { |
| 40 | + throw new IncompatibleClassChangeError("Failed to set TruffleFileSystem as default file system."); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public char getSeparator() { |
| 46 | + return getSeparator0(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public char getPathSeparator() { |
| 51 | + return getPathSeparator0(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public String normalize(String path) { |
| 56 | + return normalize0(path); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public int prefixLength(String path) { |
| 61 | + return prefixLength0(path); |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public String resolve(String parent, String child) { |
| 66 | + return resolve0(parent, child); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public String getDefaultParent() { |
| 71 | + return getDefaultParent0(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public String fromURIPath(String path) { |
| 76 | + return fromURIPath0(path); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean isAbsolute(File f) { |
| 81 | + return isAbsolute0(f); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public boolean isInvalid(File f) { |
| 86 | + return isInvalid0(f); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public String resolve(File f) { |
| 91 | + return resolve0(f); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public String canonicalize(String path) throws IOException { |
| 96 | + return canonicalize0(path); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public int getBooleanAttributes(File f) { |
| 101 | + return getBooleanAttributes0(f); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public boolean checkAccess(File f, int access) { |
| 106 | + return checkAccess0(f, access); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public boolean setPermission(File f, int access, boolean enable, boolean owneronly) { |
| 111 | + return setPermission0(f, access, enable, owneronly); |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public long getLastModifiedTime(File f) { |
| 116 | + return getLastModifiedTime0(f); |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public long getLength(File f) { |
| 121 | + return getLength0(f); |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public boolean createFileExclusively(String pathname) throws IOException { |
| 126 | + return createFileExclusively0(pathname); |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public boolean delete(File f) { |
| 131 | + return delete0(f); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public String[] list(File f) { |
| 136 | + return list0(f); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public boolean createDirectory(File f) { |
| 141 | + return createDirectory0(f); |
| 142 | + } |
| 143 | + |
| 144 | + @Override |
| 145 | + public boolean rename(File f1, File f2) { |
| 146 | + return rename0(f1, f2); |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public boolean setLastModifiedTime(File f, long time) { |
| 151 | + return setLastModifiedTime0(f, time); |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public boolean setReadOnly(File f) { |
| 156 | + return setReadOnly0(f); |
| 157 | + } |
| 158 | + |
| 159 | + @Override |
| 160 | + public File[] listRoots() { |
| 161 | + return listRoots0(); |
| 162 | + } |
| 163 | + |
| 164 | + @Override |
| 165 | + public long getSpace(File f, int t) { |
| 166 | + return getSpace0(f, t); |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public int getNameMax(String path) { |
| 171 | + return getNameMax0(path); |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public int compare(File f1, File f2) { |
| 176 | + return compare0(f1, f2); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public int hashCode(File f) { |
| 181 | + return hashCode0(f); |
| 182 | + } |
| 183 | + |
| 184 | + private static native char getSeparator0(); |
| 185 | + |
| 186 | + private static native char getPathSeparator0(); |
| 187 | + |
| 188 | + private static native String normalize0(String path); |
| 189 | + |
| 190 | + private static native int prefixLength0(String path); |
| 191 | + |
| 192 | + private static native String resolve0(String parent, String child); |
| 193 | + |
| 194 | + private static native String getDefaultParent0(); |
| 195 | + |
| 196 | + private static native String fromURIPath0(String path); |
| 197 | + |
| 198 | + private static native boolean isAbsolute0(File f); |
| 199 | + |
| 200 | + private static native boolean isInvalid0(File f); |
| 201 | + |
| 202 | + private static native String resolve0(File f); |
| 203 | + |
| 204 | + private static native String canonicalize0(String path) throws IOException; |
| 205 | + |
| 206 | + private static native int getBooleanAttributes0(File f); |
| 207 | + |
| 208 | + private static native boolean checkAccess0(File f, int access); |
| 209 | + |
| 210 | + private static native boolean setPermission0(File f, int access, boolean enable, boolean owneronly); |
| 211 | + |
| 212 | + private static native long getLastModifiedTime0(File f); |
| 213 | + |
| 214 | + private static native long getLength0(File path); |
| 215 | + |
| 216 | + private static native boolean createFileExclusively0(String pathname) throws IOException; |
| 217 | + |
| 218 | + private static native boolean delete0(File path); |
| 219 | + |
| 220 | + private static native String[] list0(File path); |
| 221 | + |
| 222 | + private static native boolean createDirectory0(File f); |
| 223 | + |
| 224 | + private static native boolean rename0(File from, File to); |
| 225 | + |
| 226 | + private static native boolean setLastModifiedTime0(File path, long time); |
| 227 | + |
| 228 | + private static native boolean setReadOnly0(File f); |
| 229 | + |
| 230 | + private static native File[] listRoots0(); |
| 231 | + |
| 232 | + private static native long getSpace0(File f, int t); |
| 233 | + |
| 234 | + private static native int getNameMax0(String path); |
| 235 | + |
| 236 | + private static native int compare0(File f1, File f2); |
| 237 | + |
| 238 | + private static native int hashCode0(File f); |
| 239 | +} |
0 commit comments