Path: blob/master/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributeView.java
41161 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.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.34*35* <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 class="striped">44* <caption style="display:none">Supported attributes</caption>45* <thead>46* <tr>47* <th scope="col"> Name </th>48* <th scope="col"> Type </th>49* </tr>50* </thead>51* <tbody>52* <tr>53* <th scope="row"> "lastModifiedTime" </th>54* <td> {@link FileTime} </td>55* </tr>56* <tr>57* <th scope="row"> "lastAccessTime" </th>58* <td> {@link FileTime} </td>59* </tr>60* <tr>61* <th scope="row"> "creationTime" </th>62* <td> {@link FileTime} </td>63* </tr>64* <tr>65* <th scope="row"> "size" </th>66* <td> {@link Long} </td>67* </tr>68* <tr>69* <th scope="row"> "isRegularFile" </th>70* <td> {@link Boolean} </td>71* </tr>72* <tr>73* <th scope="row"> "isDirectory" </th>74* <td> {@link Boolean} </td>75* </tr>76* <tr>77* <th scope="row"> "isSymbolicLink" </th>78* <td> {@link Boolean} </td>79* </tr>80* <tr>81* <th scope="row"> "isOther" </th>82* <td> {@link Boolean} </td>83* </tr>84* <tr>85* <th scope="row"> "fileKey" </th>86* <td> {@link Object} </td>87* </tr>88* </tbody>89* </table>90* </blockquote>91*92* <p> The {@link java.nio.file.Files#getAttribute getAttribute} method may be93* used to read any of these attributes as if by invoking the {@link94* #readAttributes() readAttributes()} method.95*96* <p> The {@link java.nio.file.Files#setAttribute setAttribute} method may be97* used to update the file's last modified time, last access time or create time98* attributes as if by invoking the {@link #setTimes setTimes} method.99*100* @since 1.7101*/102103public interface BasicFileAttributeView104extends FileAttributeView105{106/**107* Returns the name of the attribute view. Attribute views of this type108* have the name {@code "basic"}.109*/110@Override111String name();112113/**114* Reads the basic file attributes as a bulk operation.115*116* <p> It is implementation specific if all file attributes are read as an117* atomic operation with respect to other file system operations.118*119* @return the file attributes120*121* @throws IOException122* if an I/O error occurs123* @throws SecurityException124* In the case of the default provider, a security manager is125* installed, its {@link SecurityManager#checkRead(String) checkRead}126* method is invoked to check read access to the file127*/128BasicFileAttributes readAttributes() throws IOException;129130/**131* Updates any or all of the file's last modified time, last access time,132* and create time attributes.133*134* <p> This method updates the file's timestamp attributes. The values are135* converted to the epoch and precision supported by the file system.136* Converting from finer to coarser granularities result in precision loss.137* The behavior of this method when attempting to set a timestamp that is138* not supported or to a value that is outside the range supported by the139* underlying file store is not defined. It may or not fail by throwing an140* {@code IOException}.141*142* <p> If any of the {@code lastModifiedTime}, {@code lastAccessTime},143* or {@code createTime} parameters has the value {@code null} then the144* corresponding timestamp is not changed. An implementation may require to145* read the existing values of the file attributes when only some, but not146* all, of the timestamp attributes are updated. Consequently, this method147* may not be an atomic operation with respect to other file system148* operations. Reading and re-writing existing values may also result in149* precision loss. If all of the {@code lastModifiedTime}, {@code150* lastAccessTime} and {@code createTime} parameters are {@code null} then151* this method has no effect.152*153* <p> <b>Usage Example:</b>154* Suppose we want to change a file's last access time.155* <pre>156* Path path = ...157* FileTime time = ...158* Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes(null, time, null);159* </pre>160*161* @param lastModifiedTime162* the new last modified time, or {@code null} to not change the163* value164* @param lastAccessTime165* the last access time, or {@code null} to not change the value166* @param createTime167* the file's create time, or {@code null} to not change the value168*169* @throws IOException170* if an I/O error occurs171* @throws SecurityException172* In the case of the default provider, a security manager is173* installed, its {@link SecurityManager#checkWrite(String) checkWrite}174* method is invoked to check write access to the file175*176* @see java.nio.file.Files#setLastModifiedTime177*/178void setTimes(FileTime lastModifiedTime,179FileTime lastAccessTime,180FileTime createTime) throws IOException;181}182183184