jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java
changeset 2057 3acf8e5e2ca0
child 2072 80dfe4469bbd
equal deleted inserted replaced
2056:115e09b7a004 2057:3acf8e5e2ca0
       
     1 /*
       
     2  * Copyright 2007-2009 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package java.nio.file.attribute;
       
    27 
       
    28 import java.util.concurrent.TimeUnit;
       
    29 import java.io.IOException;
       
    30 
       
    31 /**
       
    32  * A file attribute view that provides a view of a <em>basic set</em> of file
       
    33  * attributes common to many file systems. The basic set of file attributes
       
    34  * consist of <em>mandatory</em> and <em>optional</em> file attributes as
       
    35  * defined by the {@link BasicFileAttributes} interface.
       
    36 
       
    37  * <p> The file attributes are retrieved from the file system as a <em>bulk
       
    38  * operation</em> by invoking the {@link #readAttributes() readAttributes} method.
       
    39  * This class also defines the {@link #setTimes setTimes} method to update the
       
    40  * file's time attributes.
       
    41  *
       
    42  * <p> Where dynamic access to file attributes is required, the attributes
       
    43  * supported by this attribute view have the following names and types:
       
    44  * <blockquote>
       
    45  *  <table border="1" cellpadding="8">
       
    46  *   <tr>
       
    47  *     <th> Name </th>
       
    48  *     <th> Type </th>
       
    49  *   </tr>
       
    50  *  <tr>
       
    51  *     <td> "lastModifiedTime" </td>
       
    52  *     <td> {@link Long} </td>
       
    53  *   </tr>
       
    54  *   <tr>
       
    55  *     <td> "lastAccessTime" </td>
       
    56  *     <td> {@link Long} </td>
       
    57  *   </tr>
       
    58  *   <tr>
       
    59  *     <td> "creationTime" </td>
       
    60  *     <td> {@link Long} </td>
       
    61  *   </tr>
       
    62  *  <tr>
       
    63  *     <td> "resolution" </td>
       
    64  *     <td> {@link java.util.concurrent.TimeUnit} </td>
       
    65  *   </tr>
       
    66  *   <tr>
       
    67  *     <td> "size" </td>
       
    68  *     <td> {@link Long} </td>
       
    69  *   </tr>
       
    70  *   <tr>
       
    71  *     <td> "isRegularFile" </td>
       
    72  *     <td> {@link Boolean} </td>
       
    73  *   </tr>
       
    74  *   <tr>
       
    75  *     <td> "isDirectory" </td>
       
    76  *     <td> {@link Boolean} </td>
       
    77  *   </tr>
       
    78  *   <tr>
       
    79  *     <td> "isSymbolicLink" </td>
       
    80  *     <td> {@link Boolean} </td>
       
    81  *   </tr>
       
    82  *   <tr>
       
    83  *     <td> "isOther" </td>
       
    84  *     <td> {@link Boolean} </td>
       
    85  *   </tr>
       
    86  *   <tr>
       
    87  *     <td> "linkCount" </td>
       
    88  *     <td> {@link Integer} </td>
       
    89  *   </tr>
       
    90  *   <tr>
       
    91  *     <td> "fileKey" </td>
       
    92  *     <td> {@link Object} </td>
       
    93  *   </tr>
       
    94  * </table>
       
    95  * </blockquote>
       
    96  *
       
    97  * <p> The {@link #getAttribute getAttribute} or {@link
       
    98  * #readAttributes(String,String[]) readAttributes(String,String[])} methods may
       
    99  * be used to read any of these attributes as if by invoking the {@link
       
   100  * #readAttributes() readAttributes()} method.
       
   101  *
       
   102  * <p> The {@link #setAttribute setAttribute} method may be used to update the
       
   103  * file's last modified time, last access time or create time attributes as if
       
   104  * by invoking the {@link #setTimes setTimes} method. In that case, the time
       
   105  * value is interpreted in {@link TimeUnit#MILLISECONDS milliseconds} and
       
   106  * converted to the precision supported by the file system.
       
   107  *
       
   108  * @since 1.7
       
   109  * @see Attributes
       
   110  */
       
   111 
       
   112 public interface BasicFileAttributeView
       
   113     extends FileAttributeView
       
   114 {
       
   115     /**
       
   116      * Returns the name of the attribute view. Attribute views of this type
       
   117      * have the name {@code "basic"}.
       
   118      */
       
   119     @Override
       
   120     String name();
       
   121 
       
   122     /**
       
   123      * Reads the basic file attributes as a bulk operation.
       
   124      *
       
   125      * <p> It is implementation specific if all file attributes are read as an
       
   126      * atomic operation with respect to other file system operations.
       
   127      *
       
   128      * @return  The file attributes
       
   129      *
       
   130      * @throws  IOException
       
   131      *          If an I/O error occurs
       
   132      * @throws  SecurityException
       
   133      *          In the case of the default provider, a security manager is
       
   134      *          installed, its {@link SecurityManager#checkRead(String) checkRead}
       
   135      *          method is invoked to check read access to the file
       
   136      */
       
   137     BasicFileAttributes readAttributes() throws IOException;
       
   138 
       
   139     /**
       
   140      * Updates any or all of the file's last modified time, last access time,
       
   141      * and create time attributes.
       
   142      *
       
   143      * <p> This method updates the file's timestamp attributes. The values are
       
   144      * measured since the epoch (00:00:00 GMT, January 1, 1970) and converted to
       
   145      * the precision supported by the file system. Converting from finer to
       
   146      * coarser granularities result in precision loss. If a value is larger
       
   147      * than the maximum supported by the file system then the corresponding
       
   148      * timestamp is set to its maximum value.
       
   149      *
       
   150      * <p> If any of the {@code lastModifiedTime}, {@code lastAccessTime},
       
   151      * or {@code createTime} parameters has the value {@code null} then the
       
   152      * corresponding timestamp is not changed. An implementation may require to
       
   153      * read the existing values of the file attributes when only some, but not
       
   154      * all, of the timestamp attributes are updated. Consequently, this method
       
   155      * may not be an atomic operation with respect to other file system
       
   156      * operations. If all of the {@code lastModifiedTime}, {@code
       
   157      * lastAccessTime} and {@code createTime} parameters are {@code null} then
       
   158      * this method has no effect.
       
   159      *
       
   160      * @param   lastModifiedTime
       
   161      *          The new last modified time, or {@code -1L} to update it to
       
   162      *          the current time, or {@code null} to not change the attribute
       
   163      * @param   lastAccessTime
       
   164      *          The last access time, or {@code -1L} to update it to
       
   165      *          the current time, or {@code null} to not change the attribute.
       
   166      * @param   createTime
       
   167      *          The file's create time, or {@code -1L} to update it to
       
   168      *          the current time, or {@code null} to not change the attribute
       
   169      * @param   unit
       
   170      *          A {@code TimeUnit} determining how to interpret the time values
       
   171      *
       
   172      * @throws  IllegalArgumentException
       
   173      *          If any of the parameters is a negative value other than {@code
       
   174      *          -1L}
       
   175      * @throws  IOException
       
   176      *          If an I/O error occurs
       
   177      * @throws  SecurityException
       
   178      *          In the case of the default provider, a security manager is
       
   179      *          installed, its  {@link SecurityManager#checkWrite(String) checkWrite}
       
   180      *          method is invoked to check write access to the file
       
   181      */
       
   182     void setTimes(Long lastModifiedTime,
       
   183                   Long lastAccessTime,
       
   184                   Long createTime,
       
   185                   TimeUnit unit) throws IOException;
       
   186 }