893N/A/*
3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/Apackage java.nio.file;
893N/A
893N/Aimport java.nio.file.attribute.*;
1319N/Aimport java.io.IOException;
893N/A
893N/A/**
893N/A * Storage for files. A {@code FileStore} represents a storage pool, device,
893N/A * partition, volume, concrete file system or other implementation specific means
893N/A * of file storage. The {@code FileStore} for where a file is stored is obtained
3471N/A * by invoking the {@link Files#getFileStore getFileStore} method, or all file
893N/A * stores can be enumerated by invoking the {@link FileSystem#getFileStores
893N/A * getFileStores} method.
893N/A *
893N/A * <p> In addition to the methods defined by this class, a file store may support
893N/A * one or more {@link FileStoreAttributeView FileStoreAttributeView} classes
893N/A * that provide a read-only or updatable view of a set of file store attributes.
893N/A *
893N/A * @since 1.7
893N/A */
893N/A
893N/Apublic abstract class FileStore {
893N/A
893N/A /**
893N/A * Initializes a new instance of this class.
893N/A */
893N/A protected FileStore() {
893N/A }
893N/A
893N/A /**
893N/A * Returns the name of this file store. The format of the name is highly
893N/A * implementation specific. It will typically be the name of the storage
893N/A * pool or volume.
893N/A *
893N/A * <p> The string returned by this method may differ from the string
893N/A * returned by the {@link Object#toString() toString} method.
893N/A *
908N/A * @return the name of this file store
893N/A */
893N/A public abstract String name();
893N/A
893N/A /**
893N/A * Returns the <em>type</em> of this file store. The format of the string
893N/A * returned by this method is highly implementation specific. It may
893N/A * indicate, for example, the format used or if the file store is local
893N/A * or remote.
893N/A *
908N/A * @return a string representing the type of this file store
893N/A */
893N/A public abstract String type();
893N/A
893N/A /**
893N/A * Tells whether this file store is read-only. A file store is read-only if
893N/A * it does not support write operations or other changes to files. Any
893N/A * attempt to create a file, open an existing file for writing etc. causes
893N/A * an {@code IOException} to be thrown.
893N/A *
893N/A * @return {@code true} if, and only if, this file store is read-only
893N/A */
893N/A public abstract boolean isReadOnly();
893N/A
893N/A /**
3471N/A * Returns the size, in bytes, of the file store.
3471N/A *
3471N/A * @return the size of the file store, in bytes
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A */
3471N/A public abstract long getTotalSpace() throws IOException;
3471N/A
3471N/A /**
3471N/A * Returns the number of bytes available to this Java virtual machine on the
3471N/A * file store.
3471N/A *
3471N/A * <p> The returned number of available bytes is a hint, but not a
3471N/A * guarantee, that it is possible to use most or any of these bytes. The
3471N/A * number of usable bytes is most likely to be accurate immediately
3471N/A * after the space attributes are obtained. It is likely to be made inaccurate
3471N/A * by any external I/O operations including those made on the system outside
3471N/A * of this Java virtual machine.
3471N/A *
3471N/A * @return the number of bytes available
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A */
3471N/A public abstract long getUsableSpace() throws IOException;
3471N/A
3471N/A /**
3471N/A * Returns the number of unallocated bytes in the file store.
3471N/A *
3471N/A * <p> The returned number of unallocated bytes is a hint, but not a
3471N/A * guarantee, that it is possible to use most or any of these bytes. The
3471N/A * number of unallocated bytes is most likely to be accurate immediately
3471N/A * after the space attributes are obtained. It is likely to be
3471N/A * made inaccurate by any external I/O operations including those made on
3471N/A * the system outside of this virtual machine.
3471N/A *
3471N/A * @return the number of unallocated bytes
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A */
3471N/A public abstract long getUnallocatedSpace() throws IOException;
3471N/A
3471N/A /**
893N/A * Tells whether or not this file store supports the file attributes
893N/A * identified by the given file attribute view.
893N/A *
893N/A * <p> Invoking this method to test if the file store supports {@link
893N/A * BasicFileAttributeView} will always return {@code true}. In the case of
893N/A * the default provider, this method cannot guarantee to give the correct
893N/A * result when the file store is not a local storage device. The reasons for
893N/A * this are implementation specific and therefore unspecified.
893N/A *
893N/A * @param type
908N/A * the file attribute view type
893N/A *
893N/A * @return {@code true} if, and only if, the file attribute view is
893N/A * supported
893N/A */
893N/A public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type);
893N/A
893N/A /**
893N/A * Tells whether or not this file store supports the file attributes
893N/A * identified by the given file attribute view.
893N/A *
893N/A * <p> Invoking this method to test if the file store supports {@link
893N/A * BasicFileAttributeView}, identified by the name "{@code basic}" will
893N/A * always return {@code true}. In the case of the default provider, this
893N/A * method cannot guarantee to give the correct result when the file store is
893N/A * not a local storage device. The reasons for this are implementation
893N/A * specific and therefore unspecified.
893N/A *
893N/A * @param name
908N/A * the {@link FileAttributeView#name name} of file attribute view
893N/A *
893N/A * @return {@code true} if, and only if, the file attribute view is
893N/A * supported
893N/A */
893N/A public abstract boolean supportsFileAttributeView(String name);
893N/A
893N/A /**
893N/A * Returns a {@code FileStoreAttributeView} of the given type.
893N/A *
893N/A * <p> This method is intended to be used where the file store attribute
893N/A * view defines type-safe methods to read or update the file store attributes.
893N/A * The {@code type} parameter is the type of the attribute view required and
893N/A * the method returns an instance of that type if supported.
893N/A *
893N/A * @param type
908N/A * the {@code Class} object corresponding to the attribute view
893N/A *
908N/A * @return a file store attribute view of the specified type or
893N/A * {@code null} if the attribute view is not available
893N/A */
893N/A public abstract <V extends FileStoreAttributeView> V
893N/A getFileStoreAttributeView(Class<V> type);
893N/A
893N/A /**
1319N/A * Reads the value of a file store attribute.
893N/A *
1319N/A * <p> The {@code attribute} parameter identifies the attribute to be read
1319N/A * and takes the form:
1319N/A * <blockquote>
1319N/A * <i>view-name</i><b>:</b><i>attribute-name</i>
1319N/A * </blockquote>
1319N/A * where the character {@code ':'} stands for itself.
1319N/A *
1319N/A * <p> <i>view-name</i> is the {@link FileStoreAttributeView#name name} of
1319N/A * a {@link FileStore AttributeView} that identifies a set of file attributes.
1319N/A * <i>attribute-name</i> is the name of the attribute.
893N/A *
1319N/A * <p> <b>Usage Example:</b>
1319N/A * Suppose we want to know if ZFS compression is enabled (assuming the "zfs"
1319N/A * view is supported):
1319N/A * <pre>
1319N/A * boolean compression = (Boolean)fs.getAttribute("zfs:compression");
1319N/A * </pre>
893N/A *
1319N/A * @param attribute
1319N/A * the attribute to read
1319N/A
1319N/A * @return the attribute value; {@code null} may be a valid valid for some
1319N/A * attributes
893N/A *
1319N/A * @throws UnsupportedOperationException
1319N/A * if the attribute view is not available or it does not support
1319N/A * reading the attribute
1319N/A * @throws IOException
1319N/A * if an I/O error occurs
893N/A */
1319N/A public abstract Object getAttribute(String attribute) throws IOException;
893N/A}