BasicFileAttributes.java 5.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * 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 12 13 14 15 16 17 18 19 20
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
24 25 26 27 28 29 30 31 32 33 34 35 36
 */

package java.nio.file.attribute;

/**
 * Basic attributes associated with a file in a file system.
 *
 * <p> Basic file attributes are attributes that are common to many file systems
 * and consist of mandatory and optional file attributes as defined by this
 * interface.
 *
 * <p> <b>Usage Example:</b>
 * <pre>
37 38
 *    Path file = ...
 *    BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
39 40 41 42 43 44 45 46 47 48 49 50
 * </pre>
 *
 * @since 1.7
 *
 * @see BasicFileAttributeView
 */

public interface BasicFileAttributes {

    /**
     * Returns the time of last modification.
     *
51 52 53 54 55
     * <p> If the file system implementation does not support a time stamp
     * to indicate the time of last modification then this method returns an
     * implementation specific default value, typically a {@code FileTime}
     * representing the epoch (1970-01-01T00:00:00Z).
     *
56
     * @return  a {@code FileTime} representing the time the file was last
57
     *          modified
58
     */
59
    FileTime lastModifiedTime();
60 61

    /**
62 63 64 65 66 67 68
     * Returns the time of last access.
     *
     * <p> If the file system implementation does not support a time stamp
     * to indicate the time of last access then this method returns
     * an implementation specific default value, typically the {@link
     * #lastModifiedTime() last-modified-time} or a {@code FileTime}
     * representing the epoch (1970-01-01T00:00:00Z).
69
     *
70
     * @return  a {@code FileTime} representing the time of last access
71
     */
72
    FileTime lastAccessTime();
73 74

    /**
75 76 77 78 79 80 81 82
     * Returns the creation time. The creation time is the time that the file
     * was created.
     *
     * <p> If the file system implementation does not support a time stamp
     * to indicate the time when the file was created then this method returns
     * an implementation specific default value, typically the {@link
     * #lastModifiedTime() last-modified-time} or a {@code FileTime}
     * representing the epoch (1970-01-01T00:00:00Z).
83
     *
84
     * @return   a {@code FileTime} representing the time the file was created
85
     */
86
    FileTime creationTime();
87 88 89

    /**
     * Tells whether the file is a regular file with opaque content.
90 91
     *
     * @return {@code true} if the file is a regular file with opaque content
92 93 94 95 96
     */
    boolean isRegularFile();

    /**
     * Tells whether the file is a directory.
97 98
     *
     * @return {@code true} if the file is a directory
99 100 101 102
     */
    boolean isDirectory();

    /**
103
     * Tells whether the file is a symbolic link.
104 105
     *
     * @return {@code true} if the file is a symbolic link
106 107 108 109 110
     */
    boolean isSymbolicLink();

    /**
     * Tells whether the file is something other than a regular file, directory,
111
     * or symbolic link.
112 113 114
     *
     * @return {@code true} if the file something other than a regular file,
     *         directory or symbolic link
115 116 117 118 119 120 121 122 123 124
     */
    boolean isOther();

    /**
     * Returns the size of the file (in bytes). The size may differ from the
     * actual size on the file system due to compression, support for sparse
     * files, or other reasons. The size of files that are not {@link
     * #isRegularFile regular} files is implementation specific and
     * therefore unspecified.
     *
125
     * @return  the file size, in bytes
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
     */
    long size();

    /**
     * Returns an object that uniquely identifies the given file, or {@code
     * null} if a file key is not available. On some platforms or file systems
     * it is possible to use an identifier, or a combination of identifiers to
     * uniquely identify a file. Such identifiers are important for operations
     * such as file tree traversal in file systems that support <a
     * href="../package-summary.html#links">symbolic links</a> or file systems
     * that allow a file to be an entry in more than one directory. On UNIX file
     * systems, for example, the <em>device ID</em> and <em>inode</em> are
     * commonly used for such purposes.
     *
     * <p> The file key returned by this method can only be guaranteed to be
     * unique if the file system and files remain static. Whether a file system
     * re-uses identifiers after a file is deleted is implementation dependent and
     * therefore unspecified.
     *
     * <p> File keys returned by this method can be compared for equality and are
     * suitable for use in collections. If the file system and files remain static,
147
     * and two files are the {@link java.nio.file.Files#isSameFile same} with
148 149
     * non-{@code null} file keys, then their file keys are equal.
     *
150 151
     * @return an object that uniquely identifies the given file, or {@code null}
     *
152 153 154 155
     * @see java.nio.file.Files#walkFileTree
     */
    Object fileKey();
}