Path: blob/master/src/java.base/share/classes/java/nio/file/FileStore.java
41159 views
/*1* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.file;2627import java.nio.file.attribute.*;28import java.io.IOException;2930/**31* Storage for files. A {@code FileStore} represents a storage pool, device,32* partition, volume, concrete file system or other implementation specific means33* of file storage. The {@code FileStore} for where a file is stored is obtained34* by invoking the {@link Files#getFileStore getFileStore} method, or all file35* stores can be enumerated by invoking the {@link FileSystem#getFileStores36* getFileStores} method.37*38* <p> In addition to the methods defined by this class, a file store may support39* one or more {@link FileStoreAttributeView FileStoreAttributeView} classes40* that provide a read-only or updatable view of a set of file store attributes.41*42* @since 1.743*/4445public abstract class FileStore {4647/**48* Initializes a new instance of this class.49*/50protected FileStore() {51}5253/**54* Returns the name of this file store. The format of the name is highly55* implementation specific. It will typically be the name of the storage56* pool or volume.57*58* <p> The string returned by this method may differ from the string59* returned by the {@link Object#toString() toString} method.60*61* @return the name of this file store62*/63public abstract String name();6465/**66* Returns the <em>type</em> of this file store. The format of the string67* returned by this method is highly implementation specific. It may68* indicate, for example, the format used or if the file store is local69* or remote.70*71* @return a string representing the type of this file store72*/73public abstract String type();7475/**76* Tells whether this file store is read-only. A file store is read-only if77* it does not support write operations or other changes to files. Any78* attempt to create a file, open an existing file for writing etc. causes79* an {@code IOException} to be thrown.80*81* @return {@code true} if, and only if, this file store is read-only82*/83public abstract boolean isReadOnly();8485/**86* Returns the size, in bytes, of the file store. If the total number of87* bytes in the file store is greater than {@link Long#MAX_VALUE}, then88* {@code Long.MAX_VALUE} will be returned.89*90* @return the size of the file store, in bytes91*92* @throws IOException93* if an I/O error occurs94*/95public abstract long getTotalSpace() throws IOException;9697/**98* Returns the number of bytes available to this Java virtual machine on the99* file store. If the number of bytes available is greater than100* {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.101*102* <p> The returned number of available bytes is a hint, but not a103* guarantee, that it is possible to use most or any of these bytes. The104* number of usable bytes is most likely to be accurate immediately105* after the space attributes are obtained. It is likely to be made inaccurate106* by any external I/O operations including those made on the system outside107* of this Java virtual machine.108*109* @return the number of bytes available110*111* @throws IOException112* if an I/O error occurs113*/114public abstract long getUsableSpace() throws IOException;115116/**117* Returns the number of unallocated bytes in the file store.118* If the number of unallocated bytes is greater than119* {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned.120*121* <p> The returned number of unallocated bytes is a hint, but not a122* guarantee, that it is possible to use most or any of these bytes. The123* number of unallocated bytes is most likely to be accurate immediately124* after the space attributes are obtained. It is likely to be125* made inaccurate by any external I/O operations including those made on126* the system outside of this virtual machine.127*128* @return the number of unallocated bytes129*130* @throws IOException131* if an I/O error occurs132*/133public abstract long getUnallocatedSpace() throws IOException;134135/**136* Returns the number of bytes per block in this file store.137*138* <p> File storage is typically organized into discrete sequences of bytes139* called <i>blocks</i>. A block is the smallest storage unit of a file store.140* Every read and write operation is performed on a multiple of blocks.141*142* @implSpec The implementation in this class throws143* {@code UnsupportedOperationException}.144*145* @return a positive value representing the block size of this file store,146* in bytes147*148* @throws IOException149* if an I/O error occurs150*151* @throws UnsupportedOperationException152* if the operation is not supported153*154* @since 10155*/156public long getBlockSize() throws IOException {157throw new UnsupportedOperationException();158}159160/**161* Tells whether or not this file store supports the file attributes162* identified by the given file attribute view.163*164* <p> Invoking this method to test if the file store supports {@link165* BasicFileAttributeView} will always return {@code true}. In the case of166* the default provider, this method cannot guarantee to give the correct167* result when the file store is not a local storage device. The reasons for168* this are implementation specific and therefore unspecified.169*170* @param type171* the file attribute view type172*173* @return {@code true} if, and only if, the file attribute view is174* supported175*/176public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type);177178/**179* Tells whether or not this file store supports the file attributes180* identified by the given file attribute view.181*182* <p> Invoking this method to test if the file store supports {@link183* BasicFileAttributeView}, identified by the name "{@code basic}" will184* always return {@code true}. In the case of the default provider, this185* method cannot guarantee to give the correct result when the file store is186* not a local storage device. The reasons for this are implementation187* specific and therefore unspecified.188*189* @param name190* the {@link FileAttributeView#name name} of file attribute view191*192* @return {@code true} if, and only if, the file attribute view is193* supported194*/195public abstract boolean supportsFileAttributeView(String name);196197/**198* Returns a {@code FileStoreAttributeView} of the given type.199*200* <p> This method is intended to be used where the file store attribute201* view defines type-safe methods to read or update the file store attributes.202* The {@code type} parameter is the type of the attribute view required and203* the method returns an instance of that type if supported.204*205* @param <V>206* The {@code FileStoreAttributeView} type207* @param type208* the {@code Class} object corresponding to the attribute view209*210* @return a file store attribute view of the specified type or211* {@code null} if the attribute view is not available212*/213public abstract <V extends FileStoreAttributeView> V214getFileStoreAttributeView(Class<V> type);215216/**217* Reads the value of a file store attribute.218*219* <p> The {@code attribute} parameter identifies the attribute to be read220* and takes the form:221* <blockquote>222* <i>view-name</i><b>:</b><i>attribute-name</i>223* </blockquote>224* where the character {@code ':'} stands for itself.225*226* <p> <i>view-name</i> is the {@link FileStoreAttributeView#name name} of227* a {@link FileStore AttributeView} that identifies a set of file attributes.228* <i>attribute-name</i> is the name of the attribute.229*230* <p> <b>Usage Example:</b>231* Suppose we want to know if ZFS compression is enabled (assuming the "zfs"232* view is supported):233* <pre>234* boolean compression = (Boolean)fs.getAttribute("zfs:compression");235* </pre>236*237* @param attribute238* the attribute to read239*240* @return the attribute value; {@code null} may be valid for some241* attributes242*243* @throws UnsupportedOperationException244* if the attribute view is not available or it does not support245* reading the attribute246* @throws IOException247* if an I/O error occurs248*/249public abstract Object getAttribute(String attribute) throws IOException;250}251252253