Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/file/FileStore.java
38918 views
/*1* Copyright (c) 2007, 2013, 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.87*88* @return the size of the file store, in bytes89*90* @throws IOException91* if an I/O error occurs92*/93public abstract long getTotalSpace() throws IOException;9495/**96* Returns the number of bytes available to this Java virtual machine on the97* file store.98*99* <p> The returned number of available bytes is a hint, but not a100* guarantee, that it is possible to use most or any of these bytes. The101* number of usable bytes is most likely to be accurate immediately102* after the space attributes are obtained. It is likely to be made inaccurate103* by any external I/O operations including those made on the system outside104* of this Java virtual machine.105*106* @return the number of bytes available107*108* @throws IOException109* if an I/O error occurs110*/111public abstract long getUsableSpace() throws IOException;112113/**114* Returns the number of unallocated bytes in the file store.115*116* <p> The returned number of unallocated bytes is a hint, but not a117* guarantee, that it is possible to use most or any of these bytes. The118* number of unallocated bytes is most likely to be accurate immediately119* after the space attributes are obtained. It is likely to be120* made inaccurate by any external I/O operations including those made on121* the system outside of this virtual machine.122*123* @return the number of unallocated bytes124*125* @throws IOException126* if an I/O error occurs127*/128public abstract long getUnallocatedSpace() throws IOException;129130/**131* Tells whether or not this file store supports the file attributes132* identified by the given file attribute view.133*134* <p> Invoking this method to test if the file store supports {@link135* BasicFileAttributeView} will always return {@code true}. In the case of136* the default provider, this method cannot guarantee to give the correct137* result when the file store is not a local storage device. The reasons for138* this are implementation specific and therefore unspecified.139*140* @param type141* the file attribute view type142*143* @return {@code true} if, and only if, the file attribute view is144* supported145*/146public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type);147148/**149* Tells whether or not this file store supports the file attributes150* identified by the given file attribute view.151*152* <p> Invoking this method to test if the file store supports {@link153* BasicFileAttributeView}, identified by the name "{@code basic}" will154* always return {@code true}. In the case of the default provider, this155* method cannot guarantee to give the correct result when the file store is156* not a local storage device. The reasons for this are implementation157* specific and therefore unspecified.158*159* @param name160* the {@link FileAttributeView#name name} of file attribute view161*162* @return {@code true} if, and only if, the file attribute view is163* supported164*/165public abstract boolean supportsFileAttributeView(String name);166167/**168* Returns a {@code FileStoreAttributeView} of the given type.169*170* <p> This method is intended to be used where the file store attribute171* view defines type-safe methods to read or update the file store attributes.172* The {@code type} parameter is the type of the attribute view required and173* the method returns an instance of that type if supported.174*175* @param <V>176* The {@code FileStoreAttributeView} type177* @param type178* the {@code Class} object corresponding to the attribute view179*180* @return a file store attribute view of the specified type or181* {@code null} if the attribute view is not available182*/183public abstract <V extends FileStoreAttributeView> V184getFileStoreAttributeView(Class<V> type);185186/**187* Reads the value of a file store attribute.188*189* <p> The {@code attribute} parameter identifies the attribute to be read190* and takes the form:191* <blockquote>192* <i>view-name</i><b>:</b><i>attribute-name</i>193* </blockquote>194* where the character {@code ':'} stands for itself.195*196* <p> <i>view-name</i> is the {@link FileStoreAttributeView#name name} of197* a {@link FileStore AttributeView} that identifies a set of file attributes.198* <i>attribute-name</i> is the name of the attribute.199*200* <p> <b>Usage Example:</b>201* Suppose we want to know if ZFS compression is enabled (assuming the "zfs"202* view is supported):203* <pre>204* boolean compression = (Boolean)fs.getAttribute("zfs:compression");205* </pre>206*207* @param attribute208* the attribute to read209210* @return the attribute value; {@code null} may be a valid valid for some211* attributes212*213* @throws UnsupportedOperationException214* if the attribute view is not available or it does not support215* reading the attribute216* @throws IOException217* if an I/O error occurs218*/219public abstract Object getAttribute(String attribute) throws IOException;220}221222223