BasicFileAttributes.java 4.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2007, 2009, 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 */

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>
 *    FileRef file = ...
 *    BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file);
 * </pre>
 *
 * @since 1.7
 *
 * @see BasicFileAttributeView
 */

public interface BasicFileAttributes {

    /**
     * Returns the time of last modification.
     *
51 52
     * @return  a {@code FileTime} representing the time the file was last
     *          modified or {@code null} if the attribute is not supported.
53
     */
54
    FileTime lastModifiedTime();
55 56 57 58

    /**
     * Returns the time of last access if supported.
     *
59 60
     * @return  a {@code FileTime} representing the time of last access or
     *          {@code null} if the attribute is not supported.
61
     */
62
    FileTime lastAccessTime();
63 64 65 66 67

    /**
     * Returns the creation time if supported. The creation time is the time
     * that the file was created.
     *
68 69
     * @return   a {@code FileTime} representing the time  the file was created
     *           or {@code null} if the attribute is not supported.
70
     */
71
    FileTime creationTime();
72 73 74 75 76 77 78 79 80 81 82 83

    /**
     * Tells whether the file is a regular file with opaque content.
     */
    boolean isRegularFile();

    /**
     * Tells whether the file is a directory.
     */
    boolean isDirectory();

    /**
84
     * Tells whether the file is a symbolic link.
85 86 87 88 89
     */
    boolean isSymbolicLink();

    /**
     * Tells whether the file is something other than a regular file, directory,
90
     * or symbolic link.
91 92 93 94 95 96 97 98 99 100
     */
    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.
     *
101
     * @return  the file size, in bytes
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
     */
    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,
123
     * and two files are the {@link java.nio.file.Path#isSameFile same} with
124 125 126 127 128 129
     * non-{@code null} file keys, then their file keys are equal.
     *
     * @see java.nio.file.Files#walkFileTree
     */
    Object fileKey();
}