Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/io/FileSystem.java
41152 views
1
/*
2
* Copyright (c) 1998, 2019, 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
* Resolve the given abstract pathname into absolute form. Invoked by the
92
* getAbsolutePath and getCanonicalPath methods in the File class.
93
*/
94
public abstract String resolve(File f);
95
96
public abstract String canonicalize(String path) throws IOException;
97
98
99
/* -- Attribute accessors -- */
100
101
/* Constants for simple boolean attributes */
102
@Native public static final int BA_EXISTS = 0x01;
103
@Native public static final int BA_REGULAR = 0x02;
104
@Native public static final int BA_DIRECTORY = 0x04;
105
@Native public static final int BA_HIDDEN = 0x08;
106
107
/**
108
* Return the simple boolean attributes for the file or directory denoted
109
* by the given abstract pathname, or zero if it does not exist or some
110
* other I/O error occurs.
111
*/
112
public abstract int getBooleanAttributes(File f);
113
114
/**
115
* Checks if all the given boolean attributes are true for the file or
116
* directory denoted by the given abstract pathname. False if it does not
117
* exist or some other I/O error occurs.
118
*/
119
public boolean hasBooleanAttributes(File f, int attributes) {
120
return (getBooleanAttributes(f) & attributes) == attributes;
121
}
122
123
@Native public static final int ACCESS_READ = 0x04;
124
@Native public static final int ACCESS_WRITE = 0x02;
125
@Native public static final int ACCESS_EXECUTE = 0x01;
126
127
/**
128
* Check whether the file or directory denoted by the given abstract
129
* pathname may be accessed by this process. The second argument specifies
130
* which access, ACCESS_READ, ACCESS_WRITE or ACCESS_EXECUTE, to check.
131
* Return false if access is denied or an I/O error occurs
132
*/
133
public abstract boolean checkAccess(File f, int access);
134
/**
135
* Set on or off the access permission (to owner only or to all) to the file
136
* or directory denoted by the given abstract pathname, based on the parameters
137
* enable, access and oweronly.
138
*/
139
public abstract boolean setPermission(File f, int access, boolean enable, boolean owneronly);
140
141
/**
142
* Return the time at which the file or directory denoted by the given
143
* abstract pathname was last modified, or zero if it does not exist or
144
* some other I/O error occurs.
145
*/
146
public abstract long getLastModifiedTime(File f);
147
148
/**
149
* Return the length in bytes of the file denoted by the given abstract
150
* pathname, or zero if it does not exist, is a directory, or some other
151
* I/O error occurs.
152
*/
153
public abstract long getLength(File f);
154
155
156
/* -- File operations -- */
157
158
/**
159
* Create a new empty file with the given pathname. Return
160
* {@code true} if the file was created and {@code false} if a
161
* file or directory with the given pathname already exists. Throw an
162
* IOException if an I/O error occurs.
163
*/
164
public abstract boolean createFileExclusively(String pathname)
165
throws IOException;
166
167
/**
168
* Delete the file or directory denoted by the given abstract pathname,
169
* returning {@code true} if and only if the operation succeeds.
170
*/
171
public abstract boolean delete(File f);
172
173
/**
174
* List the elements of the directory denoted by the given abstract
175
* pathname. Return an array of strings naming the elements of the
176
* directory if successful; otherwise, return {@code null}.
177
*/
178
public abstract String[] list(File f);
179
180
/**
181
* Create a new directory denoted by the given abstract pathname,
182
* returning {@code true} if and only if the operation succeeds.
183
*/
184
public abstract boolean createDirectory(File f);
185
186
/**
187
* Rename the file or directory denoted by the first abstract pathname to
188
* the second abstract pathname, returning {@code true} if and only if
189
* the operation succeeds.
190
*/
191
public abstract boolean rename(File f1, File f2);
192
193
/**
194
* Set the last-modified time of the file or directory denoted by the
195
* given abstract pathname, returning {@code true} if and only if the
196
* operation succeeds.
197
*/
198
public abstract boolean setLastModifiedTime(File f, long time);
199
200
/**
201
* Mark the file or directory denoted by the given abstract pathname as
202
* read-only, returning {@code true} if and only if the operation
203
* succeeds.
204
*/
205
public abstract boolean setReadOnly(File f);
206
207
208
/* -- Filesystem interface -- */
209
210
/**
211
* List the available filesystem roots.
212
*/
213
public abstract File[] listRoots();
214
215
/* -- Disk usage -- */
216
@Native public static final int SPACE_TOTAL = 0;
217
@Native public static final int SPACE_FREE = 1;
218
@Native public static final int SPACE_USABLE = 2;
219
220
public abstract long getSpace(File f, int t);
221
222
/* -- Basic infrastructure -- */
223
224
/**
225
* Retrieve the maximum length of a component of a file path.
226
*
227
* @return The maximum length of a file path component.
228
*/
229
public abstract int getNameMax(String path);
230
231
/**
232
* Compare two abstract pathnames lexicographically.
233
*/
234
public abstract int compare(File f1, File f2);
235
236
/**
237
* Compute the hash code of an abstract pathname.
238
*/
239
public abstract int hashCode(File f);
240
241
// Flags for enabling/disabling performance optimizations for file
242
// name canonicalization
243
static final boolean useCanonCaches;
244
static final boolean useCanonPrefixCache;
245
246
private static boolean getBooleanProperty(String prop, boolean defaultVal) {
247
String value = System.getProperty(prop);
248
return (value != null) ? Boolean.parseBoolean(value) : defaultVal;
249
}
250
251
static {
252
useCanonCaches = getBooleanProperty("sun.io.useCanonCaches", false);
253
useCanonPrefixCache = useCanonCaches && getBooleanProperty("sun.io.useCanonPrefixCache", false);
254
}
255
}
256
257