Path.java 80.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright 2007-2009 Sun Microsystems, Inc.  All Rights Reserved.
 * 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
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * 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.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

package java.nio.file;

import java.nio.file.attribute.*;
29 30 31
import java.nio.channels.SeekableByteChannel;
import java.io.IOException;
import java.io.OutputStream;
32
import java.net.URI;
33 34
import java.util.Iterator;
import java.util.Set;
35 36 37 38 39 40 41

/**
 * A file reference that locates a file using a system dependent path. The file
 * is not required to exist.
 *
 * <p> On many platforms a <em>path</em> is the means to locate and access files
 * in a file system. A path is hierarchical and composed of a sequence of
42 43
 * directory and file name elements separated by a special separator or
 * delimiter.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
 *
 * <h4>Path operations</h4>
 *
 * <p> A system dependent path represented by this class is conceptually a
 * sequence of name elements and optionally a <em>root component</em>. The name
 * that is <em>farthest</em> from the root of the directory hierarchy is the
 * name of a file or directory. The other elements are directory names. The root
 * component typically identifies a file system hierarchy. A {@code Path} can
 * represent a root, a root and a sequence of names, or simply one or more name
 * elements. It defines the {@link #getName() getName}, {@link #getParent
 * getParent}, {@link #getRoot getRoot}, and {@link #subpath subpath} methods
 * to access the components or a subsequence of its name elements.
 *
 * <p> In addition to accessing the components of a path, a {@code Path} also
 * defines {@link #resolve(Path) resolve} and {@link #relativize relativize}
 * operations. Paths can also be {@link #compareTo compared}, and tested
 * against each other using using the {@link #startsWith startsWith} and {@link
 * #endsWith endWith} methods.
 *
 * <h4>File operations</h4>
 *
 * <p> A {@code Path} is either <em>absolute</em> or <em>relative</em>. An
 * absolute path is complete in that does not need to be combined with another
 * path in order to locate a file. All operations on relative paths are first
 * resolved against a file system's default directory as if by invoking the
 * {@link #toAbsolutePath toAbsolutePath} method.
 *
 * <p> In addition to the operations defined by the {@link FileRef} interface,
 * this class defines the following operations:
 *
 * <ul>
75 76 77
 *   <li><p> The {@link #newByteChannel newByteChannel} method
 *     may be used to open a file and obtain a byte channel for reading or
 *     writing. </p></li>
78 79 80
 *   <li><p> Files may be {@link #createFile(FileAttribute[]) created}, or
 *     directories may be {@link #createDirectory(FileAttribute[]) created}.
 *     </p></li>
81 82 83 84 85 86 87 88 89
 *   <li><p> The {@link #delete delete} method may be used to delete a file.
 *     </p></li>
 *   <li><p> The {@link #checkAccess checkAccess} method may be used to check
 *     the existence or accessibility of a file. </p></li>
 *   <li><p> The {@link #isSameFile isSameFile} method may be used to test if
 *     two file references locate the same file. </p></li>
 *   <li><p> The {@link #getFileStore getFileStore} method may be used to
 *     obtain the {@link FileStore} representing the storage where a file is
 *     located. </p></li>
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
 *   <li><p> Directories can be {@link #newDirectoryStream opened} so as to
 *      iterate over the entries in the directory. </p></li>
 *   <li><p> Files can be {@link #copyTo(Path,CopyOption[]) copied} or
 *     {@link #moveTo(Path,CopyOption[]) moved}. </p></li>
 *   <li><p> Symbolic-links may be {@link #createSymbolicLink created}, or the
 *     target of a link may be {@link #readSymbolicLink read}. </p></li>
 *   <li><p> The {@link #toRealPath real} path of an existing file may be
 *     obtained. </li></p>
 * </ul>
 *
 * <p> This class implements {@link Watchable} interface so that a directory
 * located by a path can be {@link #register registered} with a {@link WatchService}.
 * and entries in the directory watched.
 *
 * <h4>File attributes</h4>
 *
106 107 108 109 110 111 112 113
 * In addition to the {@link #setAttribute setAttribute} and {@link #getAttribute
 * getAttribute} methods, the <a href="attribute/package-summary.html">{@code
 * java.nio.file.attribute}</a> package provides type-safe and efficient access
 * to file attributes or <em>meta-data</em> associated with files. The {@link
 * Attributes Attributes} class defines methods that operate on or return file
 * attributes. For example, the file type, size, timestamps, and other
 * <em>basic</em> meta-data are obtained, in bulk, by invoking the {@link
 * Attributes#readBasicFileAttributes Attributes.readBasicFileAttributes} method:
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
 * <pre>
 *     Path file = ...
 *     BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file);
 * </pre>
 *
 * <a name="interop"><h4>Interoperability</h4></a>
 *
 * <p> Paths created by file systems associated with the default {@link
 * java.nio.file.spi.FileSystemProvider provider} are generally interoperable
 * with the {@link java.io.File java.io.File} class. Paths created by other
 * providers are unlikely to be interoperable with the abstract path names
 * represented by {@code java.io.File}. The {@link java.io.File#toPath
 * File.toPath} method may be used to obtain a {@code Path} from the abstract
 * path name represented by a {@code java.io.File java.io.File} object. The
 * resulting {@code Path} can be used to operate on the same file as the {@code
 * java.io.File} object.
 *
 * <p> Path objects created by file systems associated with the default
 * provider are interoperable with objects created by other file systems created
 * by the same provider. Path objects created by file systems associated with
 * other providers may not be interoperable with other file systems created by
 * the same provider. The reasons for this are provider specific.
 *
 * <h4>Concurrency</h4></a>
 *
 * <p> Instances of this class are immutable and safe for use by multiple concurrent
 * threads.
 *
 * @since 1.7
 */

