1 /*
   2  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.nio.file;
  27 
  28 import java.io.File;
  29 import java.io.IOException;
  30 import java.net.URI;
  31 import java.util.Iterator;
  32 
  33 /**
  34  * An object that may be used to locate a file in a file system. It will
  35  * typically represent a system dependent file path.
  36  *
  37  * <p> A {@code Path} represents a path that is hierarchical and composed of a
  38  * sequence of directory and file name elements separated by a special separator
  39  * or delimiter. A <em>root component</em>, that identifies a file system
  40  * hierarchy, may also be present. The name element that is <em>farthest</em>
  41  * from the root of the directory hierarchy is the name of a file or directory.
  42  * The other name elements are directory names. A {@code Path} can represent a
  43  * root, a root and a sequence of names, or simply one or more name elements.
  44  * A {@code Path} is considered to be an <i>empty path</i> if it consists
  45  * solely of one name element that is empty. Accessing a file using an
  46  * <i>empty path</i> is equivalent to accessing the default directory of the
  47  * file system. {@code Path} defines the {@link #getFileName() getFileName},
  48  * {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath
  49  * subpath} methods to access the path components or a subsequence of its name
  50  * elements.
  51  *
  52  * <p> In addition to accessing the components of a path, a {@code Path} also
  53  * defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path)
  54  * resolveSibling} methods to combine paths. The {@link #relativize relativize}
  55  * method that can be used to construct a relative path between two paths.
  56  * Paths can be {@link #compareTo compared}, and tested against each other using
  57  * the {@link #startsWith startsWith} and {@link #endsWith endWith} methods.
  58  *
  59  * <p> This interface extends {@link Watchable} interface so that a directory
  60  * located by a path can be {@link #register registered} with a {@link
  61  * WatchService} and entries in the directory watched. </p>
  62  *
  63  * <p> <b>WARNING:</b> This interface is only intended to be implemented by
  64  * those developing custom file system implementations. Methods may be added to
  65  * this interface in future releases. </p>
  66  *
  67  * <a name="interop"><h4>Accessing Files</h4></a>
  68  * <p> Paths may be used with the {@link Files} class to operate on files,
  69  * directories, and other types of files. For example, suppose we want a {@link
  70  * java.io.BufferedReader} to read text from a file "{@code access.log}". The
  71  * file is located in a directory "{@code logs}" relative to the current working
  72  * directory and is UTF-8 encoded.
  73  * <pre>
  74  *     Path path = FileSystems.getDefault().getPath("logs", "access.log");
  75  *     BufferReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
  76  * </pre>
  77  *
  78  * <a name="interop"><h4>Interoperability</h4></a>
  79  * <p> Paths associated with the default {@link
  80  * java.nio.file.spi.FileSystemProvider provider} are generally interoperable
  81  * with the {@link java.io.File java.io.File} class. Paths created by other
  82  * providers are unlikely to be interoperable with the abstract path names
  83  * represented by {@code java.io.File}. The {@link java.io.File#toPath toPath}
  84  * method may be used to obtain a {@code Path} from the abstract path name
  85  * represented by a {@code java.io.File} object. The resulting {@code Path} can
  86  * be used to operate on the same file as the {@code java.io.File} object. In
  87  * addition, the {@link #toFile toFile} method is useful to construct a {@code
  88  * File} from the {@code String} representation of a {@code Path}.
  89  *
  90  * <h4>Concurrency</h4></a>
  91  * <p> Implementations of this interface are immutable and safe for use by
  92  * multiple concurrent threads.
  93  *
  94  * @since 1.7
  95  * @see Paths
  96  */
  97 
  98 public interface Path
  99     extends Comparable<Path>, Iterable<Path>, Watchable
 100 {
 101     /**
 102      * Returns the file system that created this object.
 103      *
 104      * @return  the file system that created this object
 105      */
 106     FileSystem getFileSystem();
 107 
 108     /**
 109      * Tells whether or not this path is absolute.
 110      *
 111      * <p> An absolute path is complete in that it doesn't need to be combined
 112      * with other path information in order to locate a file.
 113      *
 114      * @return  {@code true} if, and only if, this path is absolute
 115      */
 116     boolean isAbsolute();
 117 
 118     /**
 119      * Returns the root component of this path as a {@code Path} object,
 120      * or {@code null} if this path does not have a root component.
 121      *
 122      * @return  a path representing the root component of this path,
 123      *          or {@code null}
 124      */
 125     Path getRoot();
 126 
 127     /**
 128      * Returns the name of the file or directory denoted by this path as a
 129      * {@code Path} object. The file name is the <em>farthest</em> element from
 130      * the root in the directory hierarchy.
 131      *
 132      * @return  a path representing the name of the file or directory, or
 133      *          {@code null} if this path has zero elements
 134      */
 135     Path getFileName();
 136 
 137     /**
 138      * Returns the <em>parent path</em>, or {@code null} if this path does not
 139      * have a parent.
 140      *
 141      * <p> The parent of this path object consists of this path's root
 142      * component, if any, and each element in the path except for the
 143      * <em>farthest</em> from the root in the directory hierarchy. This method
 144      * does not access the file system; the path or its parent may not exist.
 145      * Furthermore, this method does not eliminate special names such as "."
 146      * and ".." that may be used in some implementations. On UNIX for example,
 147      * the parent of "{@code /a/b/c}" is "{@code /a/b}", and the parent of
 148      * {@code "x/y/.}" is "{@code x/y}". This method may be used with the {@link
 149      * #normalize normalize} method, to eliminate redundant names, for cases where
 150      * <em>shell-like</em> navigation is required.
 151      *
 152      * <p> If this path has one or more elements, and no root component, then
 153      * this method is equivalent to evaluating the expression:
 154      * <blockquote><pre>
 155      * subpath(0,&nbsp;getNameCount()-1);
 156      * </pre></blockquote>
 157      *
 158      * @return  a path representing the path's parent
 159      */
 160     Path getParent();
 161 
 162     /**
 163      * Returns the number of name elements in the path.
 164      *
 165      * @return  the number of elements in the path, or {@code 0} if this path
 166      *          only represents a root component
 167      */
 168     int getNameCount();
 169 
 170     /**
 171      * Returns a name element of this path as a {@code Path} object.
 172      *
 173      * <p> The {@code index} parameter is the index of the name element to return.
 174      * The element that is <em>closest</em> to the root in the directory hierarchy
 175      * has index {@code 0}. The element that is <em>farthest</em> from the root
 176      * has index {@link #getNameCount count}{@code -1}.
 177      *
 178      * @param   index
 179      *          the index of the element
 180      *
 181      * @return  the name element
 182      *
 183      * @throws  IllegalArgumentException
 184      *          if {@code index} is negative, {@code index} is greater than or
 185      *          equal to the number of elements, or this path has zero name
 186      *          elements
 187      */
 188     Path getName(int index);
 189 
 190     /**
 191      * Returns a relative {@code Path} that is a subsequence of the name
 192      * elements of this path.
 193      *
 194      * <p> The {@code beginIndex} and {@code endIndex} parameters specify the
 195      * subsequence of name elements. The name that is <em>closest</em> to the root
 196      * in the directory hierarchy has index {@code 0}. The name that is
 197      * <em>farthest</em> from the root has index {@link #getNameCount
 198      * count}{@code -1}. The returned {@code Path} object has the name elements
 199      * that begin at {@code beginIndex} and extend to the element at index {@code
 200      * endIndex-1}.
 201      *
 202      * @param   beginIndex
 203      *          the index of the first element, inclusive
 204      * @param   endIndex
 205      *          the index of the last element, exclusive
 206      *
 207      * @return  a new {@code Path} object that is a subsequence of the name
 208      *          elements in this {@code Path}
 209      *
 210      * @throws  IllegalArgumentException
 211      *          if {@code beginIndex} is negative, or greater than or equal to
 212      *          the number of elements. If {@code endIndex} is less than or
 213      *          equal to {@code beginIndex}, or larger than the number of elements.
 214      */
 215     Path subpath(int beginIndex, int endIndex);
 216 
 217     /**
 218      * Tests if this path starts with the given path.
 219      *
 220      * <p> This path <em>starts</em> with the given path if this path's root
 221      * component <em>starts</em> with the root component of the given path,
 222      * and this path starts with the same name elements as the given path.
 223      * If the given path has more name elements than this path then {@code false}
 224      * is returned.
 225      *
 226      * <p> Whether or not the root component of this path starts with the root
 227      * component of the given path is file system specific. If this path does
 228      * not have a root component and the given path has a root component then
 229      * this path does not start with the given path.
 230      *
 231      * <p> If the given path is associated with a different {@code FileSystem}
 232      * to this path then {@code false} is returned.
 233      *
 234      * @param   other
 235      *          the given path
 236      *
 237      * @return  {@code true} if this path starts with the given path; otherwise
 238      *          {@code false}
 239      */
 240     boolean startsWith(Path other);
 241 
 242     /**
 243      * Tests if this path starts with a {@code Path}, constructed by converting
 244      * the given path string, in exactly the manner specified by the {@link
 245      * #startsWith(Path) startsWith(Path)} method. On UNIX for example, the path
 246      * "{@code foo/bar}" starts with "{@code foo}" and "{@code foo/bar}". It
 247      * does not start with "{@code f}" or "{@code fo}".
 248      *
 249      * @param   other
 250      *          the given path string
 251      *
 252      * @return  {@code true} if this path starts with the given path; otherwise
 253      *          {@code false}
 254      *
 255      * @throws  InvalidPathException
 256      *          If the path string cannot be converted to a Path.
 257      */
 258     boolean startsWith(String other);
 259 
 260     /**
 261      * Tests if this path ends with the given path.
 262      *
 263      * <p> If the given path has <em>N</em> elements, and no root component,
 264      * and this path has <em>N</em> or more elements, then this path ends with
 265      * the given path if the last <em>N</em> elements of each path, starting at
 266      * the element farthest from the root, are equal.
 267      *
 268      * <p> If the given path has a root component then this path ends with the
 269      * given path if the root component of this path <em>ends with</em> the root
 270      * component of the given path, and the corresponding elements of both paths
 271      * are equal. Whether or not the root component of this path ends with the
 272      * root component of the given path is file system specific. If this path
 273      * does not have a root component and the given path has a root component
 274      * then this path does not end with the given path.
 275      *
 276      * <p> If the given path is associated with a different {@code FileSystem}
 277      * to this path then {@code false} is returned.
 278      *
 279      * @param   other
 280      *          the given path
 281      *
 282      * @return  {@code true} if this path ends with the given path; otherwise
 283      *          {@code false}
 284      */
 285     boolean endsWith(Path other);
 286 
 287     /**
 288      * Tests if this path ends with a {@code Path}, constructed by converting
 289      * the given path string, in exactly the manner specified by the {@link
 290      * #endsWith(Path) endsWith(Path)} method. On UNIX for example, the path
 291      * "{@code foo/bar}" ends with "{@code foo/bar}" and "{@code bar}". It does
 292      * not end with "{@code r}" or "{@code /bar}". Note that trailing separators
 293      * are not taken into account, and so invoking this method on the {@code
 294      * Path}"{@code foo/bar}" with the {@code String} "{@code bar/}" returns
 295      * {@code true}.
 296      *
 297      * @param   other
 298      *          the given path string
 299      *
 300      * @return  {@code true} if this path starts with the given path; otherwise
 301      *          {@code false}
 302      *
 303      * @throws  InvalidPathException
 304      *          If the path string cannot be converted to a Path.
 305      */
 306     boolean endsWith(String other);
 307 
 308     /**
 309      * Returns a path that is this path with redundant name elements eliminated.
 310      *
 311      * <p> The precise definition of this method is implementation dependent but
 312      * in general it derives from this path, a path that does not contain
 313      * <em>redundant</em> name elements. In many file systems, the "{@code .}"
 314      * and "{@code ..}" are special names used to indicate the current directory
 315      * and parent directory. In such file systems all occurrences of "{@code .}"
 316      * are considered redundant. If a "{@code ..}" is preceded by a
 317      * non-"{@code ..}" name then both names are considered redundant (the
 318      * process to identify such names is repeated until is it no longer
 319      * applicable).
 320      *
 321      * <p> This method does not access the file system; the path may not locate
 322      * a file that exists. Eliminating "{@code ..}" and a preceding name from a
 323      * path may result in the path that locates a different file than the original
 324      * path. This can arise when the preceding name is a symbolic link.
 325      *
 326      * @return  the resulting path or this path if it does not contain
 327      *          redundant name elements; an empty path is returned if this path
 328      *          does have a root component and all name elements are redundant
 329      *
 330      * @see #getParent
 331      * @see #toRealPath
 332      */
 333     Path normalize();
 334 
 335     // -- resolution and relativization --
 336 
 337     /**
 338      * Resolve the given path against this path.
 339      *
 340      * <p> If the {@code other} parameter is an {@link #isAbsolute() absolute}
 341      * path then this method trivially returns {@code other}. If {@code other}
 342      * is an <i>empty path</i> then this method trivially returns this path.
 343      * Otherwise this method considers this path to be a directory and resolves
 344      * the given path against this path. In the simplest case, the given path
 345      * does not have a {@link #getRoot root} component, in which case this method
 346      * <em>joins</em> the given path to this path and returns a resulting path
 347      * that {@link #endsWith ends} with the given path. Where the given path has
 348      * a root component then resolution is highly implementation dependent and
 349      * therefore unspecified.
 350      *
 351      * @param   other
 352      *          the path to resolve against this path
 353      *
 354      * @return  the resulting path
 355      *
 356      * @see #relativize
 357      */
 358     Path resolve(Path other);
 359 
 360     /**
 361      * Converts a given path string to a {@code Path} and resolves it against
 362      * this {@code Path} in exactly the manner specified by the {@link
 363      * #resolve(Path) resolve} method. For example, suppose that the name
 364      * separator is "{@code /}" and a path represents "{@code foo/bar}", then
 365      * invoking this method with the path string "{@code gus}" will result in
 366      * the {@code Path} "{@code foo/bar/gus}".
 367      *
 368      * @param   other
 369      *          the path string to resolve against this path
 370      *
 371      * @return  the resulting path
 372      *
 373      * @throws  InvalidPathException
 374      *          if the path string cannot be converted to a Path.
 375      *
 376      * @see FileSystem#getPath
 377      */
 378     Path resolve(String other);
 379 
 380     /**
 381      * Resolves the given path against this path's {@link #getParent parent}
 382      * path. This is useful where a file name needs to be <i>replaced</i> with
 383      * another file name. For example, suppose that the name separator is
 384      * "{@code /}" and a path represents "{@code dir1/dir2/foo}", then invoking
 385      * this method with the {@code Path} "{@code bar}" will result in the {@code
 386      * Path} "{@code dir1/dir2/bar}". If this path does not have a parent path,
 387      * or {@code other} is {@link #isAbsolute() absolute}, then this method
 388      * returns {@code other}. If {@code other} is an empty path then this method
 389      * returns this path's parent, or where this path doesn't have a parent, the
 390      * empty path.
 391      *
 392      * @param   other
 393      *          the path to resolve against this path's parent
 394      *
 395      * @return  the resulting path
 396      *
 397      * @see #resolve(Path)
 398      */
 399     Path resolveSibling(Path other);
 400 
 401     /**
 402      * Converts a given path string to a {@code Path} and resolves it against
 403      * this path's {@link #getParent parent} path in exactly the manner
 404      * specified by the {@link #resolveSibling(Path) resolveSibling} method.
 405      *
 406      * @param   other
 407      *          the path string to resolve against this path's parent
 408      *
 409      * @return  the resulting path
 410      *
 411      * @throws  InvalidPathException
 412      *          if the path string cannot be converted to a Path.
 413      *
 414      * @see FileSystem#getPath
 415      */
 416     Path resolveSibling(String other);
 417 
 418     /**
 419      * Constructs a relative path between this path and a given path.
 420      *
 421      * <p> Relativization is the inverse of {@link #resolve(Path) resolution}.
 422      * This method attempts to construct a {@link #isAbsolute relative} path
 423      * that when {@link #resolve(Path) resolved} against this path, yields a
 424      * path that locates the same file as the given path. For example, on UNIX,
 425      * if this path is {@code "/a/b"} and the given path is {@code "/a/b/c/d"}
 426      * then the resulting relative path would be {@code "c/d"}. Where this
 427      * path and the given path do not have a {@link #getRoot root} component,
 428      * then a relative path can be constructed. A relative path cannot be
 429      * constructed if only one of the paths have a root component. Where both
 430      * paths have a root component then it is implementation dependent if a
 431      * relative path can be constructed. If this path and the given path are
 432      * {@link #equals equal} then an <i>empty path</i> is returned.
 433      *
 434      * <p> For any two {@link #normalize normalized} paths <i>p</i> and
 435      * <i>q</i>, where <i>q</i> does not have a root component,
 436      * <blockquote>
 437      *   <i>p</i><tt>.relativize(</tt><i>p</i><tt>.resolve(</tt><i>q</i><tt>)).equals(</tt><i>q</i><tt>)</tt>
 438      * </blockquote>
 439      *
 440      * <p> When symbolic links are supported, then whether the resulting path,
 441      * when resolved against this path, yields a path that can be used to locate
 442      * the {@link Files#isSameFile same} file as {@code other} is implementation
 443      * dependent. For example, if this path is  {@code "/a/b"} and the given
 444      * path is {@code "/a/x"} then the resulting relative path may be {@code
 445      * "../x"}. If {@code "b"} is a symbolic link then is implementation
 446      * dependent if {@code "a/b/../x"} would locate the same file as {@code "/a/x"}.
 447      *
 448      * @param   other
 449      *          the path to relativize against this path
 450      *
 451      * @return  the resulting relative path, or an empty path if both paths are
 452      *          equal
 453      *
 454      * @throws  IllegalArgumentException
 455      *          if {@code other} is not a {@code Path} that can be relativized
 456      *          against this path
 457      */
 458     Path relativize(Path other);
 459 
 460     /**
 461      * Returns a URI to represent this path.
 462      *
 463      * <p> This method constructs a hierarchical {@link URI} that is absolute
 464      * with a non-empty path component. Its {@link URI#getScheme() scheme} is
 465      * equal to the URI scheme that identifies the provider. The exact form of
 466      * the other URI components is highly provider dependent. In particular, it
 467      * is implementation dependent if its query, fragment, and authority
 468      * components are defined or undefined.
 469      *
 470      * <p> For the default provider the {@link URI#getPath() path} component
 471      * will represent the {@link #toAbsolutePath absolute} path; the query,
 472      * fragment components are undefined. Whether the authority component is
 473      * defined or not is implementation dependent. There is no guarantee that
 474      * the {@code URI} may be used to construct a {@link java.io.File java.io.File}.
 475      * In particular, if this path represents a Universal Naming Convention (UNC)
 476      * path, then the UNC server name may be encoded in the authority component
 477      * of the resulting URI. In the case of the default provider, and the file
 478      * exists, and it can be determined that the file is a directory, then the
 479      * resulting {@code URI} will end with a slash.
 480      *
 481      * <p> The default provider provides a similar <em>round-trip</em> guarantee
 482      * to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
 483      * is guaranteed that
 484      * <blockquote><tt>
 485      * {@link Paths#get(URI) Paths.get}(</tt><i>p</i><tt>.toUri()).equals(</tt><i>p</i>
 486      * <tt>.{@link #toAbsolutePath() toAbsolutePath}())</tt>
 487      * </blockquote>
 488      * so long as the original {@code Path}, the {@code URI}, and the new {@code
 489      * Path} are all created in (possibly different invocations of) the same
 490      * Java virtual machine. Whether other providers make any guarantees is
 491      * provider specific and therefore unspecified.
 492      *
 493      * <p> When a file system is constructed to access the contents of a file
 494      * as a file system then it is highly implementation specific if the returned
 495      * URI represents the given path in the file system or it represents a
 496      * <em>compound</em> URI that encodes the URI of the enclosing file system.
 497      * A format for compound URIs is not defined in this release; such a scheme
 498      * may be added in a future release.
 499      *
 500      * @return  an absolute, hierarchical URI with a non-empty path component
 501      *
 502      * @throws  java.io.IOError
 503      *          if an I/O error occurs obtaining the absolute path, or where a
 504      *          file system is constructed to access the contents of a file as
 505      *          a file system, and the URI of the enclosing file system cannot be
 506      *          obtained
 507      *
 508      * @throws  SecurityException
 509      *          In the case of the default provider, and a security manager
 510      *          is installed, the {@link #toAbsolutePath toAbsolutePath} method
 511      *          throws a security exception.
 512      */
 513     URI toUri();
 514 
 515     /**
 516      * Returns a {@code Path} object representing the absolute path of this
 517      * path.
 518      *
 519      * <p> If this path is already {@link Path#isAbsolute absolute} then this
 520      * method simply returns this path. Otherwise, this method resolves the path
 521      * in an implementation dependent manner, typically by resolving the path
 522      * against a file system default directory. Depending on the implementation,
 523      * this method may throw an I/O error if the file system is not accessible.
 524      *
 525      * @return  a {@code Path} object representing the absolute path
 526      *
 527      * @throws  IOError
 528      *          if an I/O error occurs
 529      * @throws  SecurityException
 530      *          In the case of the default provider, a security manager
 531      *          is installed, and this path is not absolute, then the security
 532      *          manager's {@link SecurityManager#checkPropertyAccess(String)
 533      *          checkPropertyAccess} method is invoked to check access to the
 534      *          system property {@code user.dir}
 535      */
 536     Path toAbsolutePath();
 537 
 538     /**
 539      * Returns the <em>real</em> path of an existing file.
 540      *
 541      * <p> The precise definition of this method is implementation dependent but
 542      * in general it derives from this path, an {@link #isAbsolute absolute}
 543      * path that locates the {@link Files#isSameFile same} file as this path, but
 544      * with name elements that represent the actual name of the directories
 545      * and the file. For example, where filename comparisons on a file system
 546      * are case insensitive then the name elements represent the names in their
 547      * actual case. Additionally, the resulting path has redundant name
 548      * elements removed.
 549      *
 550      * <p> If this path is relative then its absolute path is first obtained,
 551      * as if by invoking the {@link #toAbsolutePath toAbsolutePath} method.
 552      *
 553      * <p> The {@code options} array may be used to indicate how symbolic links
 554      * are handled. By default, symbolic links are resolved to their final
 555      * target. If the option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is
 556      * present then this method does not resolve symbolic links.
 557      *
 558      * Some implementations allow special names such as "{@code ..}" to refer to
 559      * the parent directory. When deriving the <em>real path</em>, and a
 560      * "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then
 561      * an implementation will typically cause both names to be removed. When
 562      * not resolving symbolic links and the preceding name is a symbolic link
 563      * then the names are only removed if it guaranteed that the resulting path
 564      * will locate the same file as this path.
 565      *
 566      * @param   options
 567      *          options indicating how symbolic links are handled
 568      *
 569      * @return  an absolute path represent the <em>real</em> path of the file
 570      *          located by this object
 571      *
 572      * @throws  IOException
 573      *          if the file does not exist or an I/O error occurs
 574      * @throws  SecurityException
 575      *          In the case of the default provider, and a security manager
 576      *          is installed, its {@link SecurityManager#checkRead(String) checkRead}
 577      *          method is invoked to check read access to the file, and where
 578      *          this path is not absolute, its {@link SecurityManager#checkPropertyAccess(String)
 579      *          checkPropertyAccess} method is invoked to check access to the
 580      *          system property {@code user.dir}
 581      */
 582     Path toRealPath(LinkOption... options) throws IOException;
 583 
 584     /**
 585      * Returns a {@link File} object representing this path. Where this {@code
 586      * Path} is associated with the default provider, then this method is
 587      * equivalent to returning a {@code File} object constructed with the
 588      * {@code String} representation of this path.
 589      *
 590      * <p> If this path was created by invoking the {@code File} {@link
 591      * File#toPath toPath} method then there is no guarantee that the {@code
 592      * File} object returned by this method is {@link #equals equal} to the
 593      * original {@code File}.
 594      *
 595      * @return  a {@code File} object representing this path
 596      *
 597      * @throws  UnsupportedOperationException
 598      *          if this {@code Path} is not associated with the default provider
 599      */
 600     File toFile();
 601 
 602     // -- watchable --
 603 
 604     /**
 605      * Registers the file located by this path with a watch service.
 606      *
 607      * <p> In this release, this path locates a directory that exists. The
 608      * directory is registered with the watch service so that entries in the
 609      * directory can be watched. The {@code events} parameter is the events to
 610      * register and may contain the following events:
 611      * <ul>
 612      *   <li>{@link StandardWatchEventKind#ENTRY_CREATE ENTRY_CREATE} -
 613      *       entry created or moved into the directory</li>
 614      *   <li>{@link StandardWatchEventKind#ENTRY_DELETE ENTRY_DELETE} -
 615      *        entry deleted or moved out of the directory</li>
 616      *   <li>{@link StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} -
 617      *        entry in directory was modified</li>
 618      * </ul>
 619      *
 620      * <p> The {@link WatchEvent#context context} for these events is the
 621      * relative path between the directory located by this path, and the path
 622      * that locates the directory entry that is created, deleted, or modified.
 623      *
 624      * <p> The set of events may include additional implementation specific
 625      * event that are not defined by the enum {@link StandardWatchEventKind}
 626      *
 627      * <p> The {@code modifiers} parameter specifies <em>modifiers</em> that
 628      * qualify how the directory is registered. This release does not define any
 629      * <em>standard</em> modifiers. It may contain implementation specific
 630      * modifiers.
 631      *
 632      * <p> Where a file is registered with a watch service by means of a symbolic
 633      * link then it is implementation specific if the watch continues to depend
 634      * on the existence of the symbolic link after it is registered.
 635      *
 636      * @param   watcher
 637      *          the watch service to which this object is to be registered
 638      * @param   events
 639      *          the events for which this object should be registered
 640      * @param   modifiers
 641      *          the modifiers, if any, that modify how the object is registered
 642      *
 643      * @return  a key representing the registration of this object with the
 644      *          given watch service
 645      *
 646      * @throws  UnsupportedOperationException
 647      *          if unsupported events or modifiers are specified
 648      * @throws  IllegalArgumentException
 649      *          if an invalid combination of events or modifiers is specified
 650      * @throws  ClosedWatchServiceException
 651      *          if the watch service is closed
 652      * @throws  NotDirectoryException
 653      *          if the file is registered to watch the entries in a directory
 654      *          and the file is not a directory  <i>(optional specific exception)</i>
 655      * @throws  IOException
 656      *          if an I/O error occurs
 657      * @throws  SecurityException
 658      *          In the case of the default provider, and a security manager is
 659      *          installed, the {@link SecurityManager#checkRead(String) checkRead}
 660      *          method is invoked to check read access to the file.
 661      */
 662     @Override
 663     WatchKey register(WatchService watcher,
 664                       WatchEvent.Kind<?>[] events,
 665                       WatchEvent.Modifier... modifiers)
 666         throws IOException;
 667 
 668     /**
 669      * Registers the file located by this path with a watch service.
 670      *
 671      * <p> An invocation of this method behaves in exactly the same way as the
 672      * invocation
 673      * <pre>
 674      *     watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);
 675      * </pre>
 676      *
 677      * <p> <b>Usage Example:</b>
 678      * Suppose we wish to register a directory for entry create, delete, and modify
 679      * events:
 680      * <pre>
 681      *     Path dir = ...
 682      *     WatchService watcher = ...
 683      *
 684      *     WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
 685      * </pre>
 686      * @param   watcher
 687      *          The watch service to which this object is to be registered
 688      * @param   events
 689      *          The events for which this object should be registered
 690      *
 691      * @return  A key representing the registration of this object with the
 692      *          given watch service
 693      *
 694      * @throws  UnsupportedOperationException
 695      *          If unsupported events are specified
 696      * @throws  IllegalArgumentException
 697      *          If an invalid combination of events is specified
 698      * @throws  ClosedWatchServiceException
 699      *          If the watch service is closed
 700      * @throws  NotDirectoryException
 701      *          If the file is registered to watch the entries in a directory
 702      *          and the file is not a directory  <i>(optional specific exception)</i>
 703      * @throws  IOException
 704      *          If an I/O error occurs
 705      * @throws  SecurityException
 706      *          In the case of the default provider, and a security manager is
 707      *          installed, the {@link SecurityManager#checkRead(String) checkRead}
 708      *          method is invoked to check read access to the file.
 709      */
 710     @Override
 711     WatchKey register(WatchService watcher,
 712                       WatchEvent.Kind<?>... events)
 713         throws IOException;
 714 
 715     // -- Iterable --
 716 
 717     /**
 718      * Returns an iterator over the name elements of this path.
 719      *
 720      * <p> The first element returned by the iterator represents the name
 721      * element that is closest to the root in the directory hierarchy, the
 722      * second element is the next closest, and so on. The last element returned
 723      * is the name of the file or directory denoted by this path. The {@link
 724      * #getRoot root} component, if present, is not returned by the iterator.
 725      *
 726      * @return  an iterator over the name elements of this path.
 727      */
 728     @Override
 729     Iterator<Path> iterator();
 730 
 731     // -- compareTo/equals/hashCode --
 732 
 733     /**
 734      * Compares two abstract paths lexicographically. The ordering defined by
 735      * this method is provider specific, and in the case of the default
 736      * provider, platform specific. This method does not access the file system
 737      * and neither file is required to exist.
 738      *
 739      * <p> This method may not be used to compare paths that are associated
 740      * with different file system providers.
 741      *
 742      * @param   other  the path compared to this path.
 743      *
 744      * @return  zero if the argument is {@link #equals equal} to this path, a
 745      *          value less than zero if this path is lexicographically less than
 746      *          the argument, or a value greater than zero if this path is
 747      *          lexicographically greater than the argument
 748      *
 749      * @throws  ClassCastException
 750      *          if the paths are associated with different providers
 751      */
 752     @Override
 753     int compareTo(Path other);
 754 
 755     /**
 756      * Tests this path for equality with the given object.
 757      *
 758      * <p> If the given object is not a Path, or is a Path associated with a
 759      * different {@code FileSystem}, then this method returns {@code false}.
 760      *
 761      * <p> Whether or not two path are equal depends on the file system
 762      * implementation. In some cases the paths are compared without regard
 763      * to case, and others are case sensitive. This method does not access the
 764      * file system and the file is not required to exist. Where required, the
 765      * {@link Files#isSameFile isSameFile} method may be used to check if two
 766      * paths locate the same file.
 767      *
 768      * <p> This method satisfies the general contract of the {@link
 769      * java.lang.Object#equals(Object) Object.equals} method. </p>
 770      *
 771      * @param   other
 772      *          the object to which this object is to be compared
 773      *
 774      * @return  {@code true} if, and only if, the given object is a {@code Path}
 775      *          that is identical to this {@code Path}
 776      */
 777     boolean equals(Object other);
 778 
 779     /**
 780      * Computes a hash code for this path.
 781      *
 782      * <p> The hash code is based upon the components of the path, and
 783      * satisfies the general contract of the {@link Object#hashCode
 784      * Object.hashCode} method.
 785      *
 786      * @return  the hash-code value for this path
 787      */
 788     int hashCode();
 789 
 790     /**
 791      * Returns the string representation of this path.
 792      *
 793      * <p> If this path was created by converting a path string using the
 794      * {@link FileSystem#getPath getPath} method then the path string returned
 795      * by this method may differ from the original String used to create the path.
 796      *
 797      * <p> The returned path string uses the default name {@link
 798      * FileSystem#getSeparator separator} to separate names in the path.
 799      *
 800      * @return  the string representation of this path
 801      */
 802     String toString();
 803 }