Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/nio/file/FileStore.java
41159 views
1
/*
2
* Copyright (c) 2007, 2020, 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.nio.file;
27
28
import java.nio.file.attribute.*;
29
import java.io.IOException;
30
31
/**
32
* Storage for files. A {@code FileStore} represents a storage pool, device,
33
* partition, volume, concrete file system or other implementation specific means
34
* of file storage. The {@code FileStore} for where a file is stored is obtained
35
* by invoking the {@link Files#getFileStore getFileStore} method, or all file
36
* stores can be enumerated by invoking the {@link FileSystem#getFileStores
37
* getFileStores} method.
38
*
39
* <p> In addition to the methods defined by this class, a file store may support
40
* one or more {@link FileStoreAttributeView FileStoreAttributeView} classes
41
* that provide a read-only or updatable view of a set of file store attributes.
42
*
43
* @since 1.7
44
*/
45
46
public abstract class FileStore {
47
48
/**
49
* Initializes a new instance of this class.
50
*/
51
protected FileStore() {
52
}
53
54
/**
55
* Returns the name of this file store. The format of the name is highly
56
* implementation specific. It will typically be the name of the storage
57
* pool or volume.
58
*
59
* <p> The string returned by this method may differ from the string
60
* returned by the {@link Object#toString() toString} method.
61
*
62
* @return the name of this file store
63
*/
64
public abstract String name();
65
66
/**
67
* Returns the <em>type</em> of this file store. The format of the string
68
* returned by this method is highly implementation specific. It may
69
* indicate, for example, the format used or if the file store is local
70
* or remote.
71
*
72
* @return a string representing the type of this file store
73
*/
74
public abstract String type();
75
76
/**
77
* Tells whether this file store is read-only. A file store is read-only if
78
* it does not support write operations or other changes to files. Any
79
* attempt to create a file, open an existing file for writing etc. causes
80
* an {@code IOException} to be thrown.
81
*
82
* @return {@code true} if, and only if, this file store is read-only
83
*/
84
public abstract boolean isReadOnly();
85
86
/**
87
* Returns the size, in bytes, of the file store. If the total number of
88
* bytes in the file store is greater than {@link Long#MAX_VALUE}, then
89
* {@code Long.MAX_VALUE} will be returned.
90
*
91
* @return the size of the file store, in bytes
92
*
93
* @throws IOException
94
* if an I/O error occurs
95
*/
96
public abstract long getTotalSpace() throws IOException;
97
98
/**
99
* Returns the number of bytes available to this Java virtual machine on the
100
* file store. If the number of bytes available is greater than
101
* {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.
102
*
103
* <p> The returned number of available bytes is a hint, but not a
104
* guarantee, that it is possible to use most or any of these bytes. The
105
* number of usable bytes is most likely to be accurate immediately
106
* after the space attributes are obtained. It is likely to be made inaccurate
107
* by any external I/O operations including those made on the system outside
108
* of this Java virtual machine.
109
*
110
* @return the number of bytes available
111
*
112
* @throws IOException
113
* if an I/O error occurs
114
*/
115
public abstract long getUsableSpace() throws IOException;
116
117
/**
118
* Returns the number of unallocated bytes in the file store.
119
* If the number of unallocated bytes is greater than
120
* {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.
121
*
122
* <p> The returned number of unallocated bytes is a hint, but not a
123
* guarantee, that it is possible to use most or any of these bytes. The
124
* number of unallocated bytes is most likely to be accurate immediately
125
* after the space attributes are obtained. It is likely to be
126
* made inaccurate by any external I/O operations including those made on
127
* the system outside of this virtual machine.
128
*
129
* @return the number of unallocated bytes
130
*
131
* @throws IOException
132
* if an I/O error occurs
133
*/
134
public abstract long getUnallocatedSpace() throws IOException;
135
136
/**
137
* Returns the number of bytes per block in this file store.
138
*
139
* <p> File storage is typically organized into discrete sequences of bytes
140
* called <i>blocks</i>. A block is the smallest storage unit of a file store.
141
* Every read and write operation is performed on a multiple of blocks.
142
*
143
* @implSpec The implementation in this class throws
144
* {@code UnsupportedOperationException}.
145
*
146
* @return a positive value representing the block size of this file store,
147
* in bytes
148
*
149
* @throws IOException
150
* if an I/O error occurs
151
*
152
* @throws UnsupportedOperationException
153
* if the operation is not supported
154
*
155
* @since 10
156
*/
157
public long getBlockSize() throws IOException {
158
throw new UnsupportedOperationException();
159
}
160
161
/**
162
* Tells whether or not this file store supports the file attributes
163
* identified by the given file attribute view.
164
*
165
* <p> Invoking this method to test if the file store supports {@link
166
* BasicFileAttributeView} will always return {@code true}. In the case of
167
* the default provider, this method cannot guarantee to give the correct
168
* result when the file store is not a local storage device. The reasons for
169
* this are implementation specific and therefore unspecified.
170
*
171
* @param type
172
* the file attribute view type
173
*
174
* @return {@code true} if, and only if, the file attribute view is
175
* supported
176
*/
177
public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type);
178
179
/**
180
* Tells whether or not this file store supports the file attributes
181
* identified by the given file attribute view.
182
*
183
* <p> Invoking this method to test if the file store supports {@link
184
* BasicFileAttributeView}, identified by the name "{@code basic}" will
185
* always return {@code true}. In the case of the default provider, this
186
* method cannot guarantee to give the correct result when the file store is
187
* not a local storage device. The reasons for this are implementation
188
* specific and therefore unspecified.
189
*
190
* @param name
191
* the {@link FileAttributeView#name name} of file attribute view
192
*
193
* @return {@code true} if, and only if, the file attribute view is
194
* supported
195
*/
196
public abstract boolean supportsFileAttributeView(String name);
197
198
/**
199
* Returns a {@code FileStoreAttributeView} of the given type.
200
*
201
* <p> This method is intended to be used where the file store attribute
202
* view defines type-safe methods to read or update the file store attributes.
203
* The {@code type} parameter is the type of the attribute view required and
204
* the method returns an instance of that type if supported.
205
*
206
* @param <V>
207
* The {@code FileStoreAttributeView} type
208
* @param type
209
* the {@code Class} object corresponding to the attribute view
210
*
211
* @return a file store attribute view of the specified type or
212
* {@code null} if the attribute view is not available
213
*/
214
public abstract <V extends FileStoreAttributeView> V
215
getFileStoreAttributeView(Class<V> type);
216
217
/**
218
* Reads the value of a file store attribute.
219
*
220
* <p> The {@code attribute} parameter identifies the attribute to be read
221
* and takes the form:
222
* <blockquote>
223
* <i>view-name</i><b>:</b><i>attribute-name</i>
224
* </blockquote>
225
* where the character {@code ':'} stands for itself.
226
*
227
* <p> <i>view-name</i> is the {@link FileStoreAttributeView#name name} of
228
* a {@link FileStore AttributeView} that identifies a set of file attributes.
229
* <i>attribute-name</i> is the name of the attribute.
230
*
231
* <p> <b>Usage Example:</b>
232
* Suppose we want to know if ZFS compression is enabled (assuming the "zfs"
233
* view is supported):
234
* <pre>
235
* boolean compression = (Boolean)fs.getAttribute("zfs:compression");
236
* </pre>
237
*
238
* @param attribute
239
* the attribute to read
240
*
241
* @return the attribute value; {@code null} may be valid for some
242
* attributes
243
*
244
* @throws UnsupportedOperationException
245
* if the attribute view is not available or it does not support
246
* reading the attribute
247
* @throws IOException
248
* if an I/O error occurs
249
*/
250
public abstract Object getAttribute(String attribute) throws IOException;
251
}
252
253