public abstract class Path
    implements FileRef, Comparable<Path>, Iterable<Path>, Watchable
{
    /**
     * Initializes a new instance of this class.
     */
    protected Path() { }

    /**
     * Returns the file system that created this object.
     *
156
     * @return  the file system that created this object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
     */
    public abstract FileSystem getFileSystem();

    /**
     * Tells whether or not this path is absolute.
     *
     * <p> An absolute path is complete in that it doesn't need to be
     * combined with other path information in order to locate a file.
     *
     * @return  {@code true} if, and only if, this path is absolute
     */
    public abstract boolean isAbsolute();

    /**
     * Returns the root component of this path as a {@code Path} object,
     * or {@code null} if this path does not have a root component.
     *
174
     * @return  a path representing the root component of this path,
175 176 177 178 179 180 181 182 183
     *          or {@code null}
     */
    public abstract Path getRoot();

    /**
     * Returns the name of the file or directory denoted by this path. The
     * file name is the <em>farthest</em> element from the root in the directory
     * hierarchy.
     *
184
     * @return  a path representing the name of the file or directory, or
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
     *          {@code null} if this path has zero elements
     */
    public abstract Path getName();

    /**
     * Returns the <em>parent path</em>, or {@code null} if this path does not
     * have a parent.
     *
     * <p> The parent of this path object consists of this path's root
     * component, if any, and each element in the path except for the
     * <em>farthest</em> from the root in the directory hierarchy. This method
     * does not access the file system; the path or its parent may not exist.
     * Furthermore, this method does not eliminate special names such as "."
     * and ".." that may be used in some implementations. On UNIX for example,
     * the parent of "{@code /a/b/c}" is "{@code /a/b}", and the parent of
     * {@code "x/y/.}" is "{@code x/y}". This method may be used with the {@link
     * #normalize normalize} method, to eliminate redundant names, for cases where
     * <em>shell-like</em> navigation is required.
     *
     * <p> If this path has one or more elements, and no root component, then
     * this method is equivalent to evaluating the expression:
     * <blockquote><pre>
     * subpath(0,&nbsp;getNameCount()-1);
     * </pre></blockquote>
     *
210
     * @return  a path representing the path's parent
211 212 213 214 215 216
     */
    public abstract Path getParent();

    /**
     * Returns the number of name elements in the path.
     *
217
     * @return  the number of elements in the path, or {@code 0} if this path
218 219 220 221 222 223 224 225 226 227 228 229 230
     *          only represents a root component
     */
    public abstract int getNameCount();

   /**
     * Returns a name element of this path.
     *
     * <p> The {@code index} parameter is the index of the name element to return.
     * The element that is <em>closest</em> to the root in the directory hierarchy
     * has index {@code 0}. The element that is <em>farthest</em> from the root
     * has index {@link #getNameCount count}{@code -1}.
     *
     * @param   index
231
     *          the index of the element
232
     *
233
     * @return  the name element
234 235
     *
     * @throws  IllegalArgumentException
236
     *          if {@code index} is negative, {@code index} is greater than or
237
     *          equal to the number of elements, or this path has zero name
238
     *          elements
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
     */
    public abstract Path getName(int index);

    /**
     * Returns a relative {@code Path} that is a subsequence of the name
     * elements of this path.
     *
     * <p> The {@code beginIndex} and {@code endIndex} parameters specify the
     * subsequence of name elements. The name that is <em>closest</em> to the root
     * in the directory hierarchy has index {@code 0}. The name that is
     * <em>farthest</em> from the root has index {@link #getNameCount
     * count}{@code -1}. The returned {@code Path} object has the name elements
     * that begin at {@code beginIndex} and extend to the element at index {@code
     * endIndex-1}.
     *
     * @param   beginIndex
255
     *          the index of the first element, inclusive
256
     * @param   endIndex
257
     *          the index of the last element, exclusive
258
     *
259
     * @return  a new {@code Path} object that is a subsequence of the name
260 261 262
     *          elements in this {@code Path}
     *
     * @throws  IllegalArgumentException
263
     *          if {@code beginIndex} is negative, or greater than or equal to
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
     *          the number of elements. If {@code endIndex} is less than or
     *          equal to {@code beginIndex}, or larger than the number of elements.
     */
    public abstract Path subpath(int beginIndex, int endIndex);

    /**
     * Tests if this path starts with the given path.
     *
     * <p> This path <em>starts</em> with the given path if this path's root
     * component <em>starts</em> with the root component of the given path,
     * and this path starts with the same name elements as the given path.
     * If the given path has more name elements than this path then {@code false}
     * is returned.
     *
     * <p> Whether or not the root component of this path starts with the root
     * component of the given path is file system specific. If this path does
     * not have a root component and the given path has a root component then
     * this path does not start with the given path.
     *
     * @param   other
284
     *          the given path
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
     *
     * @return  {@code true} if this path starts with the given path; otherwise
     *          {@code false}
     */
    public abstract boolean startsWith(Path other);

    /**
     * Tests if this path ends with the given path.
     *
     * <p> If the given path has <em>N</em> elements, and no root component,
     * and this path has <em>N</em> or more elements, then this path ends with
     * the given path if the last <em>N</em> elements of each path, starting at
     * the element farthest from the root, are equal.
     *
     * <p> If the given path has a root component then this path ends with the
     * given path if the root component of this path <em>ends with</em> the root
     * component of the given path, and the corresponding elements of both paths
     * are equal. Whether or not the root component of this path ends with the
     * root component of the given path is file system specific. If this path
     * does not have a root component and the given path has a root component
     * then this path does not end with the given path.
     *
     * @param   other
308
     *          the given path
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
     *
     * @return  {@code true} if this path ends with the given path; otherwise
     *          {@code false}
     */
    public abstract boolean endsWith(Path other);

    /**
     * Returns a path that is this path with redundant name elements eliminated.
     *
     * <p> The precise definition of this method is implementation dependent but
     * in general it derives from this path, a path that does not contain
     * <em>redundant</em> name elements. In many file systems, the "{@code .}"
     * and "{@code ..}" are special names used to indicate the current directory
     * and parent directory. In such file systems all occurrences of "{@code .}"
     * are considered redundant. If a "{@code ..}" is preceded by a
     * non-"{@code ..}" name then both names are considered redundant (the
     * process to identify such names is repeated until is it no longer
     * applicable).
     *
     * <p> This method does not access the file system; the path may not locate
     * a file that exists. Eliminating "{@code ..}" and a preceding name from a
     * path may result in the path that locates a different file than the original
     * path. This can arise when the preceding name is a symbolic link.
     *
333
     * @return  the resulting path, or this path if it does not contain
334
     *          redundant name elements, or {@code null} if this path does not
335
     *          have a root component and all name elements are redundant
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
     *
     * @see #getParent
     * @see #toRealPath
     */
    public abstract Path normalize();

    // -- resolution and relativization --

    /**
     * Resolve the given path against this path.
     *
     * <p> If the {@code other} parameter is an {@link #isAbsolute() absolute}
     * path then this method trivially returns {@code other}. If {@code other}
     * is {@code null} then this path is returned. Otherwise this method
     * considers this path to be a directory and resolves the given path
     * against this path. In the simplest case, the given path does not have
     * a {@link #getRoot root} component, in which case this method <em>joins</em>
     * the given path to this path and returns a resulting path that {@link
     * #endsWith ends} with the given path. Where the given path has a root
     * component then resolution is highly implementation dependent and therefore
     * unspecified.
     *
     * @param   other
359
     *          the path to resolve against this path; can be {@code null}
360
     *
361
     * @return  the resulting path
362 363 364 365 366 367 368 369 370 371 372
     *
     * @see #relativize
     */
    public abstract Path resolve(Path other);

    /**
     * Converts a given path string to a {@code Path} and resolves it against
     * this {@code Path} in exactly the manner specified by the {@link
     * #resolve(Path) resolve} method.
     *
     * @param   other
373
     *          the path string to resolve against this path
374
     *
375
     * @return  the resulting path
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
     *
     * @throws  InvalidPathException
     *          If the path string cannot be converted to a Path.
     *
     * @see FileSystem#getPath
     */
    public abstract Path resolve(String other);

    /**
     * Constructs a relative path between this path and a given path.
     *
     * <p> Relativization is the inverse of {@link #resolve(Path) resolution}.
     * This method attempts to construct a {@link #isAbsolute relative} path
     * that when {@link #resolve(Path) resolved} against this path, yields a
     * path that locates the same file as the given path. For example, on UNIX,
     * if this path is {@code "/a/b"} and the given path is {@code "/a/b/c/d"}
     * then the resulting relative path would be {@code "c/d"}. Where this
     * path and the given path do not have a {@link #getRoot root} component,
     * then a relative path can be constructed. A relative path cannot be
     * constructed if only one of the paths have a root component. Where both
     * paths have a root component then it is implementation dependent if a
     * relative path can be constructed. If this path and the given path are
     * {@link #equals equal} then {@code null} is returned.
     *
     * <p> For any two paths <i>p</i> and <i>q</i>, where <i>q</i> does not have
     * a root component,
     * <blockquote>
     *   <i>p</i><tt>.relativize(</tt><i>p</i><tt>.resolve(</tt><i>q</i><tt>)).equals(</tt><i>q</i><tt>)</tt>
     * </blockquote>
     *
     * <p> When symbolic-links are supported, then whether the resulting path,
     * when resolved against this path, yields a path that can be used to locate
     * the {@link #isSameFile same} file as {@code other} is implementation
     * dependent. For example, if this path is  {@code "/a/b"} and the given
     * path is {@code "/a/x"} then the resulting relative path may be {@code
     * "../x"}. If {@code "b"} is a symbolic-link then is implementation
     * dependent if {@code "a/b/../x"} would locate the same file as {@code "/a/x"}.
     *
     * @param   other
415
     *          the resulting path
416
     *
417
     * @return  the resulting relative path, or {@code null} if both paths are
418 419 420
     *          equal
     *
     * @throws  IllegalArgumentException
421
     *          if {@code other} is not a {@code Path} that can be relativized
422 423 424 425 426 427 428 429 430
     *          against this path
     */
    public abstract Path relativize(Path other);

    // -- file operations --

    /**
     * Deletes the file located by this path.
     *
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
     * <p> An implementation may require to examine the file to determine if the
     * file is a directory. Consequently this method may not be atomic with respect
     * to other file system operations.  If the file is a symbolic-link then the
     * link is deleted and not the final target of the link.
     *
     * <p> If the file is a directory then the directory must be empty. In some
     * implementations a directory has entries for special files or links that
     * are created when the directory is created. In such implementations a
     * directory is considered empty when only the special entries exist.
     *
     * <p> On some operating systems it may not be possible to remove a file when
     * it is open and in use by this Java virtual machine or other programs.
     *
     * @throws  NoSuchFileException
     *          if the file does not exist <i>(optional specific exception)</i>
     * @throws  DirectoryNotEmptyException
     *          if the file is a directory and could not otherwise be deleted
     *          because the directory is not empty <i>(optional specific
     *          exception)</i>
     * @throws  IOException
     *          if an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkDelete(String)} method
     *          is invoked to check delete access to the file
     */
    public abstract void delete() throws IOException;

    /**
     * Deletes the file located by this path, if it exists.
461
     *
462
     * <p> As with the {@link #delete delete()} method, an implementation
463 464 465 466 467 468 469 470 471 472 473 474 475 476
     * may require to examine the file to determine if the file is a directory.
     * Consequently this method may not be atomic with respect to other file
     * system operations.  If the file is a symbolic-link then the link is
     * deleted and not the final target of the link.
     *
     * <p> If the file is a directory then the directory must be empty. In some
     * implementations a directory has entries for special files or links that
     * are created when the directory is created. In such implementations a
     * directory is considered empty when only the special entries exist.
     *
     * <p> On some operating systems it may not be possible to remove a file when
     * it is open and in use by this Java virtual machine or other programs.
     *
     * @throws  DirectoryNotEmptyException
477
     *          if the file is a directory and could not otherwise be deleted
478 479 480
     *          because the directory is not empty <i>(optional specific
     *          exception)</i>
     * @throws  IOException
481
     *          if an I/O error occurs
482 483 484
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkDelete(String)} method
485
     *          is invoked to check delete access to the file.
486
     */
487
    public abstract void deleteIfExists() throws IOException;
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509

    /**
     * Creates a symbolic link to a target <i>(optional operation)</i>.
     *
     * <p> The {@code target} parameter is the target of the link. It may be an
     * {@link Path#isAbsolute absolute} or relative path and may not exist. When
     * the target is a relative path then file system operations on the resulting
     * link are relative to the path of the link.
     *
     * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute
     * attributes} to set atomically when creating the link. Each attribute is
     * identified by its {@link FileAttribute#name name}. If more than one attribute
     * of the same name is included in the array then all but the last occurrence
     * is ignored.
     *
     * <p> Where symbolic links are supported, but the underlying {@link FileStore}
     * does not support symbolic links, then this may fail with an {@link
     * IOException}. Additionally, some operating systems may require that the
     * Java virtual machine be started with implementation specific privileges to
     * create symbolic links, in which case this method may throw {@code IOException}.
     *
     * @param   target
510
     *          the target of the link
511
     * @param   attrs
512
     *          the array of attributes to set atomically when creating the
513 514 515 516 517
     *          symbolic link
     *
     * @return  this path
     *
     * @throws  UnsupportedOperationException
518
     *          if the implementation does not support symbolic links or the
519 520 521
     *          array contains an attribute that cannot be set atomically when
     *          creating the symbolic link
     * @throws  FileAlreadyExistsException
522
     *          if a file with the name already exists <i>(optional specific
523 524
     *          exception)</i>
     * @throws  IOException
525
     *          if an I/O error occurs
526
     * @throws  SecurityException
M
martin 已提交
527
     *          In the case of the default provider, and a security manager
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
     *          is installed, it denies {@link LinkPermission}<tt>("symbolic")</tt>
     *          or its {@link SecurityManager#checkWrite(String) checkWrite}
     *          method denies write access to the path of the symbolic link.
     */
    public abstract Path createSymbolicLink(Path target, FileAttribute<?>... attrs)
        throws IOException;

    /**
     * Creates a new link (directory entry) for an existing file <i>(optional
     * operation)</i>.
     *
     * <p> This path locates the directory entry to create. The {@code existing}
     * parameter is the path to an existing file. This method creates a new
     * directory entry for the file so that it can be accessed using this path.
     * On some file systems this is known as creating a "hard link". Whether the
     * file attributes are maintained for the file or for each directory entry
     * is file system specific and therefore not specified. Typically, a file
     * system requires that all links (directory entries) for a file be on the
     * same file system. Furthermore, on some platforms, the Java virtual machine
     * may require to be started with implementation specific privileges to
     * create hard links or to create links to directories.
     *
     * @param   existing
551
     *          a reference to an existing file
552 553 554 555
     *
     * @return  this path
     *
     * @throws  UnsupportedOperationException
556
     *          if the implementation does not support adding an existing file
557 558
     *          to a directory
     * @throws  FileAlreadyExistsException
559
     *          if the entry could not otherwise be created because a file of
560 561
     *          that name already exists <i>(optional specific exception)</i>
     * @throws  IOException
562
     *          if an I/O error occurs
563
     * @throws  SecurityException
M
martin 已提交
564
     *          In the case of the default provider, and a security manager
565 566 567
     *          is installed, it denies {@link LinkPermission}<tt>("hard")</tt>
     *          or its {@link SecurityManager#checkWrite(String) checkWrite}
     *          method denies write access to both this path and the path of the
568
     *          existing file.
569 570 571 572 573 574 575 576 577 578 579 580
     */
    public abstract Path createLink(Path existing) throws IOException;

    /**
     * Reads the target of a symbolic link <i>(optional operation)</i>.
     *
     * <p> If the file system supports <a href="package-summary.html#links">symbolic
     * links</a> then this method is used read the target of the link, failing
     * if the file is not a link. The target of the link need not exist. The
     * returned {@code Path} object will be associated with the same file
     * system as this {@code Path}.
     *
581
     * @return  a {@code Path} object representing the target of the link
582 583
     *
     * @throws  UnsupportedOperationException
584
     *          if the implementation does not support symbolic links
585
     * @throws  NotLinkException
586
     *          if the target could otherwise not be read because the file
587 588
     *          is not a link <i>(optional specific exception)</i>
     * @throws  IOException
589
     *          if an I/O error occurs
590
     * @throws  SecurityException
M
martin 已提交
591
     *          In the case of the default provider, and a security manager
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
     *          is installed, it checks that {@code FilePermission} has been
     *          granted with the "{@code readlink}" action to read the link.
     */
    public abstract Path readSymbolicLink() throws IOException;

    /**
     * Returns a URI to represent this path.
     *
     * <p> This method constructs a hierarchical {@link URI} that is absolute
     * with a non-empty path component. Its {@link URI#getScheme() scheme} is
     * equal to the URI scheme that identifies the provider. The exact form of
     * the other URI components is highly provider dependent. In particular, it
     * is implementation dependent if its query, fragment, and authority
     * components are defined or undefined.
     *
     * <p> For the default provider the {@link URI#getPath() path} component
     * will represent the {@link #toAbsolutePath absolute} path; the query,
     * fragment components are undefined. Whether the authority component is
     * defined or not is implementation dependent. There is no guarantee that
     * the {@code URI} may be used to construct a {@link java.io.File java.io.File}.
     * In particular, if this path represents a Universal Naming Convention (UNC)
     * path, then the UNC server name may be encoded in the authority component
     * of the resulting URI. In the case of the default provider, and the file
     * exists, and it can be determined that the file is a directory, then the
     * resulting {@code URI} will end with a slash.
     *
     * <p> The default provider provides a similar <em>round-trip</em> guarantee
     * to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
     * is guaranteed that
     * <blockquote><tt>
     * {@link Paths#get(URI) Paths.get}(</tt><i>p</i><tt>.toUri()).equals(</tt><i>p</i>
     * <tt>.{@link #toAbsolutePath() toAbsolutePath}())</tt>
     * </blockquote>
     * so long as the original {@code Path}, the {@code URI}, and the new {@code
     * Path} are all created in (possibly different invocations of) the same
     * Java virtual machine. Whether other providers make any guarantees is
     * provider specific and therefore unspecified.
     *
     * <p> When a file system is constructed to access the contents of a file
     * as a file system then it is highly implementation specific if the returned
     * URI represents the given path in the file system or it represents a
     * <em>compound</em> URI that encodes the URI of the enclosing file system.
     * A format for compound URIs is not defined in this release; such a scheme
     * may be added in a future release.
     *
637
     * @return  an absolute, hierarchical URI with a non-empty path component
638
     *
639
     * @throws  java.io.IOError
640
     *          if an I/O error occurs obtaining the absolute path, or where a
641
     *          file system is constructed to access the contents of a file as
642 643
     *          a file system, and the URI of the enclosing file system cannot be
     *          obtained
644 645
     *
     * @throws  SecurityException
M
martin 已提交
646
     *          In the case of the default provider, and a security manager
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
     *          is installed, the {@link #toAbsolutePath toAbsolutePath} method
     *          throws a security exception.
     */
    public abstract URI toUri();

    /**
     * Returns a {@code Path} object representing the absolute path of this
     * path.
     *
     * <p> If this path is already {@link Path#isAbsolute absolute} then this
     * method simply returns this path. Otherwise, this method resolves the path
     * in an implementation dependent manner, typically by resolving the path
     * against a file system default directory. Depending on the implementation,
     * this method may throw an I/O error if the file system is not accessible.
     *
662
     * @return  a {@code Path} object representing the absolute path
663 664
     *
     * @throws  IOError
665
     *          if an I/O error occurs
666
     * @throws  SecurityException
667 668 669
     *          In the case of the default provider, a security manager
     *          is installed, and this path is not absolute, then the security
     *          manager's {@link SecurityManager#checkPropertyAccess(String)
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
     *          checkPropertyAccess} method is invoked to check access to the
     *          system property {@code user.dir}
     */
    public abstract Path toAbsolutePath();

    /**
     * Returns the <em>real</em> path of an existing file.
     *
     * <p> The precise definition of this method is implementation dependent but
     * in general it derives from this path, an {@link #isAbsolute absolute}
     * path that locates the {@link #isSameFile same} file as this path, but
     * with name elements that represent the actual name of the directories
     * and the file. For example, where filename comparisons on a file system
     * are case insensitive then the name elements represent the names in their
     * actual case. Additionally, the resulting path has redundant name
     * elements removed.
     *
     * <p> If this path is relative then its absolute path is first obtained,
     * as if by invoking the {@link #toAbsolutePath toAbsolutePath} method.
     *
     * <p> The {@code resolveLinks} parameter specifies if symbolic links
     * should be resolved. This parameter is ignored when symbolic links are
     * not supported. Where supported, and the parameter has the value {@code
     * true} then symbolic links are resolved to their final target. Where the
     * parameter has the value {@code false} then this method does not resolve
     * symbolic links. Some implementations allow special names such as
     * "{@code ..}" to refer to the parent directory. When deriving the <em>real
     * path</em>, and a "{@code ..}" (or equivalent) is preceded by a
     * non-"{@code ..}" name then an implementation will typically causes both
     * names to be removed. When not resolving symbolic links and the preceding
     * name is a symbolic link then the names are only removed if it guaranteed
     * that the resulting path will locate the same file as this path.
     *
703
     * @return  an absolute path represent the <em>real</em> path of the file
704 705 706
     *          located by this object
     *
     * @throws  IOException
707
     *          if the file does not exist or an I/O error occurs
708
     * @throws  SecurityException
M
martin 已提交
709
     *          In the case of the default provider, and a security manager
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
     *          is installed, its {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the file, and where
     *          this path is not absolute, its {@link SecurityManager#checkPropertyAccess(String)
     *          checkPropertyAccess} method is invoked to check access to the
     *          system property {@code user.dir}
     */
    public abstract Path toRealPath(boolean resolveLinks) throws IOException;

    /**
     * Copy the file located by this path to a target location.
     *
     * <p> This method copies the file located by this {@code Path} to the
     * target location with the {@code options} parameter specifying how the
     * copy is performed. By default, the copy fails if the target file already
     * exists, except if the source and target are the {@link #isSameFile same}
     * file, in which case this method has no effect. File attributes are not
     * required to be copied to the target file. If symbolic links are supported,
     * and the file is a link, then the final target of the link is copied. If
     * the file is a directory then it creates an empty directory in the target
     * location (entries in the directory are not copied). This method can be
     * used with the {@link Files#walkFileTree Files.walkFileTree} utility
     * method to copy a directory and all entries in the directory, or an entire
     * <i>file-tree</i> where required.
     *
     * <p> The {@code options} parameter is an array of options and may contain
     * any of the following:
     *
     * <table border=1 cellpadding=5 summary="">
     * <tr> <th>Option</th> <th>Description</th> </tr>
     * <tr>
     *   <td> {@link StandardCopyOption#REPLACE_EXISTING REPLACE_EXISTING} </td>
     *   <td> If the target file exists, then the target file is replaced if it
     *     is not a non-empty directory. If the target file exists and is a
     *     symbolic-link then the symbolic-link is replaced (not the target of
     *     the link. </td>
     * </tr>
     * <tr>
     *   <td> {@link StandardCopyOption#COPY_ATTRIBUTES COPY_ATTRIBUTES} </td>
     *   <td> Attempts to copy the file attributes associated with this file to
     *     the target file. The exact file attributes that are copied is platform
     *     and file system dependent and therefore unspecified. Minimally, the
     *     {@link BasicFileAttributes#lastModifiedTime last-modified-time} is
752 753 754
     *     copied to the target file if supported by both the source and target
     *     file store. Copying of file timestamps may result in precision
     *     loss. </td>
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
     * </tr>
     * <tr>
     *   <td> {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} </td>
     *   <td> Symbolic-links are not followed. If the file, located by this path,
     *     is a symbolic-link then the link is copied rather than the target of
     *     the link. It is implementation specific if file attributes can be
     *     copied to the new link. In other words, the {@code COPY_ATTRIBUTES}
     *     option may be ignored when copying a link. </td>
     * </tr>
     * </table>
     *
     * <p> An implementation of this interface may support additional
     * implementation specific options.
     *
     * <p> Copying a file is not an atomic operation. If an {@link IOException}
     * is thrown then it possible that the target file is incomplete or some of
     * its file attributes have not been copied from the source file. When the
     * {@code REPLACE_EXISTING} option is specified and the target file exists,
     * then the target file is replaced. The check for the existence of the file
     * and the creation of the new file may not be atomic with respect to other
     * file system activities.
     *
     * @param   target
778
     *          the target location
779
     * @param   options
780
     *          options specifying how the copy should be done
781
     *
782
     * @return  the target
783 784
     *
     * @throws  UnsupportedOperationException
785
     *          if the array contains a copy option that is not supported
786
     * @throws  FileAlreadyExistsException
787
     *          if the target file exists and cannot be replaced because the
788 789 790
     *          {@code REPLACE_EXISTING} option is not specified, or the target
     *          file is a non-empty directory <i>(optional specific exception)</i>
     * @throws  IOException
791
     *          if an I/O error occurs
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the source file, the
     *          {@link SecurityManager#checkWrite(String) checkWrite} is invoked
     *          to check write access to the target file. If a symbolic link is
     *          copied the security manager is invoked to check {@link
     *          LinkPermission}{@code ("symbolic")}.
     */
    public abstract Path copyTo(Path target, CopyOption... options)
        throws IOException;

    /**
     * Move or rename the file located by this path to a target location.
     *
     * <p> By default, this method attempts to move the file to the target
     * location, failing if the target file exists except if the source and
     * target are the {@link #isSameFile same} file, in which case this method
     * has no effect. If the file is a symbolic link then the link is moved and
     * not the target of the link. This method may be invoked to move an empty
     * directory. In some implementations a directory has entries for special
     * files or links that are created when the directory is created. In such
     * implementations a directory is considered empty when only the special
     * entries exist. When invoked to move a directory that is not empty then the
     * directory is moved if it does not require moving the entries in the directory.
     * For example, renaming a directory on the same {@link FileStore} will usually
     * not require moving the entries in the directory. When moving a directory
     * requires that its entries be moved then this method fails (by throwing
     * an {@code IOException}). To move a <i>file tree</i> may involve copying
     * rather than moving directories and this can be done using the {@link
     * #copyTo copyTo} method in conjunction with the {@link
     * Files#walkFileTree Files.walkFileTree} utility method.
     *
     * <p> The {@code options} parameter is an array of options and may contain
     * any of the following:
     *
     * <table border=1 cellpadding=5 summary="">
     * <tr> <th>Option</th> <th>Description</th> </tr>
     * <tr>
     *   <td> {@link StandardCopyOption#REPLACE_EXISTING REPLACE_EXISTING} </td>
     *   <td> If the target file exists, then the target file is replaced if it
     *     is not a non-empty directory. If the target file exists and is a
     *     symbolic-link then the symbolic-link is replaced and not the target of
     *     the link. </td>
     * </tr>
     * <tr>
     *   <td> {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} </td>
     *   <td> The move is performed as an atomic file system operation and all
     *     other options are ignored. If the target file exists then it is
     *     implementation specific if the existing file is replaced or this method
     *     fails by throwing an {@link IOException}. If the move cannot be
     *     performed as an atomic file system operation then {@link
     *     AtomicMoveNotSupportedException} is thrown. This can arise, for
     *     example, when the target location is on a different {@code FileStore}
     *     and would require that the file be copied, or target location is
     *     associated with a different provider to this object. </td>
     * </table>
     *
     * <p> An implementation of this interface may support additional
     * implementation specific options.
     *
     * <p> Where the move requires that the file be copied then the {@link
     * BasicFileAttributes#lastModifiedTime last-modified-time} is copied to the
     * new file. An implementation may also attempt to copy other file
     * attributes but is not required to fail if the file attributes cannot be
     * copied. When the move is performed as a non-atomic operation, and a {@code
     * IOException} is thrown, then the state of the files is not defined. The
     * original file and the target file may both exist, the target file may be
     * incomplete or some of its file attributes may not been copied from the
     * original file.
     *
     * @param   target
864
     *          the target location
865
     * @param   options
866
     *          options specifying how the move should be done
867
     *
868
     * @return  the target
869 870
     *
     * @throws  UnsupportedOperationException
871
     *          if the array contains a copy option that is not supported
872
     * @throws  FileAlreadyExistsException
873
     *          if the target file exists and cannot be replaced because the
874 875 876
     *          {@code REPLACE_EXISTING} option is not specified, or the target
     *          file is a non-empty directory
     * @throws  AtomicMoveNotSupportedException
877
     *          if the options array contains the {@code ATOMIC_MOVE} option but
878 879
     *          the file cannot be moved as an atomic file system operation.
     * @throws  IOException
880
     *          if an I/O error occurs
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
     *          method is invoked to check write access to both the source and
     *          target file.
     */
    public abstract Path moveTo(Path target, CopyOption... options)
        throws IOException;

    /**
     * Opens the directory referenced by this object, returning a {@code
     * DirectoryStream} to iterate over all entries in the directory. The
     * elements returned by the directory stream's {@link DirectoryStream#iterator
     * iterator} are of type {@code Path}, each one representing an entry in the
     * directory. The {@code Path} objects are obtained as if by {@link
     * #resolve(Path) resolving} the name of the directory entry against this
     * path.
     *
     * <p> The directory stream's {@code close} method should be invoked after
     * iteration is completed so as to free any resources held for the open
901
     * directory.
902 903 904 905 906
     *
     * <p> When an implementation supports operations on entries in the
     * directory that execute in a race-free manner then the returned directory
     * stream is a {@link SecureDirectoryStream}.
     *
907
     * @return  a new and open {@code DirectoryStream} object
908 909
     *
     * @throws  NotDirectoryException
910
     *          if the file could not otherwise be opened because it is not
911 912
     *          a directory <i>(optional specific exception)</i>
     * @throws  IOException
913
     *          if an I/O error occurs
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the directory.
     */
    public abstract DirectoryStream<Path> newDirectoryStream()
        throws IOException;

    /**
     * Opens the directory referenced by this object, returning a {@code
     * DirectoryStream} to iterate over the entries in the directory. The
     * elements returned by the directory stream's {@link DirectoryStream#iterator
     * iterator} are of type {@code Path}, each one representing an entry in the
     * directory. The {@code Path} objects are obtained as if by {@link
     * #resolve(Path) resolving} the name of the directory entry against this
     * path. The entries returned by the iterator are filtered by matching the
     * {@code String} representation of their file names against the given
     * <em>globbing</em> pattern.
     *
     * <p> For example, suppose we want to iterate over the files ending with
     * ".java" in a directory:
     * <pre>
     *     Path dir = ...
     *     DirectoryStream&lt;Path&gt; stream = dir.newDirectoryStream("*.java");
     * </pre>
     *
     * <p> The globbing pattern is specified by the {@link
     * FileSystem#getPathMatcher getPathMatcher} method.
     *
     * <p> The directory stream's {@code close} method should be invoked after
     * iteration is completed so as to free any resources held for the open
     * directory.
     *
     * <p> When an implementation supports operations on entries in the
     * directory that execute in a race-free manner then the returned directory
     * stream is a {@link SecureDirectoryStream}.
     *
     * @param   glob
952
     *          the glob pattern
953
     *
954
     * @return  a new and open {@code DirectoryStream} object
955 956
     *
     * @throws  java.util.regex.PatternSyntaxException
957
     *          if the pattern is invalid
958
     * @throws  NotDirectoryException
959
     *          if the file could not otherwise be opened because it is not
960 961
     *          a directory <i>(optional specific exception)</i>
     * @throws  IOException
962
     *          if an I/O error occurs
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the directory.
     */
    public abstract DirectoryStream<Path> newDirectoryStream(String glob)
        throws IOException;

    /**
     * Opens the directory referenced by this object, returning a {@code
     * DirectoryStream} to iterate over the entries in the directory. The
     * elements returned by the directory stream's {@link DirectoryStream#iterator
     * iterator} are of type {@code Path}, each one representing an entry in the
     * directory. The {@code Path} objects are obtained as if by {@link
     * #resolve(Path) resolving} the name of the directory entry against this
     * path. The entries returned by the iterator are filtered by the given
979
     * {@link DirectoryStream.Filter filter}.
980 981 982
     *
     * <p> The directory stream's {@code close} method should be invoked after
     * iteration is completed so as to free any resources held for the open
983
     * directory.
984 985
     *
     * <p> Where the filter terminates due to an uncaught error or runtime
986 987 988 989 990
     * exception then it is propogated to the iterator's {@link Iterator#hasNext()
     * hasNext} or {@link Iterator#next() next} method. Where an {@code
     * IOException} is thrown, it is propogated as a {@link
     * java.util.concurrent.ConcurrentModificationException} with the {@code
     * IOException} as the cause.
991 992 993 994 995 996 997 998 999 1000
     *
     * <p> When an implementation supports operations on entries in the
     * directory that execute in a race-free manner then the returned directory
     * stream is a {@link SecureDirectoryStream}.
     *
     * <p> <b>Usage Example:</b>
     * Suppose we want to iterate over the files in a directory that are
     * larger than 8K.
     * <pre>
     *     DirectoryStream.Filter&lt;Path&gt; filter = new DirectoryStream.Filter&lt;Path&gt;() {
1001 1002 1003
     *         public boolean accept(Path file) throws IOException {
     *             long size = Attributes.readBasicFileAttributes(file).size();
     *             return (size > 8192L);
1004 1005 1006 1007 1008 1009
     *         }
     *     };
     *     Path dir = ...
     *     DirectoryStream&lt;Path&gt; stream = dir.newDirectoryStream(filter);
     * </pre>
     * @param   filter
1010
     *          the directory stream filter
1011
     *
1012
     * @return  a new and open {@code DirectoryStream} object
1013 1014
     *
     * @throws  NotDirectoryException
1015
     *          if the file could not otherwise be opened because it is not
1016 1017
     *          a directory <i>(optional specific exception)</i>
     * @throws  IOException
1018
     *          if an I/O error occurs
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the directory.
     */
    public abstract DirectoryStream<Path> newDirectoryStream(DirectoryStream.Filter<? super Path> filter)
        throws IOException;

    /**
     * Creates a new and empty file, failing if the file already exists.
     *
     * <p> This {@code Path} locates the file to create. The check for the
     * existence of the file and the creation of the new file if it does not
     * exist are a single operation that is atomic with respect to all other
     * filesystem activities that might affect the directory.
     *
     * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute
     * file-attributes} to set atomically when creating the file. Each attribute
     * is identified by its {@link FileAttribute#name name}. If more than one
     * attribute of the same name is included in the array then all but the last
     * occurrence is ignored.
     *
     * @param   attrs
1042
     *          an optional list of file attributes to set atomically when
1043 1044
     *          creating the file
     *
1045
     * @return  this path
1046 1047
     *
     * @throws  UnsupportedOperationException
1048
     *          if the array contains an attribute that cannot be set atomically
1049 1050
     *          when creating the file
     * @throws  FileAlreadyExistsException
1051
     *          if a file of that name already exists
1052 1053
     *          <i>(optional specific exception)</i>
     * @throws  IOException
1054
     *          if an I/O error occurs
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
     *          method is invoked to check write access to the new file.
     */
    public abstract Path createFile(FileAttribute<?>... attrs) throws IOException;

    /**
     * Creates a new directory.
     *
     * <p> This {@code Path} locates the directory to create. The check for the
     * existence of the file and the creation of the directory if it does not
     * exist are a single operation that is atomic with respect to all other
     * filesystem activities that might affect the directory.
     *
     * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute
     * file-attributes} to set atomically when creating the directory. Each
     * file attribute is identified by its {@link FileAttribute#name name}. If
     * more than one attribute of the same name is included in the array then all
     * but the last occurrence is ignored.
     *
     * @param   attrs
1077
     *          an optional list of file attributes to set atomically when
1078 1079
     *          creating the directory
     *
1080
     * @return  this path
1081 1082
     *
     * @throws  UnsupportedOperationException
1083
     *          if the array contains an attribute that cannot be set atomically
1084 1085
     *          when creating the directory
     * @throws  FileAlreadyExistsException
1086
     *          if a directory could not otherwise be created because a file of
1087 1088
     *          that name already exists <i>(optional specific exception)</i>
     * @throws  IOException
1089
     *          if an I/O error occurs
1090 1091 1092 1093
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
     *          method is invoked to check write access to the new directory.
1094 1095
     *
     * @see Files#createDirectories
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
     */
    public abstract Path createDirectory(FileAttribute<?>... attrs)
        throws IOException;

    /**
     * Opens or creates a file, returning a seekable byte channel to access the
     * file.
     *
     * <p> The {@code options} parameter determines how the file is opened.
     * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE WRITE}
     * options determine if the file should be opened for reading and/or writing.
     * If neither option (or the {@link StandardOpenOption#APPEND APPEND}
     * option) is contained in the array then the file is opened for reading.
     * By default reading or writing commences at the beginning of the file.
     *
     * <p> In the addition to {@code READ} and {@code WRITE}, the following
     * options may be present:
     *
     * <table border=1 cellpadding=5 summary="">
     * <tr> <th>Option</th> <th>Description</th> </tr>
     * <tr>
     *   <td> {@link StandardOpenOption#APPEND APPEND} </td>
     *   <td> If this option is present then the file is opened for writing and
     *     each invocation of the channel's {@code write} method first advances
     *     the position to the end of the file and then writes the requested
     *     data. Whether the advancement of the position and the writing of the
     *     data are done in a single atomic operation is system-dependent and
     *     therefore unspecified. This option may not be used in conjunction
     *     with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td>
     * </tr>
     * <tr>
     *   <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td>
     *   <td> If this option is present then the existing file is truncated to
     *   a size of 0 bytes. This option is ignored when the file is opened only
     *   for reading. </td>
     * </tr>
     * <tr>
     *   <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td>
     *   <td> If this option is present then a new file is created, failing if
     *   the file already exists or is a symbolic link. When creating a file the
     *   check for the existence of the file and the creation of the file if it
     *   does not exist is atomic with respect to other file system operations.
     *   This option is ignored when the file is opened only for reading. </td>
     * </tr>
     * <tr>
     *   <td > {@link StandardOpenOption#CREATE CREATE} </td>
     *   <td> If this option is present then an existing file is opened if it
     *   exists, otherwise a new file is created. This option is ignored if the
     *   {@code CREATE_NEW} option is also present or the file is opened only
     *   for reading. </td>
     * </tr>
     * <tr>
     *   <td > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </td>
     *   <td> When this option is present then the implementation makes a
     *   <em>best effort</em> attempt to delete the file when closed by the
     *   {@link SeekableByteChannel#close close} method. If the {@code close}
     *   method is not invoked then a <em>best effort</em> attempt is made to
     *   delete the file when the Java virtual machine terminates. </td>
     * </tr>
     * <tr>
     *   <td>{@link StandardOpenOption#SPARSE SPARSE} </td>
     *   <td> When creating a new file this option is a <em>hint</em> that the
     *   new file will be sparse. This option is ignored when not creating
     *   a new file. </td>
     * </tr>
     * <tr>
     *   <td> {@link StandardOpenOption#SYNC SYNC} </td>
     *   <td> Requires that every update to the file's content or metadata be
     *   written synchronously to the underlying storage device. (see <a
     *   href="package-summary.html#integrity"> Synchronized I/O file
     *   integrity</a>). </td>
     * <tr>
     * <tr>
     *   <td> {@link StandardOpenOption#DSYNC DSYNC} </td>
     *   <td> Requires that every update to the file's content be written
     *   synchronously to the underlying storage device. (see <a
     *   href="package-summary.html#integrity"> Synchronized I/O file
     *   integrity</a>). </td>
     * </tr>
     * </table>
     *
     * <p> An implementation may also support additional implementation specific
     * options.
     *
     * <p> The {@code attrs} parameter is an optional array of file {@link
     * FileAttribute file-attributes} to set atomically when a new file is created.
     *
     * <p> In the case of the default provider, the returned seekable byte channel
1184
     * is a {@link java.nio.channels.FileChannel}.
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
     *
     * <p> <b>Usage Examples:</b>
     * <pre>
     *     Path file = ...
     *
     *     // open file for reading
     *     ReadableByteChannel rbc = file.newByteChannel(EnumSet.of(READ)));
     *
     *     // open file for writing to the end of an existing file, creating
     *     // the file if it doesn't already exist
     *     WritableByteChannel wbc = file.newByteChannel(EnumSet.of(CREATE,APPEND));
     *
     *     // create file with initial permissions, opening it for both reading and writing
     *     FileAttribute&lt;Set&lt;PosixFilePermission&gt;&gt; perms = ...
     *     SeekableByteChannel sbc = file.newByteChannel(EnumSet.of(CREATE_NEW,READ,WRITE), perms);
     * </pre>
     *
     * @param   options
     *          Options specifying how the file is opened
     * @param   attrs
     *          An optional list of file attributes to set atomically when
     *          creating the file
     *
     * @return  a new seekable byte channel
     *
     * @throws  IllegalArgumentException
1211
     *          if the set contains an invalid combination of options
1212
     * @throws  UnsupportedOperationException
1213
     *          if an unsupported open option is specified or the array contains
1214 1215
     *          attributes that cannot be set atomically when creating the file
     * @throws  FileAlreadyExistsException
1216
     *          if a file of that name already exists and the {@link
1217 1218 1219
     *          StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
     *          <i>(optional specific exception)</i>
     * @throws  IOException
1220
     *          if an I/O error occurs
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the path if the file is
     *          opened for reading. The {@link SecurityManager#checkWrite(String)
     *          checkWrite} method is invoked to check write access to the path
     *          if the file is opened for writing.
     */
    public abstract SeekableByteChannel newByteChannel(Set<? extends OpenOption> options,
                                                       FileAttribute<?>... attrs)
        throws IOException;

    /**
     * Opens or creates a file, returning a seekable byte channel to access the
     * file.
     *
1237 1238 1239
     * <p> This method opens or creates a file in exactly the manner specified
     * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel}
     * method.
1240 1241
     *
     * @param   options
1242
     *          options specifying how the file is opened
1243 1244 1245 1246
     *
     * @return  a new seekable byte channel
     *
     * @throws  IllegalArgumentException
1247
     *          if the set contains an invalid combination of options
1248
     * @throws  UnsupportedOperationException
1249
     *          if an unsupported open option is specified
1250
     * @throws  FileAlreadyExistsException
1251
     *          if a file of that name already exists and the {@link
1252 1253 1254
     *          StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
     *          <i>(optional specific exception)</i>
     * @throws  IOException
1255
     *          if an I/O error occurs
1256 1257 1258
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
1259 1260 1261 1262
     *          method is invoked to check read access to the path if the file is
     *          opened for reading. The {@link SecurityManager#checkWrite(String)
     *          checkWrite} method is invoked to check write access to the path
     *          if the file is opened for writing.
1263
     */
1264
    public abstract SeekableByteChannel newByteChannel(OpenOption... options)
1265 1266 1267
        throws IOException;

    /**
1268 1269
     * Opens or creates the file located by this object for writing, returning
     * an output stream to write bytes to the file.
1270 1271 1272
     *
     * <p> This method opens or creates a file in exactly the manner specified
     * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel}
1273 1274
     * method except that the {@link StandardOpenOption#READ READ} option may not
     * be present in the array of open options.
1275 1276
     *
     * @param   options
1277
     *          options specifying how the file is opened
1278
     *
1279
     * @return  a new output stream
1280
     *
1281 1282 1283 1284
     * @throws  IllegalArgumentException            {@inheritDoc}
     * @throws  UnsupportedOperationException       {@inheritDoc}
     * @throws  IOException                         {@inheritDoc}
     * @throws  SecurityException                   {@inheritDoc}
1285
     */
1286 1287
    @Override
    public abstract OutputStream newOutputStream(OpenOption... options)
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
        throws IOException;

    /**
     * Tells whether or not the file located by this object is considered
     * <em>hidden</em>. The exact definition of hidden is platform or provider
     * dependent. On UNIX for example a file is considered to be hidden if its
     * name begins with a period character ('.'). On Windows a file is
     * considered hidden if it isn't a directory and the DOS {@link
     * DosFileAttributes#isHidden hidden} attribute is set.
     *
     * <p> Depending on the implementation this method may require to access
     * the file system to determine if the file is considered hidden.
     *
     * @return  {@code true} if the file is considered hidden
     *
     * @throws  IOException
1304
     *          if an I/O error occurs
1305 1306 1307 1308 1309 1310 1311
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the file.
     */
    public abstract boolean isHidden() throws IOException;

1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
    /**
     * Checks the existence and optionally the accessibility of the file
     * located by this path.
     *
     * <p> This method checks the existence of a file and that this Java virtual
     * machine has appropriate privileges that would allow it access the file
     * according to all of access modes specified in the {@code modes} parameter
     * as follows:
     *
     * <table border=1 cellpadding=5 summary="">
     * <tr> <th>Value</th> <th>Description</th> </tr>
     * <tr>
     *   <td> {@link AccessMode#READ READ} </td>
     *   <td> Checks that the file exists and that the Java virtual machine has
     *     permission to read the file. </td>
     * </tr>
     * <tr>
     *   <td> {@link AccessMode#WRITE WRITE} </td>
     *   <td> Checks that the file exists and that the Java virtual machine has
     *     permission to write to the file, </td>
     * </tr>
     * <tr>
     *   <td> {@link AccessMode#EXECUTE EXECUTE} </td>
     *   <td> Checks that the file exists and that the Java virtual machine has
     *     permission to {@link Runtime#exec execute} the file. The semantics
     *     may differ when checking access to a directory. For example, on UNIX
     *     systems, checking for {@code EXECUTE} access checks that the Java
     *     virtual machine has permission to search the directory in order to
     *     access file or subdirectories. </td>
     * </tr>
     * </table>
     *
     * <p> If the {@code modes} parameter is of length zero, then the existence
     * of the file is checked.
     *
     * <p> This method follows symbolic links if the file referenced by this
     * object is a symbolic link. Depending on the implementation, this method
     * may require to read file permissions, access control lists, or other
     * file attributes in order to check the effective access to the file. To
     * determine the effective access to a file may require access to several
     * attributes and so in some implementations this method may not be atomic
     * with respect to other file system operations. Furthermore, as the result
     * of this method is immediately outdated, there is no guarantee that a
     * subsequence access will succeed (or even that it will access the same
     * file). Care should be taken when using this method in security sensitive
     * applications.
     *
     * @param   modes
     *          The access modes to check; may have zero elements
     *
     * @throws  UnsupportedOperationException
     *          an implementation is required to support checking for
     *          {@code READ}, {@code WRITE}, and {@code EXECUTE} access. This
     *          exception is specified to allow for the {@code Access} enum to
     *          be extended in future releases.
     * @throws  NoSuchFileException
     *          if a file does not exist <i>(optional specific exception)</i>
     * @throws  AccessDeniedException
     *          the requested access would be denied or the access cannot be
     *          determined because the Java virtual machine has insufficient
     *          privileges or other reasons. <i>(optional specific exception)</i>
     * @throws  IOException
     *          if an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          is invoked when checking read access to the file or only the
     *          existence of the file, the {@link SecurityManager#checkWrite(String)
     *          checkWrite} is invoked when checking write access to the file,
     *          and {@link SecurityManager#checkExec(String) checkExec} is invoked
     *          when checking execute access.
     */
    public abstract void checkAccess(AccessMode... modes) throws IOException;

1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
    /**
     * Tests whether the file located by this path exists.
     *
     * <p> This convenience method is intended for cases where it is required to
     * take action when it can be confirmed that a file exists. This method simply
     * invokes the {@link #checkAccess checkAccess} method to check if the file
     * exists. If the {@code checkAccess} method succeeds then this method returns
     * {@code true}, otherwise if an {@code IOException} is thrown (because the
     * file doesn't exist or cannot be accessed by this Java virtual machine)
     * then {@code false} is returned.
     *
     * <p> Note that the result of this method is immediately outdated. If this
     * method indicates the file exists then there is no guarantee that a
     * subsequence access will succeed. Care should be taken when using this
     * method in security sensitive applications.
     *
     * @return  {@code true} if the file exists; {@code false} if the file does
     *          not exist or its existence cannot be determined.
     *
     * @throws  SecurityException
     *          In the case of the default provider, the {@link
     *          SecurityManager#checkRead(String)} is invoked to check
     *          read access to the file.
     *
     * @see #notExists
     */
    public abstract boolean exists();

    /**
     * Tests whether the file located by this path does not exist.
     *
     * <p> This convenience method is intended for cases where it is required to
     * take action when it can be confirmed that a file does not exist. This
     * method invokes the {@link #checkAccess checkAccess} method to check if the
     * file exists. If the file does not exist then {@code true} is returned,
     * otherwise the file exists or cannot be accessed by this Java virtual
     * machine and {@code false} is returned.
     *
     * <p> Note that this method is not the complement of the {@link #exists
     * exists} method. Where it is not possible to determine if a file exists
     * or not then both methods return {@code false}. As with the {@code exists}
     * method, the result of this method is immediately outdated. If this
     * method indicates the file does exist then there is no guarantee that a
     * subsequence attempt to create the file will succeed. Care should be taken
     * when using this method in security sensitive applications.
     *
     * @return  {@code true} if the file does not exist; {@code false} if the
     *          file exists or its existence cannot be determined.
     *
     * @throws  SecurityException
     *          In the case of the default provider, the {@link
     *          SecurityManager#checkRead(String)} is invoked to check
     *          read access to the file.
     */
    public abstract boolean notExists();

1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
    /**
     * Returns the {@link FileStore} representing the file store where an
     * existing file, located by this path, is stored.
     *
     * <p> Once a reference to the {@code FileStore} is obtained it is
     * implementation specific if operations on the returned {@code FileStore},
     * or {@link FileStoreAttributeView} objects obtained from it, continue
     * to depend on the existence of the file. In particular the behavior is not
     * defined for the case that the file is deleted or moved to a different
     * file store.
     *
     * @return  the file store where the file is stored
     *
     * @throws  IOException
     *          if an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the file, and in
     *          addition it checks {@link RuntimePermission}<tt>
     *          ("getFileStoreAttributes")</tt>
     */
    public abstract FileStore getFileStore() throws IOException;

1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
    // -- watchable --

    /**
     * Registers the file located by this path with a watch service.
     *
     * <p> In this release, this path locates a directory that exists. The
     * directory is registered with the watch service so that entries in the
     * directory can be watched. The {@code events} parameter is an array of
     * events to register and may contain the following events:
     * <ul>
     *   <li>{@link StandardWatchEventKind#ENTRY_CREATE ENTRY_CREATE} -
     *       entry created or moved into the directory</li>
     *   <li>{@link StandardWatchEventKind#ENTRY_DELETE ENTRY_DELETE} -
     *        entry deleted or moved out of the directory</li>
     *   <li>{@link StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} -
     *        entry in directory was modified</li>
     * </ul>
     *
     * <p> The {@link WatchEvent#context context} for these events is the
     * relative path between the directory located by this path, and the path
     * that locates the directory entry that is created, deleted, or modified.
     *
     * <p> The set of events may include additional implementation specific
     * event that are not defined by the enum {@link StandardWatchEventKind}
     *
     * <p> The {@code modifiers} parameter is an array of <em>modifiers</em>
     * that qualify how the directory is registered. This release does not
     * define any <em>standard</em> modifiers. The array may contain
     * implementation specific modifiers.
     *
     * <p> Where a file is registered with a watch service by means of a symbolic
     * link then it is implementation specific if the watch continues to depend
     * on the existence of the link after it is registered.
     *
     * @param   watcher
1501
     *          the watch service to which this object is to be registered
1502
     * @param   events
1503
     *          the events for which this object should be registered
1504
     * @param   modifiers
1505
     *          the modifiers, if any, that modify how the object is registered
1506
     *
1507
     * @return  a key representing the registration of this object with the
1508 1509 1510
     *          given watch service
     *
     * @throws  UnsupportedOperationException
1511
     *          if unsupported events or modifiers are specified
1512
     * @throws  IllegalArgumentException
1513
     *          if an invalid combination of events or modifiers is specified
1514
     * @throws  ClosedWatchServiceException
1515
     *          if the watch service is closed
1516
     * @throws  NotDirectoryException
1517
     *          if the file is registered to watch the entries in a directory
1518 1519
     *          and the file is not a directory  <i>(optional specific exception)</i>
     * @throws  IOException
1520
     *          if an I/O error occurs
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the file.
     */
    @Override
    public abstract WatchKey register(WatchService watcher,
                                      WatchEvent.Kind<?>[] events,
                                      WatchEvent.Modifier... modifiers)
        throws IOException;

    /**
     * Registers the file located by this path with a watch service.
     *
     * <p> An invocation of this method behaves in exactly the same way as the
     * invocation
     * <pre>
     *     watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);
     * </pre>
     *
     * <p> <b>Usage Example:</b>
     * Suppose we wish to register a directory for entry create, delete, and modify
     * events:
     * <pre>
     *     Path dir = ...
     *     WatchService watcher = ...
     *
     *     WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
     * </pre>
     * @param   watcher
     *          The watch service to which this object is to be registered
     * @param   events
     *          The events for which this object should be registered
     *
     * @return  A key representing the registration of this object with the
     *          given watch service
     *
     * @throws  UnsupportedOperationException
     *          If unsupported events are specified
     * @throws  IllegalArgumentException
     *          If an invalid combination of events is specified
     * @throws  ClosedWatchServiceException
     *          If the watch service is closed
     * @throws  NotDirectoryException
     *          If the file is registered to watch the entries in a directory
     *          and the file is not a directory  <i>(optional specific exception)</i>
     * @throws  IOException
     *          If an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to the file.
     */
    @Override
    public abstract WatchKey register(WatchService watcher,
                                      WatchEvent.Kind<?>... events)
        throws IOException;

    // -- Iterable --

    /**
     * Returns an iterator over the name elements of this path.
     *
     * <p> The first element returned by the iterator represents the name
     * element that is closest to the root in the directory hierarchy, the
     * second element is the next closest, and so on. The last element returned
     * is the name of the file or directory denoted by this path. The {@link
     * #getRoot root} component, if present, is not returned by the iterator.
     *
1590
     * @return  an iterator over the name elements of this path.
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
     */
    @Override
    public abstract Iterator<Path> iterator();

    // -- compareTo/equals/hashCode --

    /**
     * Compares two abstract paths lexicographically. The ordering defined by
     * this method is provider specific, and in the case of the default
     * provider, platform specific. This method does not access the file system
     * and neither file is required to exist.
     *
1603
     * @param   other  the path compared to this path.
1604
     *
1605
     * @return  zero if the argument is {@link #equals equal} to this path, a
1606 1607 1608 1609 1610 1611 1612
     *          value less than zero if this path is lexicographically less than
     *          the argument, or a value greater than zero if this path is
     *          lexicographically greater than the argument
     */
    @Override
    public abstract int compareTo(Path other);

1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
    /**
     * Tests if the file referenced by this object is the same file referenced
     * by another object.
     *
     * <p> If this {@code FileRef} and the given {@code FileRef} are {@link
     * #equals(Object) equal} then this method returns {@code true} without checking
     * if the file exists. If the {@code FileRef} and the given {@code FileRef}
     * are associated with different providers, or the given {@code FileRef} is
     * {@code null} then this method returns {@code false}. Otherwise, this method
     * checks if both {@code FileRefs} locate the same file, and depending on the
     * implementation, may require to open or access both files.
     *
     * <p> If the file system and files remain static, then this method implements
     * an equivalence relation for non-null {@code FileRefs}.
     * <ul>
     * <li>It is <i>reflexive</i>: for a non-null {@code FileRef} {@code f},
     *     {@code f.isSameFile(f)} should return {@code true}.
     * <li>It is <i>symmetric</i>: for two non-null {@code FileRefs}
     *     {@code f} and {@code g}, {@code f.isSameFile(g)} will equal
     *     {@code g.isSameFile(f)}.
     * <li>It is <i>transitive</i>: for three {@code FileRefs}
     *     {@code f}, {@code g}, and {@code h}, if {@code f.isSameFile(g)} returns
     *     {@code true} and {@code g.isSameFile(h)} returns {@code true}, then
     *     {@code f.isSameFile(h)} will return return {@code true}.
     * </ul>
     *
     * @param   other
     *          the other file reference
     *
     * @return  {@code true} if, and only if, this object and the given object
     *          locate the same file
     *
     * @throws  IOException
     *          if an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
     *          method is invoked to check read access to both files.
     *
     * @see java.nio.file.attribute.BasicFileAttributes#fileKey
     */
    public abstract boolean isSameFile(Path other) throws IOException;

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
    /**
     * Tests this path for equality with the given object.
     *
     * <p> If the given object is not a Path, or is a Path associated with a
     * different provider, then this method immediately returns {@code false}.
     *
     * <p> Whether or not two path are equal depends on the file system
     * implementation. In some cases the paths are compared without regard
     * to case, and others are case sensitive. This method does not access the
     * file system and the file is not required to exist.
     *
     * <p> This method satisfies the general contract of the {@link
     * java.lang.Object#equals(Object) Object.equals} method. </p>
     *
1670 1671
     * @param   other
     *          the object to which this object is to be compared
1672 1673 1674 1675 1676
     *
     * @return  {@code true} if, and only if, the given object is a {@code Path}
     *          that is identical to this {@code Path}
     */
    @Override
1677
    public abstract boolean equals(Object other);
1678 1679 1680 1681 1682 1683 1684 1685

    /**
     * Computes a hash code for this path.
     *
     * <p> The hash code is based upon the components of the path, and
     * satisfies the general contract of the {@link Object#hashCode
     * Object.hashCode} method.
     *
1686
     * @return  the hash-code value for this path
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
     */
    @Override
    public abstract int hashCode();

    /**
     * Returns the string representation of this path.
     *
     * <p> If this path was created by converting a path string using the
     * {@link FileSystem#getPath getPath} method then the path string returned
     * by this method may differ from the original String used to create the path.
     *
     * <p> The returned path string uses the default name {@link
     * FileSystem#getSeparator separator} to separate names in the path.
     *
1701
     * @return  the string representation of this path
1702 1703 1704 1705
     */
    @Override
    public abstract String toString();
}