Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.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.attribute;2627import java.io.IOException;2829/**30* A file attribute view that provides a view of a <em>basic set</em> of file31* attributes common to many file systems. The basic set of file attributes32* consist of <em>mandatory</em> and <em>optional</em> file attributes as33* defined by the {@link BasicFileAttributes} interface.3435* <p> The file attributes are retrieved from the file system as a <em>bulk36* operation</em> by invoking the {@link #readAttributes() readAttributes} method.37* This class also defines the {@link #setTimes setTimes} method to update the38* file's time attributes.39*40* <p> Where dynamic access to file attributes is required, the attributes41* supported by this attribute view have the following names and types:42* <blockquote>43* <table border="1" cellpadding="8" summary="Supported attributes">44* <tr>45* <th> Name </th>46* <th> Type </th>47* </tr>48* <tr>49* <td> "lastModifiedTime" </td>50* <td> {@link FileTime} </td>51* </tr>52* <tr>53* <td> "lastAccessTime" </td>54* <td> {@link FileTime} </td>55* </tr>56* <tr>57* <td> "creationTime" </td>58* <td> {@link FileTime} </td>59* </tr>60* <tr>61* <td> "size" </td>62* <td> {@link Long} </td>63* </tr>64* <tr>65* <td> "isRegularFile" </td>66* <td> {@link Boolean} </td>67* </tr>68* <tr>69* <td> "isDirectory" </td>70* <td> {@link Boolean} </td>71* </tr>72* <tr>73* <td> "isSymbolicLink" </td>74* <td> {@link Boolean} </td>75* </tr>76* <tr>77* <td> "isOther" </td>78* <td> {@link Boolean} </td>79* </tr>80* <tr>81* <td> "fileKey" </td>82* <td> {@link Object} </td>83* </tr>84* </table>85* </blockquote>86*87* <p> The {@link java.nio.file.Files#getAttribute getAttribute} method may be88* used to read any of these attributes as if by invoking the {@link89* #readAttributes() readAttributes()} method.90*91* <p> The {@link java.nio.file.Files#setAttribute setAttribute} method may be92* used to update the file's last modified time, last access time or create time93* attributes as if by invoking the {@link #setTimes setTimes} method.94*95* @since 1.796*/9798public interface BasicFileAttributeView99extends FileAttributeView100{101/**102* Returns the name of the attribute view. Attribute views of this type103* have the name {@code "basic"}.104*/105@Override106String name();107108/**109* Reads the basic file attributes as a bulk operation.110*111* <p> It is implementation specific if all file attributes are read as an112* atomic operation with respect to other file system operations.113*114* @return the file attributes115*116* @throws IOException117* if an I/O error occurs118* @throws SecurityException119* In the case of the default provider, a security manager is120* installed, its {@link SecurityManager#checkRead(String) checkRead}121* method is invoked to check read access to the file122*/123BasicFileAttributes readAttributes() throws IOException;124125/**126* Updates any or all of the file's last modified time, last access time,127* and create time attributes.128*129* <p> This method updates the file's timestamp attributes. The values are130* converted to the epoch and precision supported by the file system.131* Converting from finer to coarser granularities result in precision loss.132* The behavior of this method when attempting to set a timestamp that is133* not supported or to a value that is outside the range supported by the134* underlying file store is not defined. It may or not fail by throwing an135* {@code IOException}.136*137* <p> If any of the {@code lastModifiedTime}, {@code lastAccessTime},138* or {@code createTime} parameters has the value {@code null} then the139* corresponding timestamp is not changed. An implementation may require to140* read the existing values of the file attributes when only some, but not141* all, of the timestamp attributes are updated. Consequently, this method142* may not be an atomic operation with respect to other file system143* operations. Reading and re-writing existing values may also result in144* precision loss. If all of the {@code lastModifiedTime}, {@code145* lastAccessTime} and {@code createTime} parameters are {@code null} then146* this method has no effect.147*148* <p> <b>Usage Example:</b>149* Suppose we want to change a file's last access time.150* <pre>151* Path path = ...152* FileTime time = ...153* Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes(null, time, null);154* </pre>155*156* @param lastModifiedTime157* the new last modified time, or {@code null} to not change the158* value159* @param lastAccessTime160* the last access time, or {@code null} to not change the value161* @param createTime162* the file's create time, or {@code null} to not change the value163*164* @throws IOException165* if an I/O error occurs166* @throws SecurityException167* In the case of the default provider, a security manager is168* installed, its {@link SecurityManager#checkWrite(String) checkWrite}169* method is invoked to check write access to the file170*171* @see java.nio.file.Files#setLastModifiedTime172*/173void setTimes(FileTime lastModifiedTime,174FileTime lastAccessTime,175FileTime createTime) throws IOException;176}177178179