1 /*
2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.nio.file.attribute;
27 
28 import java.io.IOException;
29 
30 /**
31  * A file attribute view that provides a view of the legacy "DOS" file attributes.
32  * These attributes are supported by file systems such as the File Allocation
33  * Table (FAT) format commonly used in <em>consumer devices</em>.
34  *
35  * <p> A {@code DosFileAttributeView} is a {@link BasicFileAttributeView} that
36  * additionally supports access to the set of DOS attribute flags that are used
37  * to indicate if the file is read-only, hidden, a system file, or archived.
38  *
39  * <p> Where dynamic access to file attributes is required, the attributes
40  * supported by this attribute view are as defined by {@code
41  * BasicFileAttributeView}, and in addition, the following attributes are
42  * supported:
43  * <blockquote>
44  * <table border="1" cellpadding="8" summary="Supported attributes">
45  *   <tr>
46  *     <th> Name </th>
47  *     <th> Type </th>
48  *   </tr>
49  *   <tr>
50  *     <td> readonly </td>
51  *     <td> {@link Boolean} </td>
52  *   </tr>
53  *   <tr>
54  *     <td> hidden </td>
55  *     <td> {@link Boolean} </td>
56  *   </tr>
57  *   <tr>
58  *     <td> system </td>
59  *     <td> {@link Boolean} </td>
60  *   </tr>
61  *   <tr>
62  *     <td> archive </td>
63  *     <td> {@link Boolean} </td>
64  *   </tr>
65  * </table>
66  * </blockquote>
67  *
68  * <p> The {@link java.nio.file.Files#getAttribute getAttribute} method may
69  * be used to read any of these attributes, or any of the attributes defined by
70  * {@link BasicFileAttributeView} as if by invoking the {@link #readAttributes
71  * readAttributes()} method.
72  *
73  * <p> The {@link java.nio.file.Files#setAttribute setAttribute} method may
74  * be used to update the file's last modified time, last access time or create
75  * time attributes as defined by {@link BasicFileAttributeView}. It may also be
76  * used to update the DOS attributes as if by invoking the {@link #setReadOnly
77  * setReadOnly}, {@link #setHidden setHidden}, {@link #setSystem setSystem}, and
78  * {@link #setArchive setArchive} methods respectively.
79  *
80  * @since 1.7
81  */
82 
83 public interface DosFileAttributeView
84     extends BasicFileAttributeView
85 {
86     /**
87      * Returns the name of the attribute view. Attribute views of this type
88      * have the name {@code "dos"}.
89      */
90     @Override
name()91     String name();
92 
93     /**
94      * @throws  IOException                             {@inheritDoc}
95      * @throws  SecurityException                       {@inheritDoc}
96      */
97     @Override
readAttributes()98     DosFileAttributes readAttributes() throws IOException;
99 
100     /**
101      * Updates the value of the read-only attribute.
102      *
103      * <p> It is implementation specific if the attribute can be updated as an
104      * atomic operation with respect to other file system operations. An
105      * implementation may, for example, require to read the existing value of
106      * the DOS attribute in order to update this attribute.
107      *
108      * @param   value
109      *          the new value of the attribute
110      *
111      * @throws  IOException
112      *          if an I/O error occurs
113      * @throws  SecurityException
114      *          In the case of the default, and a security manager is installed,
115      *          its  {@link SecurityManager#checkWrite(String) checkWrite} method
116      *          is invoked to check write access to the file
117      */
setReadOnly(boolean value)118     void setReadOnly(boolean value) throws IOException;
119 
120     /**
121      * Updates the value of the hidden attribute.
122      *
123      * <p> It is implementation specific if the attribute can be updated as an
124      * atomic operation with respect to other file system operations. An
125      * implementation may, for example, require to read the existing value of
126      * the DOS attribute in order to update this attribute.
127      *
128      * @param   value
129      *          the new value of the attribute
130      *
131      * @throws  IOException
132      *          if an I/O error occurs
133      * @throws  SecurityException
134      *          In the case of the default, and a security manager is installed,
135      *          its  {@link SecurityManager#checkWrite(String) checkWrite} method
136      *          is invoked to check write access to the file
137      */
setHidden(boolean value)138     void setHidden(boolean value) throws IOException;
139 
140     /**
141      * Updates the value of the system attribute.
142      *
143      * <p> It is implementation specific if the attribute can be updated as an
144      * atomic operation with respect to other file system operations. An
145      * implementation may, for example, require to read the existing value of
146      * the DOS attribute in order to update this attribute.
147      *
148      * @param   value
149      *          the new value of the attribute
150      *
151      * @throws  IOException
152      *          if an I/O error occurs
153      * @throws  SecurityException
154      *          In the case of the default, and a security manager is installed,
155      *          its  {@link SecurityManager#checkWrite(String) checkWrite} method
156      *          is invoked to check write access to the file
157      */
setSystem(boolean value)158     void setSystem(boolean value) throws IOException;
159 
160     /**
161      * Updates the value of the archive attribute.
162      *
163      * <p> It is implementation specific if the attribute can be updated as an
164      * atomic operation with respect to other file system operations. An
165      * implementation may, for example, require to read the existing value of
166      * the DOS attribute in order to update this attribute.
167      *
168      * @param   value
169      *          the new value of the attribute
170      *
171      * @throws  IOException
172      *          if an I/O error occurs
173      * @throws  SecurityException
174      *          In the case of the default, and a security manager is installed,
175      *          its  {@link SecurityManager#checkWrite(String) checkWrite} method
176      *          is invoked to check write access to the file
177      */
setArchive(boolean value)178     void setArchive(boolean value) throws IOException;
179 }
180