|
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 |
|
30 /** |
|
31 * Basic attributes associated with a file in a file system. |
|
32 * |
|
33 * <p> Basic file attributes are attributes that are common to many file systems |
|
34 * and consist of mandatory and optional file attributes as defined by this |
|
35 * interface. |
|
36 * |
|
37 * <p> <b>Usage Example:</b> |
|
38 * <pre> |
|
39 * FileRef file = ... |
|
40 * BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file); |
|
41 * </pre> |
|
42 * |
|
43 * @since 1.7 |
|
44 * |
|
45 * @see BasicFileAttributeView |
|
46 */ |
|
47 |
|
48 public interface BasicFileAttributes { |
|
49 |
|
50 /** |
|
51 * Returns the time of last modification. |
|
52 * |
|
53 * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} |
|
54 * to interpret the return value of this method. |
|
55 * |
|
56 * @return A <code>long</code> value representing the time the file was |
|
57 * last modified since the epoch (00:00:00 GMT, January 1, 1970), |
|
58 * or {@code -1L} if the attribute is not supported. |
|
59 */ |
|
60 long lastModifiedTime(); |
|
61 |
|
62 /** |
|
63 * Returns the time of last access if supported. |
|
64 * |
|
65 * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} |
|
66 * to interpret the return value of this method. |
|
67 * |
|
68 * @return A <code>long</code> value representing the time of last access |
|
69 * since the epoch (00:00:00 GMT, January 1, 1970), or {@code -1L} |
|
70 * if the attribute is not supported. |
|
71 */ |
|
72 long lastAccessTime(); |
|
73 |
|
74 /** |
|
75 * Returns the creation time if supported. The creation time is the time |
|
76 * that the file was created. |
|
77 * |
|
78 * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} |
|
79 * to interpret the return value of this method. |
|
80 * |
|
81 * @return A <code>long</code> value representing the time the file was |
|
82 * created since the epoch (00:00:00 GMT, January 1, 1970), or |
|
83 * {@code -1L} if the attribute is not supported. |
|
84 */ |
|
85 long creationTime(); |
|
86 |
|
87 /** |
|
88 * Returns the {@link TimeUnit} required to interpret the time of last |
|
89 * modification, time of last access, and creation time. |
|
90 * |
|
91 * @return The {@code TimeUnit} required to interpret the file time stamps |
|
92 */ |
|
93 TimeUnit resolution(); |
|
94 |
|
95 /** |
|
96 * Tells whether the file is a regular file with opaque content. |
|
97 */ |
|
98 boolean isRegularFile(); |
|
99 |
|
100 /** |
|
101 * Tells whether the file is a directory. |
|
102 */ |
|
103 boolean isDirectory(); |
|
104 |
|
105 /** |
|
106 * Tells whether the file is a symbolic-link. |
|
107 */ |
|
108 boolean isSymbolicLink(); |
|
109 |
|
110 /** |
|
111 * Tells whether the file is something other than a regular file, directory, |
|
112 * or link. |
|
113 */ |
|
114 boolean isOther(); |
|
115 |
|
116 /** |
|
117 * Returns the size of the file (in bytes). The size may differ from the |
|
118 * actual size on the file system due to compression, support for sparse |
|
119 * files, or other reasons. The size of files that are not {@link |
|
120 * #isRegularFile regular} files is implementation specific and |
|
121 * therefore unspecified. |
|
122 * |
|
123 * @return The file size, in bytes |
|
124 */ |
|
125 long size(); |
|
126 |
|
127 /** |
|
128 * Returns the number of <em>links</em> to this file. |
|
129 * |
|
130 * <p> On file systems where the same file may be in several directories then |
|
131 * the link count is the number of directory entries for the file. The return |
|
132 * value is {@code 1} on file systems that only allow a file to have a |
|
133 * single name in a single directory. |
|
134 * |
|
135 * @see java.nio.file.Path#createLink |
|
136 */ |
|
137 int linkCount(); |
|
138 |
|
139 /** |
|
140 * Returns an object that uniquely identifies the given file, or {@code |
|
141 * null} if a file key is not available. On some platforms or file systems |
|
142 * it is possible to use an identifier, or a combination of identifiers to |
|
143 * uniquely identify a file. Such identifiers are important for operations |
|
144 * such as file tree traversal in file systems that support <a |
|
145 * href="../package-summary.html#links">symbolic links</a> or file systems |
|
146 * that allow a file to be an entry in more than one directory. On UNIX file |
|
147 * systems, for example, the <em>device ID</em> and <em>inode</em> are |
|
148 * commonly used for such purposes. |
|
149 * |
|
150 * <p> The file key returned by this method can only be guaranteed to be |
|
151 * unique if the file system and files remain static. Whether a file system |
|
152 * re-uses identifiers after a file is deleted is implementation dependent and |
|
153 * therefore unspecified. |
|
154 * |
|
155 * <p> File keys returned by this method can be compared for equality and are |
|
156 * suitable for use in collections. If the file system and files remain static, |
|
157 * and two files are the {@link java.nio.file.FileRef#isSameFile same} with |
|
158 * non-{@code null} file keys, then their file keys are equal. |
|
159 * |
|
160 * @see java.nio.file.Files#walkFileTree |
|
161 */ |
|
162 Object fileKey(); |
|
163 } |