Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/share/classes/java/io/FileSystem.java
67794 views
1
/*
2
* Copyright (c) 1998, 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
23
* questions.
24
*/
25
26
package java.io;
27
28
import java.lang.annotation.Native;
29
30
/**
31
* Package-private abstract class for the local filesystem abstraction.
32
*/
33
34
abstract class FileSystem {
35
36
/* -- Normalization and construction -- */
37
38
/**
39
* Return the local filesystem's name-separator character.
40
*/
41
public abstract char getSeparator();
42
43
/**
44
* Return the local filesystem's path-separator character.
45
*/
46
public abstract char getPathSeparator();
47
48
/**
49
* Convert the given pathname string to normal form. If the string is
50
* already in normal form then it is simply returned.
51
*/
52
public abstract String normalize(String path);
53
54
/**
55
* Compute the length of this pathname string's prefix. The pathname
56
* string must be in normal form.
57
*/
58
public abstract int prefixLength(String path);
59
60
/**
61
* Resolve the child pathname string against the parent.
62
* Both strings must be in normal form, and the result
63
* will be in normal form.
64
*/
65
public abstract String resolve(String parent, String child);
66
67
/**
68
* Return the parent pathname string to be used when the parent-directory
69
* argument in one of the two-argument File constructors is the empty
70
* pathname.
71
*/
72
public abstract String getDefaultParent();
73
74
/**
75
* Post-process the given URI path string if necessary. This is used on
76
* win32, e.g., to transform "/c:/foo" into "c:/foo". The path string
77
* still has slash separators; code in the File class will translate them
78
* after this method returns.
79
*/
80
public abstract String fromURIPath(String path);
81
82
83
/* -- Path operations -- */
84
85
/**
86
* Tell whether or not the given abstract pathname is absolute.
87
*/
88
public abstract boolean isAbsolute(File f);
89
90
/**
91
* Tell whether the given abstract pathname is invalid.
92
*/
93
public abstract boolean isInvalid(File f);
94
95
/**
96
* Resolve the given abstract pathname into absolute form. Invoked by the
97
* getAbsolutePath and getCanonicalPath methods in the File class.
98
*/
99
public abstract String resolve(File f);
100
101
public abstract String canonicalize(String path) throws IOException;
102
103
104
/* -- Attribute accessors -- */
105
106
/* Constants for simple boolean attributes */
107
@Native public static final int BA_EXISTS = 0x01;
108
@Native public static final int BA_REGULAR = 0x02;
109
@Native public static final int BA_DIRECTORY = 0x04;
110
@Native public static final int BA_HIDDEN = 0x08;
111
112
/**
113
* Return the simple boolean attributes for the file or directory denoted
114
* by the given abstract pathname, or zero if it does not exist or some
115
* other I/O error occurs.
116
*/
117
public abstract int getBooleanAttributes(File f);
118
119
/**
120
* Checks if all the given boolean attributes are true for the file or
121
* directory denoted by the given abstract pathname. False if it does not
122
* exist or some other I/O error occurs.
123
*/
124
public boolean hasBooleanAttributes(File f, int attributes) {
125
return (getBooleanAttributes(f) & attributes) == attributes;
126
}
127
128
@Native public static final int ACCESS_READ = 0x04;
129
@Native public static final int ACCESS_WRITE = 0x02;
130
@Native public static final int ACCESS_EXECUTE = 0x01;
131
132
/**
133
* Check whether the file or directory denoted by the given abstract
134
* pathname may be accessed by this process. The second argument specifies
135
* which access, ACCESS_READ, ACCESS_WRITE or ACCESS_EXECUTE, to check.
136
* Return false if access is denied or an I/O error occurs
137
*/
138
public abstract boolean checkAccess(File f, int access);
139
/**
140
* Set on or off the access permission (to owner only or to all) to the file
141
* or directory denoted by the given abstract pathname, based on the parameters
142
* enable, access and oweronly.
143
*/
144
public abstract boolean setPermission(File f, int access, boolean enable, boolean owneronly);
145
146
/**
147
* Return the time at which the file or directory denoted by the given
148
* abstract pathname was last modified, or zero if it does not exist or
149
* some other I/O error occurs.
150
*/
151
public abstract long getLastModifiedTime(File f);
152
153
/**
154
* Return the length in bytes of the file denoted by the given abstract
155
* pathname, or zero if it does not exist, is a directory, or some other
156
* I/O error occurs.
157
*/
158
public abstract long getLength(File f);
159
160
161
/* -- File operations -- */
162
163
/**
164
* Create a new empty file with the given pathname. Return
165
* {@code true} if the file was created and {@code false} if a
166
* file or directory with the given pathname already exists. Throw an
167
* IOException if an I/O error occurs.
168
*/
169
public abstract boolean createFileExclusively(String pathname)
170
throws IOException;
171
172
/**
173
* Delete the file or directory denoted by the given abstract pathname,
174
* returning {@code true} if and only if the operation succeeds.
175
*/
176
public abstract boolean delete(File f);
177
178
/**
179
* List the elements of the directory denoted by the given abstract
180
* pathname. Return an array of strings naming the elements of the
181
* directory if successful; otherwise, return {@code null}.
182
*/
183
public abstract String[] list(File f);
184
185
/**
186
* Create a new directory denoted by the given abstract pathname,
187
* returning {@code true} if and only if the operation succeeds.
188
*/
189
public abstract boolean createDirectory(File f);
190
191
/**
192
* Rename the file or directory denoted by the first abstract pathname to
193
* the second abstract pathname, returning {@code true} if and only if
194
* the operation succeeds.
195
*/
196
public abstract boolean rename(File f1, File f2);
197
198
/**
199
* Set the last-modified time of the file or directory denoted by the
200
* given abstract pathname, returning {@code true} if and only if the
201
* operation succeeds.
202
*/
203
public abstract boolean setLastModifiedTime(File f, long time);
204
205
/**
206
* Mark the file or directory denoted by the given abstract pathname as
207
* read-only, returning {@code true} if and only if the operation
208
* succeeds.
209
*/
210
public abstract boolean setReadOnly(File f);
211
212
213
/* -- Filesystem interface -- */
214
215
/**
216
* List the available filesystem roots.
217
*/
218
public abstract File[] listRoots();
219
220
/* -- Disk usage -- */
221
@Native public static final int SPACE_TOTAL = 0;
222
@Native public static final int SPACE_FREE = 1;
223
@Native public static final int SPACE_USABLE = 2;
224
225
public abstract long getSpace(File f, int t);
226
227
/* -- Basic infrastructure -- */
228
229
/**
230
* Retrieve the maximum length of a component of a file path.
231
*
232
* @return The maximum length of a file path component.
233
*/
234
public abstract int getNameMax(String path);
235
236
/**
237
* Compare two abstract pathnames lexicographically.
238
*/
239
public abstract int compare(File f1, File f2);
240
241
/**
242
* Compute the hash code of an abstract pathname.
243
*/
244
public abstract int hashCode(File f);
245
246
// Flags for enabling/disabling performance optimizations for file
247
// name canonicalization
248
static final boolean useCanonCaches;
249
static final boolean useCanonPrefixCache;
250
251
private static boolean getBooleanProperty(String prop, boolean defaultVal) {
252
String value = System.getProperty(prop);
253
return (value != null) ? Boolean.parseBoolean(value) : defaultVal;
254
}
255
256
static {
257
useCanonCaches = getBooleanProperty("sun.io.useCanonCaches", false);
258
useCanonPrefixCache = useCanonCaches && getBooleanProperty("sun.io.useCanonPrefixCache", false);
259
}
260
}
261
262