diff --git a/jdk/make/java/java/FILES_java.gmk b/jdk/make/java/java/FILES_java.gmk index 83f3af7d968..58c7b13608c 100644 --- a/jdk/make/java/java/FILES_java.gmk +++ b/jdk/make/java/java/FILES_java.gmk @@ -412,6 +412,7 @@ JAVA_JAVA_java = \ java/io/FileReader.java \ java/io/PipedReader.java \ java/io/StringReader.java \ + java/io/TempFileHelper.java \ java/io/Writer.java \ java/io/BufferedWriter.java \ java/io/PrintWriter.java \ diff --git a/jdk/make/java/nio/FILES_java.gmk b/jdk/make/java/nio/FILES_java.gmk index 637b8dc4f96..4fb524a7dd4 100644 --- a/jdk/make/java/nio/FILES_java.gmk +++ b/jdk/make/java/nio/FILES_java.gmk @@ -86,8 +86,6 @@ FILES_src = \ java/nio/file/CopyOption.java \ java/nio/file/DirectoryNotEmptyException.java \ java/nio/file/DirectoryStream.java \ - java/nio/file/DirectoryStreamFilters.java \ - java/nio/file/FileAction.java \ java/nio/file/FileAlreadyExistsException.java \ java/nio/file/FileRef.java \ java/nio/file/FileStore.java \ @@ -141,6 +139,7 @@ FILES_src = \ java/nio/file/attribute/FileStoreAttributeView.java \ java/nio/file/attribute/FileStoreSpaceAttributeView.java \ java/nio/file/attribute/FileStoreSpaceAttributes.java \ + java/nio/file/attribute/FileTime.java \ java/nio/file/attribute/GroupPrincipal.java \ java/nio/file/attribute/UserDefinedFileAttributeView.java \ java/nio/file/attribute/PosixFileAttributeView.java \ @@ -151,7 +150,6 @@ FILES_src = \ java/nio/file/attribute/UserPrincipalLookupService.java \ java/nio/file/attribute/UserPrincipalNotFoundException.java \ \ - java/nio/file/spi/AbstractPath.java \ java/nio/file/spi/FileSystemProvider.java \ java/nio/file/spi/FileTypeDetector.java \ \ @@ -248,8 +246,8 @@ FILES_src = \ \ sun/nio/fs/AbstractAclFileAttributeView.java \ sun/nio/fs/AbstractBasicFileAttributeView.java \ - sun/nio/fs/AbstractFileStoreSpaceAttributeView.java \ sun/nio/fs/AbstractFileTypeDetector.java \ + sun/nio/fs/AbstractPath.java \ sun/nio/fs/AbstractPoller.java \ sun/nio/fs/AbstractUserDefinedFileAttributeView.java \ sun/nio/fs/AbstractWatchKey.java \ @@ -258,12 +256,13 @@ FILES_src = \ sun/nio/fs/Cancellable.java \ sun/nio/fs/DefaultFileSystemProvider.java \ sun/nio/fs/DefaultFileTypeDetector.java \ + sun/nio/fs/DynamicFileAttributeView.java \ sun/nio/fs/FileOwnerAttributeViewImpl.java \ sun/nio/fs/Globs.java \ - sun/nio/fs/MimeType.java \ sun/nio/fs/NativeBuffer.java \ sun/nio/fs/NativeBuffers.java \ sun/nio/fs/Reflect.java \ + sun/nio/fs/Util.java \ \ java/net/DatagramSocket.java \ java/net/DatagramSocketImpl.java \ diff --git a/jdk/make/java/nio/mapfile-linux b/jdk/make/java/nio/mapfile-linux index 13353edcdb7..79bdd1e5128 100644 --- a/jdk/make/java/nio/mapfile-linux +++ b/jdk/make/java/nio/mapfile-linux @@ -142,7 +142,7 @@ SUNWprivate_1.1 { Java_sun_nio_fs_LinuxNativeDispatcher_fremovexattr0; Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0; Java_sun_nio_fs_LinuxNativeDispatcher_endmntent; - Java_sun_nio_fs_UnixNativeDispatcher_initIDs; + Java_sun_nio_fs_UnixNativeDispatcher_init; Java_sun_nio_fs_UnixNativeDispatcher_getcwd; Java_sun_nio_fs_UnixNativeDispatcher_strerror; Java_sun_nio_fs_UnixNativeDispatcher_dup; diff --git a/jdk/make/java/nio/mapfile-solaris b/jdk/make/java/nio/mapfile-solaris index 129eaf477c0..b63fe38b8b5 100644 --- a/jdk/make/java/nio/mapfile-solaris +++ b/jdk/make/java/nio/mapfile-solaris @@ -120,7 +120,7 @@ SUNWprivate_1.1 { Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio; Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs; Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs; - Java_sun_nio_fs_UnixNativeDispatcher_initIDs; + Java_sun_nio_fs_UnixNativeDispatcher_init; Java_sun_nio_fs_UnixNativeDispatcher_getcwd; Java_sun_nio_fs_UnixNativeDispatcher_strerror; Java_sun_nio_fs_UnixNativeDispatcher_dup; diff --git a/jdk/src/share/classes/java/io/File.java b/jdk/src/share/classes/java/io/File.java index 6e58efbbd6b..4f7a413839a 100644 --- a/jdk/src/share/classes/java/io/File.java +++ b/jdk/src/share/classes/java/io/File.java @@ -30,15 +30,15 @@ import java.net.URI; import java.net.URL; import java.net.MalformedURLException; import java.net.URISyntaxException; -import java.util.*; -import java.nio.file.*; -import java.nio.file.attribute.*; +import java.util.List; +import java.util.ArrayList; import java.security.AccessController; -import java.security.PrivilegedAction; import java.security.SecureRandom; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileAttribute; import sun.security.action.GetPropertyAction; - /** * An abstract representation of file and directory pathnames. * @@ -787,7 +787,7 @@ public class File * java.lang.SecurityManager#checkRead(java.lang.String)} * method denies read access to the file * - * @see Attributes#readBasicFileAttributes + * @see java.nio.file.attribute.Attributes#readBasicFileAttributes */ public boolean isDirectory() { SecurityManager security = System.getSecurityManager(); @@ -813,7 +813,7 @@ public class File * java.lang.SecurityManager#checkRead(java.lang.String)} * method denies read access to the file * - * @see Attributes#readBasicFileAttributes + * @see java.nio.file.attribute.Attributes#readBasicFileAttributes */ public boolean isFile() { SecurityManager security = System.getSecurityManager(); @@ -863,7 +863,7 @@ public class File * java.lang.SecurityManager#checkRead(java.lang.String)} * method denies read access to the file * - * @see Attributes#readBasicFileAttributes + * @see java.nio.file.attribute.Attributes#readBasicFileAttributes */ public long lastModified() { SecurityManager security = System.getSecurityManager(); @@ -887,7 +887,7 @@ public class File * java.lang.SecurityManager#checkRead(java.lang.String)} * method denies read access to the file * - * @see Attributes#readBasicFileAttributes + * @see java.nio.file.attribute.Attributes#readBasicFileAttributes */ public long length() { SecurityManager security = System.getSecurityManager(); @@ -1369,9 +1369,10 @@ public class File * Sets the owner's or everybody's write permission for this abstract * pathname. * - *
The {@link Attributes Attributes} class defines methods that operate - * on file attributes including file permissions. This may be used when - * finer manipulation of file permissions is required. + *
The {@link java.nio.file.attribute.Attributes Attributes} class
+ * defines methods that operate on file attributes including file
+ * permissions. This may be used when finer manipulation of file permissions
+ * is required.
*
* @param writable
* If true
, sets the access permission to allow write
@@ -1436,9 +1437,10 @@ public class File
* Sets the owner's or everybody's read permission for this abstract
* pathname.
*
- *
The {@link Attributes Attributes} class defines methods that operate - * on file attributes including file permissions. This may be used when - * finer manipulation of file permissions is required. + *
The {@link java.nio.file.attribute.Attributes Attributes} class
+ * defines methods that operate on file attributes including file
+ * permissions. This may be used when finer manipulation of file permissions
+ * is required.
*
* @param readable
* If true
, sets the access permission to allow read
@@ -1509,9 +1511,10 @@ public class File
* Sets the owner's or everybody's execute permission for this abstract
* pathname.
*
- *
The {@link Attributes Attributes} class defines methods that operate - * on file attributes including file permissions. This may be used when - * finer manipulation of file permissions is required. + *
The {@link java.nio.file.attribute.Attributes Attributes} class
+ * defines methods that operate on file attributes including file
+ * permissions. This may be used when finer manipulation of file permissions
+ * is required.
*
* @param executable
* If The {@link #createTemporaryFile(String,String,FileAttribute[])} method
+ * provides an alternative method to create an empty file in the
+ * temporary-file directory. Files created by that method may have more
+ * restrictive access permissions to files created by this method and so
+ * may be more suited to security-sensitive applications.
+ *
* @param prefix The prefix string to be used in generating the file's
* name; must be at least three characters long
*
@@ -1926,17 +1916,7 @@ public class File
/**
* Creates an empty file in the default temporary-file directory, using
- * the given prefix and suffix to generate its name. This method is
- * equivalent to invoking the {@link #createTempFile(String,String)
- * createTempFile(prefix, suffix)} method with the addition that the
- * resulting pathname may be requested to be deleted when the Java virtual
- * machine terminates, and the initial file attributes to set atomically
- * when creating the file may be specified.
- *
- * When the value of the {@code deleteOnExit} method is {@code true}
- * then the resulting file is requested to be deleted when the Java virtual
- * machine terminates as if by invoking the {@link #deleteOnExit deleteOnExit}
- * method.
+ * the given prefix and suffix to generate its name.
*
* The {@code attrs} parameter is an optional array of {@link FileAttribute
* attributes} to set atomically when creating the file. Each attribute is
@@ -1944,6 +1924,12 @@ public class File
* of the same name is included in the array then all but the last occurrence
* is ignored.
*
+ * Where the {@code attrs} parameter does not specify access
+ * permissions to set atomically when creating the file, then the
+ * resulting file may have more restrictive access permissions than files
+ * created by the {@link #createTempFile(java.lang.String, java.lang.String)}
+ * method.
+ *
* @param prefix
* The prefix string to be used in generating the file's
* name; must be at least three characters long
@@ -1951,9 +1937,6 @@ public class File
* The suffix string to be used in generating the file's
* name; may be {@code null}, in which case the suffix
* {@code ".tmp"} will be used
- * @param deleteOnExit
- * {@code true} if the file denoted by resulting pathname be
- * deleted when the Java virtual machine terminates
* @param attrs
* An optional list of file attributes to set atomically when creating
* the file
@@ -1961,7 +1944,7 @@ public class File
* @return An abstract pathname denoting a newly-created empty file
*
* @throws IllegalArgumentException
- * If the The first invocation of this method works as if invoking it were
+ * equivalent to evaluating the expression:
* If this abstract pathname is the empty abstract pathname then this
- * method returns a {@code Path} that may be used to access to the current
+ * method returns a {@code Path} that may be used to access the current
* user directory.
*
- * @return A {@code Path} constructed from this abstract path. The resulting
- * {@code Path} is associated with the {@link FileSystems#getDefault
- * default-filesystem}.
+ * @return a {@code Path} constructed from this abstract path
*
* @throws InvalidPathException
- * If a {@code Path} object cannot be constructed from the abstract
+ * if a {@code Path} object cannot be constructed from the abstract
* path (see {@link java.nio.file.FileSystem#getPath FileSystem.getPath})
*
* @since 1.7
*/
public Path toPath() {
- if (filePath == null) {
+ Path result = filePath;
+ if (result == null) {
synchronized (this) {
- if (filePath == null) {
+ result = filePath;
+ if (result == null) {
if (path.length() == 0) {
// assume default file system treats "." as current directory
- filePath = Paths.get(".");
+ result = Paths.get(".");
} else {
- filePath = Paths.get(path);
+ result = Paths.get(path);
}
+ filePath = result;
}
}
}
- return filePath;
+ return result;
}
}
diff --git a/jdk/src/share/classes/java/io/TempFileHelper.java b/jdk/src/share/classes/java/io/TempFileHelper.java
new file mode 100644
index 00000000000..f3b518a2690
--- /dev/null
+++ b/jdk/src/share/classes/java/io/TempFileHelper.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 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.io;
+
+import java.nio.file.FileSystems;
+import java.nio.file.InvalidPathException;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import static java.nio.file.attribute.PosixFilePermission.*;
+import java.util.Set;
+import java.util.EnumSet;
+
+/**
+ * Helper class to support creation of temporary files and directory with
+ * initial attributes.
+ */
+
+class TempFileHelper {
+ private TempFileHelper() { }
+
+ // default file and directory permissions (lazily initialized)
+ private static class PermissionsHolder {
+ static final boolean hasPosixPermissions = FileSystems.getDefault()
+ .supportedFileAttributeViews().contains("posix");
+ static final FileAttribute A {@code DirectoryStream} is opened upon creation and is closed by
* invoking the {@link #close close} method. Closing the directory stream
- * releases any resources associated with the stream. The {@link
- * Files#withDirectory Files.withDirectory} utility method is useful for cases
- * where a task is performed on entries in a directory. This method automatically
- * closes the directory stream when iteration is complete (or an error occurs).
- * Once a directory stream is closed, all further method invocations on the
- * iterator throw {@link java.util.concurrent.ConcurrentModificationException}
- * with cause {@link ClosedDirectoryStreamException}.
+ * releases any resources associated with the stream. Once a directory stream
+ * is closed, all further method invocations on the iterator throw {@link
+ * java.util.concurrent.ConcurrentModificationException} with cause {@link
+ * ClosedDirectoryStreamException}.
*
* A directory stream is not required to be asynchronously closeable.
* If a thread is blocked on the directory stream's iterator reading from the
@@ -79,7 +77,7 @@ import java.io.Closeable;
*
* The iterator's {@link Iterator#remove() remove} method removes the
* directory entry for the last element returned by the iterator, as if by
- * invoking the {@link FileRef#delete delete} method. If an I/O error or
+ * invoking the {@link Path#delete delete} method. If an I/O error or
* security exception occurs then {@code ConcurrentModificationException} is
* thrown with the cause.
*
@@ -104,10 +102,6 @@ public interface DirectoryStream The {@link DirectoryStreamFilters} class defines factory methods to
- * create filters for a number of common usages and also methods to combine
- * filters.
- *
* @param The {@code type} parameter is the value of a Multipurpose Internet
- * Mail Extension (MIME) content type as defined by RFC 2045: Multipurpose
- * Internet Mail Extensions (MIME) Part One: Format of Internet Message
- * Bodies. It is parsable according to the grammar in the RFC. Any
- * space characters ( The {@code accept} method of the resulting directory stream filter
- * throws {@link IOError} if the probing of the content type fails by
- * throwing an {@link IOException}. Security exceptions are also propogated
- * to the caller of the {@code accept} method.
- *
- * Usage Example:
- * Suppose we require to list only the HTML files in a directory.
- * This method returns a filter that invokes, in iterator order, the
- * {@code accept} method of each of the filters. If {@code false} is returned
- * by any of the filters then the directory entry is filtered. If the
- * directory entry is not filtered then the resulting filter accepts the
- * entry. If the iterator returns zero elements then the resulting filter
- * accepts all directory entries.
- *
- * Usage Example:
- * This method returns a filter that invokes, in iteration order, the
- * {@code accept} method of each of filter. If {@code true} is returned by
- * any of the filters then the directory entry is accepted. If none of the
- * filters accepts the directory entry then it is filtered. If the iterator
- * returns zero elements then the resulting filter filters all directory
- * entries.
- *
- * @param filters
- * the sequence of filters
- *
- * @return the resulting filter
- */
- public static A {@code FileRef} is an object that locates a file and defines methods to
- * access the file. The means by which the file is located depends on the
- * implementation. In many cases, a file is located by a {@link Path} but it may
- * be located by other means such as a file-system identifier.
- *
- * This interface defines the following operations:
- * The {@link #newByteChannel newByteChannel} method
- * may be used to open a file and obtain a byte channel for reading or
- * writing. The {@link #delete delete} method may be used to delete a file.
- * The {@link #checkAccess checkAccess} method may be used to check
- * the existence or accessibility of a file. The {@link #isSameFile isSameFile} method may be used to test if
- * two file references locate the same file. The {@link #getFileStore getFileStore} method may be used to
- * obtain the {@link FileStore} representing the storage where a file is
- * located. Access to associated metadata or file attributes requires an appropriate
- * {@link FileAttributeView FileAttributeView}. The {@link
- * #getFileAttributeView(Class,LinkOption[]) getFileAttributeView(Class,LinkOption[])}
- * method may be used to obtain a file attribute view that defines type-safe
- * methods to read or update file attributes. The {@link
- * #getFileAttributeView(String,LinkOption[]) getFileAttributeView(String,LinkOption[])}
- * method may be used to obtain a file attribute view where dynamic access to
- * file attributes where required.
- *
- * A {@code FileRef} is immutable and safe for use by multiple concurrent
- * threads.
+ * open the file for reading or writing. It also provides access to associated
+ * metadata or file attributes.
*
* @since 1.7
+ * @see java.io.Inputs
+ * @see java.io.Outputs
+ * @see java.nio.file.attribute.Attributes
+ * @see java.io.File#toPath
*/
public interface FileRef {
/**
- * Opens the file referenced by this object, returning a seekable byte
- * channel to access the file.
+ * Opens the file referenced by this object, returning an input stream to
+ * read from the file. The stream will not be buffered, and is not required
+ * to support the {@link InputStream#mark mark} or {@link InputStream#reset
+ * reset} methods. The stream will be safe for access by multiple concurrent
+ * threads. Reading commences at the beginning of the file.
*
* 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.
+ * If no options are present then it is equivalent to opening the file with
+ * the {@link StandardOpenOption#READ READ} option. In addition to the {@code
+ * READ} option, an implementation may also support additional implementation
+ * specific options.
*
- * In the addition to {@code READ} and {@code WRITE}, the following
- * options may be present:
- *
- * An implementation of this interface may support additional options
- * defined by the {@link StandardOpenOption} enumeration type or other
- * implementation specific options.
- *
- * The {@link java.nio.channels.Channels} utility classes defines methods
- * to construct input and output streams where inter-operation with the
- * {@link java.io} package is required.
- *
- * @param options
- * Options specifying how the file is opened
- *
- * @return a new seekable byte channel
+ * @return an input stream to read bytes from the file
*
* @throws IllegalArgumentException
- * If an invalid combination of options is specified
+ * if an invalid combination of options is specified
* @throws UnsupportedOperationException
- * If an unsupported open option is specified
+ * if an unsupported option is specified
* @throws IOException
- * If an I/O error occurs
+ * 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 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.
+ * method is invoked to check read access to the file.
*/
- SeekableByteChannel newByteChannel(OpenOption... options)
- throws IOException;
+ InputStream newInputStream(OpenOption... options) throws IOException;
/**
- * Returns the {@link FileStore} representing the file store where the file
- * referenced by this object is stored.
+ * Opens or creates the file located by this object for writing, returning
+ * an output stream to write bytes to the file.
*
- * 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.
+ * The {@code options} parameter determines how the file is opened.
+ * If no options are present then this method creates a new file for writing
+ * or truncates an existing file. In addition to the {@link StandardOpenOption
+ * standard} options, an implementation may also support additional
+ * implementation specific options.
*
- * @return The file store where the file is stored
+ * The resulting stream will not be buffered. The stream will be safe
+ * for access by multiple concurrent threads.
*
- * @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}
- * ("getFileStoreAttributes")
- */
- FileStore getFileStore() throws IOException;
-
- /**
- * Checks the existence and optionally the accessibility of the file
- * referenced by this object.
+ * @param options
+ * options specifying how the file is opened
*
- * 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:
- *
- * If the {@code modes} parameter is of length zero, then the existence
- * of the file is checked.
- *
- * 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
+ * @return a new output stream
*
+ * @throws IllegalArgumentException
+ * if {@code options} contains an invalid combination of options
* @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 (optional specific exception)
- * @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. (optional specific exception)
+ * if an unsupported option is specified
* @throws IOException
- * If an I/O error occurs
+ * 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.
+ * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
+ * method is invoked to check write access to the file.
*/
- void checkAccess(AccessMode... modes) throws IOException;
+ OutputStream newOutputStream(OpenOption... options) throws IOException;
/**
* Returns a file attribute view of a given type.
@@ -266,11 +126,11 @@ public interface FileRef {
* that do not support symbolic links.
*
* @param type
- * The {@code Class} object corresponding to the file attribute view
+ * the {@code Class} object corresponding to the file attribute view
* @param options
- * Options indicating how symbolic links are handled
+ * options indicating how symbolic links are handled
*
- * @return A file attribute view of the specified type, or {@code null} if
+ * @return a file attribute view of the specified type, or {@code null} if
* the attribute view type is not available
*
* @throws UnsupportedOperationException
@@ -280,145 +140,185 @@ public interface FileRef {
*
* @see Attributes#readBasicFileAttributes
*/
- A file attribute view provides a read-only or updatable view of a
- * set of file attributes. This method is intended to be used where
- * dynamic access to the file attributes is required. The {@code
- * name} parameter specifies the {@link FileAttributeView#name name} of the
- * file attribute view and this method returns an instance of that view if
- * supported. The {@link BasicFileAttributeView} type supports access to the
- * basic attributes of a file and is name {@code "basic"}. Invoking this
- * method to select a file attribute view named {@code "basic"} will always
- * return an instance of that class.
+ * The {@code attribute} parameter identifies the attribute to be set
+ * and takes the form:
+ * view-name is the {@link FileAttributeView#name name} of a {@link
+ * FileAttributeView} that identifies a set of file attributes. If not
+ * specified then it defaults to {@code "basic"}, the name of the file
+ * attribute view that identifies the basic set of file attributes common to
+ * many file systems. attribute-name is the name of the attribute
+ * within the set.
+ *
+ * Usage Example:
+ * Suppose we want to set the DOS "hidden" attribute:
+ * The {@code attribute} parameter identifies the attribute to be read
+ * and takes the form:
+ * view-name is the {@link FileAttributeView#name name} of a {@link
+ * FileAttributeView} that identifies a set of file attributes. If not
+ * specified then it defaults to {@code "basic"}, the name of the file
+ * attribute view that identifies the basic set of file attributes common to
+ * many file systems. attribute-name is the name of the attribute.
*
* The {@code options} array may be used to indicate how symbolic links
- * are handled by the resulting file attribute view for the case that the
- * file is a symbolic link. By default, symbolic links are followed. If the
- * option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is present then
- * symbolic links are not followed. This option is ignored by implementations
- * that do not support symbolic links.
+ * are handled for the case that the file is a symbolic link. By default,
+ * symbolic links are followed and the file attribute of the final target
+ * of the link is read. If the option {@link LinkOption#NOFOLLOW_LINKS
+ * NOFOLLOW_LINKS} is present then symbolic links are not followed and so
+ * the method returns the file attribute of the symbolic link.
*
- * @param name
- * The name of the file attribute view
+ * Usage Example:
+ * Suppose we require the user ID of the file owner on a system that
+ * supports a "{@code unix}" view:
+ * The {@code attributes} parameter identifies the attributes to be read
+ * and takes the form:
+ * view-name is the {@link FileAttributeView#name name} of a {@link
+ * FileAttributeView} that identifies a set of file attributes. If not
+ * specified then it defaults to {@code "basic"}, the name of the file
+ * attribute view that identifies the basic set of file attributes common to
+ * many file systems.
+ *
+ * The attribute-list component is a comma separated list of
+ * zero or more names of attributes to read. If the list contains the value
+ * {@code "*"} then all attributes are read. Attributes that are not supported
+ * are ignored and will not be present in the returned map. It is
+ * implementation specific if all attributes are read as an atomic operation
+ * with respect to other file system operations.
+ *
+ * The following examples demonstrate possible values for the {@code
+ * attributes} parameter:
+ *
+ * The {@code options} array may be used to indicate how symbolic links
+ * are handled for the case that the file is a symbolic link. By default,
+ * symbolic links are followed and the file attribute of the final target
+ * of the link is read. If the option {@link LinkOption#NOFOLLOW_LINKS
+ * NOFOLLOW_LINKS} is present then symbolic links are not followed and so
+ * the method returns the file attribute of the symbolic link.
+ *
+ * @param attributes
+ * The attributes to read
* @param options
* Options indicating how symbolic links are handled
*
- * @return A file attribute view of the given name, or {@code null} if
- * the attribute view is not available
- *
- * @throws UnsupportedOperationException
- * If options contains an unsupported option. This exception is
- * specified to allow the {@code LinkOption} enum be extended
- * in future releases.
- */
- FileAttributeView getFileAttributeView(String name, LinkOption... options);
-
- /**
- * Tests if the file referenced by this object is the same file referenced
- * by another object.
- *
- * 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.
- *
- * If the file system and files remain static, then this method implements
- * an equivalence relation for non-null {@code FileRefs}.
- * 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.
- *
- * 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.
- *
- * 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 (optional specific exception)
- * @throws DirectoryNotEmptyException
- * If the file is a directory and could not otherwise be deleted
- * because the directory is not empty (optional specific
- * exception)
- * @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
- */
- void delete() throws IOException;
-
- /**
- * Tests this object for equality with another object.
- *
- * If the given object is not a {@code FileRef} then this method
- * immediately returns {@code false}.
- *
- * For two file references to be considered equal requires that they
- * are both the same type of {@code FileRef} and encapsulate components
- * to locate the same file. This method does not access the file system and
- * the file may not exist.
- *
- * This method satisfies the general contract of the {@link
- * java.lang.Object#equals(Object) Object.equals} method. This method satisfies the general contract of the
- * {@link java.lang.Object#hashCode() Object.hashCode} method.
- */
- int hashCode();
+ Map This method is intended to be used where dynamic access to
- * file store attributes is required. The {@code name} parameter specifies
- * the {@link FileAttributeView#name name} of the file store attribute view
- * and this method returns an instance of that view if supported.
+ * The {@code attribute} parameter identifies the attribute to be read
+ * and takes the form:
+ * view-name is the {@link FileStoreAttributeView#name name} of
+ * a {@link FileStore AttributeView} that identifies a set of file attributes.
+ * attribute-name is the name of the attribute.
*
* For {@code FileStore} objects created by the default provider, then
* the file stores support the {@link FileStoreSpaceAttributeView} that
- * provides access to space attributes. In that case invoking this method
- * with a parameter value of {@code "space"} will always return an instance
- * of that class.
+ * provides access to space attributes.
*
- * @param name
- * the name of the attribute view
+ * Usage Example:
+ * Suppose we want to know if ZFS compression is enabled (assuming the "zfs"
+ * view is supported):
+ * This method opens the given directory and invokes the file action's
- * {@link FileAction#invoke invoke} method for each entry accepted by the
- * filter. When iteration is completed then the directory is closed. If the
- * {@link DirectoryStream#close close} method throws an {@code IOException}
- * then it is silently ignored.
- *
- * If the {@code FileAction}'s {@code invoke} method terminates due
- * to an uncaught {@link IOException}, {@code Error} or {@code RuntimeException}
- * then the exception is propagated by this method after closing the
- * directory.
- *
- * @param dir
- * The directory
- * @param filter
- * The filter
- * @param action
- * The {@code FileAction} to invoke for each accepted entry
- *
- * @throws NotDirectoryException
- * If the {@code dir} parameter is not a directory (optional
- * specific exception)
- * @throws IOException
- * If an I/O error occurs or the {@code invoke} method terminates
- * due to an uncaught {@code IOException}
- * @throws SecurityException
- * In the case of the default provider, the {@link
- * SecurityManager#checkRead(String) checkRead} method is invoked
- * to check read access to the directory.
- */
- public static void withDirectory(Path dir,
- DirectoryStream.Filter super Path> filter,
- FileAction super Path> action)
- throws IOException
- {
- // explicit null check required in case directory is empty
- if (action == null)
- throw new NullPointerException();
-
- DirectoryStream This method opens the given directory and invokes the file action's
- * {@link FileAction#invoke invoke} method for each entry that matches the
- * given pattern. When iteration is completed then the directory is closed.
- * If the {@link DirectoryStream#close close} method throws an {@code
- * IOException} then it is silently ignored.
- *
- * If the {@code FileAction}'s {@code invoke} method terminates due
- * to an uncaught {@link IOException}, {@code Error} or {@code RuntimeException}
- * then the exception is propagated by this method after closing the
- * directory.
- *
- * The globbing pattern language supported by this method is as
- * specified by the {@link FileSystem#getPathMatcher getPathMatcher} method.
- *
- * @param dir
- * The directory
- * @param glob
- * The globbing pattern
- * @param action
- * The {@code FileAction} to invoke for each entry
- *
- * @throws NotDirectoryException
- * If the {@code dir} parameter is not a directory (optional
- * specific exception)
- * @throws IOException
- * If an I/O error occurs or the {@code invoke} method terminates
- * due to an uncaught {@code IOException}
- * @throws SecurityException
- * In the case of the default provider, the {@link
- * SecurityManager#checkRead(String) checkRead} method is invoked
- * to check read access to the directory.
- */
- public static void withDirectory(Path dir,
- String glob,
- FileAction super Path> action)
- throws IOException
- {
- if (glob == null)
- throw new NullPointerException("'glob' is null");
- final PathMatcher matcher = dir.getFileSystem().getPathMatcher("glob:" + glob);
- DirectoryStream.Filter This method works as if invoking it were equivalent to evaluating the
- * expression:
- * The {@code attrs} parameter is an optional array of {@link FileAttribute
+ * file-attributes} to set atomically when creating the nonexistent
+ * directories. 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.
+ *
+ * If this method fails, then it may do so after creating some, but not
+ * all, of the parent directories.
+ *
+ * @param dir
+ * the directory to create
+ *
+ * @param attrs
+ * an optional list of file attributes to set atomically when
+ * creating the directory
+ *
+ * @throws UnsupportedOperationException
+ * if the array contains an attribute that cannot be set atomically
+ * when creating the directory
+ * @throws FileAlreadyExistsException
+ * if {@code dir} exists but is not a directory (optional specific
+ * exception)
+ * @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#checkWrite(String) checkWrite}
+ * method is invoked prior to attempting to create a directory and
+ * its {@link SecurityManager#checkRead(String) checkRead} is
+ * invoked for each parent directory that is checked. If {@code
+ * dir} is not an absolute path then its {@link Path#toAbsolutePath
+ * toAbsolutePath} may need to be invoked to get its absolute path.
+ * This may invoke the security manager's {@link
+ * SecurityManager#checkPropertyAccess(String) checkPropertyAccess}
+ * method to check access to the system property {@code user.dir}
+ *
+ */
+ public static void createDirectories(Path dir, FileAttribute>... attrs)
+ throws IOException
+ {
+ // attempt to create the directory
+ try {
+ createAndCheckIsDirectory(dir, attrs);
+ return;
+ } catch (FileAlreadyExistsException x) {
+ // file exists and is not a directory
+ throw x;
+ } catch (IOException x) {
+ // parent may not exist or other reason
+ }
+
+ // find existing parent (may require absolute path)
+ SecurityException se = null;
+ try {
+ dir = dir.toAbsolutePath();
+ } catch (SecurityException x) {
+ // don't have permission to get absolute path
+ se = x;
+ }
+ Path parent = dir.getParent();
+ while (parent != null) {
+ try {
+ parent.checkAccess();
+ break;
+ } catch (NoSuchFileException x) {
+ // does not exist
+ }
+ parent = parent.getParent();
+ }
+ if (parent == null) {
+ // unable to find existing parent
+ if (se != null)
+ throw se;
+ throw new IOException("Root directory does not exist");
+ }
+
+ // create directories
+ Path child = parent;
+ for (Path name: parent.relativize(dir)) {
+ child = child.resolve(name);
+ createAndCheckIsDirectory(child, attrs);
+ }
+ }
+
+ /**
+ * Attempts to create a directory. Does nothing if the directory already
+ * exists.
+ */
+ private static void createAndCheckIsDirectory(Path dir, FileAttribute>... attrs)
+ throws IOException
+ {
+ try {
+ dir.createDirectory(attrs);
+ } catch (FileAlreadyExistsException x) {
+ boolean isDirectory = Attributes
+ .readBasicFileAttributes(dir, LinkOption.NOFOLLOW_LINKS).isDirectory();
+ if (!isDirectory)
+ throw x;
+ }
+ }
}
diff --git a/jdk/src/share/classes/java/nio/file/LinkPermission.java b/jdk/src/share/classes/java/nio/file/LinkPermission.java
index d17788fd029..01949114761 100644
--- a/jdk/src/share/classes/java/nio/file/LinkPermission.java
+++ b/jdk/src/share/classes/java/nio/file/LinkPermission.java
@@ -95,7 +95,7 @@ public final class LinkPermission extends BasicPermission {
* {@code null}
*
* @throws IllegalArgumentException
- * if name is empty or invalid
+ * if name is empty or invalid, or actions is a non-empty string
*/
public LinkPermission(String name, String actions) {
super(name);
diff --git a/jdk/src/share/classes/java/nio/file/OpenOption.java b/jdk/src/share/classes/java/nio/file/OpenOption.java
index c525307e7dc..b19bffb0c37 100644
--- a/jdk/src/share/classes/java/nio/file/OpenOption.java
+++ b/jdk/src/share/classes/java/nio/file/OpenOption.java
@@ -30,7 +30,7 @@ package java.nio.file;
*
* Objects of this type are used by methods such as {@link
* Path#newOutputStream(OpenOption[]) newOutputStream}, {@link
- * FileRef#newByteChannel newByteChannel}, {@link
+ * Path#newByteChannel newByteChannel}, {@link
* java.nio.channels.FileChannel#open FileChannel.open}, and {@link
* java.nio.channels.AsynchronousFileChannel#open AsynchronousFileChannel.open}
* when opening or creating a file.
diff --git a/jdk/src/share/classes/java/nio/file/Path.java b/jdk/src/share/classes/java/nio/file/Path.java
index 8f796b6c32e..e00c96144d9 100644
--- a/jdk/src/share/classes/java/nio/file/Path.java
+++ b/jdk/src/share/classes/java/nio/file/Path.java
@@ -26,10 +26,12 @@
package java.nio.file;
import java.nio.file.attribute.*;
-import java.nio.channels.*;
-import java.io.*;
+import java.nio.channels.SeekableByteChannel;
+import java.io.IOException;
+import java.io.OutputStream;
import java.net.URI;
-import java.util.*;
+import java.util.Iterator;
+import java.util.Set;
/**
* A file reference that locates a file using a system dependent path. The file
@@ -70,19 +72,27 @@ import java.util.*;
* this class defines the following operations:
*
* The {@link #newByteChannel newByteChannel} method
+ * may be used to open a file and obtain a byte channel for reading or
+ * writing. Files may be {@link #createFile(FileAttribute[]) created}, or
* directories may be {@link #createDirectory(FileAttribute[]) created}.
* The {@link #delete delete} method may be used to delete a file.
+ * The {@link #checkAccess checkAccess} method may be used to check
+ * the existence or accessibility of a file. The {@link #isSameFile isSameFile} method may be used to test if
+ * two file references locate the same file. The {@link #getFileStore getFileStore} method may be used to
+ * obtain the {@link FileStore} representing the storage where a file is
+ * located. Directories can be {@link #newDirectoryStream opened} so as to
* iterate over the entries in the directory. Files can be {@link #copyTo(Path,CopyOption[]) copied} or
* {@link #moveTo(Path,CopyOption[]) moved}. Symbolic-links may be {@link #createSymbolicLink created}, or the
* target of a link may be {@link #readSymbolicLink read}. {@link #newInputStream InputStream} or {@link #newOutputStream
- * OutputStream} streams can be created to allow for interoperation with the
- * {@code java.io} package
- * where required. The {@link #toRealPath real} path of an existing file may be
* obtained. The {@code failIfNotExists} parameter determines how the method
- * behaves when the file does not exist. When {@code true}, and the file
- * does not exist, then the method fails. When {@code false} then the method
- * does not fail.
+ * 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.
*
- * As with the {@link FileRef#delete delete()} method, an implementation
+ * 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.
+ *
+ * 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 (optional specific exception)
+ * @throws DirectoryNotEmptyException
+ * if the file is a directory and could not otherwise be deleted
+ * because the directory is not empty (optional specific
+ * exception)
+ * @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.
+ *
+ * As with the {@link #delete delete()} method, 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
@@ -436,13 +473,6 @@ public abstract class Path
* 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.
*
- * @param failIfNotExists
- * {@code true} if the method should fail when the file does not
- * exist
- *
- * @throws NoSuchFileException
- * if the value of the {@code failIfNotExists} is {@code true} and
- * the file does not exist (optional specific exception)
* @throws DirectoryNotEmptyException
* if the file is a directory and could not otherwise be deleted
* because the directory is not empty (optional specific
@@ -454,7 +484,7 @@ public abstract class Path
* installed, the {@link SecurityManager#checkDelete(String)} method
* is invoked to check delete access to the file.
*/
- public abstract void delete(boolean failIfNotExists) throws IOException;
+ public abstract void deleteIfExists() throws IOException;
/**
* Creates a symbolic link to a target (optional operation).
@@ -536,8 +566,6 @@ public abstract class Path
* or its {@link SecurityManager#checkWrite(String) checkWrite}
* method denies write access to both this path and the path of the
* existing file.
- *
- * @see BasicFileAttributes#linkCount
*/
public abstract Path createLink(Path existing) throws IOException;
@@ -608,7 +636,7 @@ public abstract class Path
*
* @return an absolute, hierarchical URI with a non-empty path component
*
- * @throws IOError
+ * @throws java.io.IOError
* if an I/O error occurs obtaining the absolute path, or where a
* file system is constructed to access the contents of a file as
* a file system, and the URI of the enclosing file system cannot be
@@ -636,8 +664,9 @@ public abstract class Path
* @throws IOError
* if an I/O error occurs
* @throws SecurityException
- * In the case of the default provider, and a security manager
- * is installed, its {@link SecurityManager#checkPropertyAccess(String)
+ * 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)
* checkPropertyAccess} method is invoked to check access to the
* system property {@code user.dir}
*/
@@ -720,7 +749,9 @@ public abstract class Path
* 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
- * copied to the target file.
+ * copied to the target file if supported by both the source and target
+ * file store. Copying of file timestamps may result in precision
+ * loss.
*
* 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. The {@link Files#withDirectory Files.withDirectory} utility
- * method is useful for cases where a task is performed on each accepted
- * entry in a directory. This method closes the directory when iteration is
- * complete (or an error occurs).
+ * directory.
*
* When an implementation supports operations on entries in the
* directory that execute in a race-free manner then the returned directory
@@ -927,8 +955,6 @@ public abstract class Path
*
* @throws java.util.regex.PatternSyntaxException
* if the pattern is invalid
- * @throws UnsupportedOperationException
- * if the pattern syntax is not known to the implementation
* @throws NotDirectoryException
* if the file could not otherwise be opened because it is not
* a directory (optional specific exception)
@@ -950,19 +976,18 @@ public abstract class Path
* 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
- * {@link DirectoryStream.Filter filter}. The {@link DirectoryStreamFilters}
- * class defines factory methods that create useful filters.
+ * {@link DirectoryStream.Filter filter}.
*
* 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. The {@link Files#withDirectory Files.withDirectory} utility
- * method is useful for cases where a task is performed on each accepted
- * entry in a directory. This method closes the directory when iteration is
- * complete (or an error occurs).
+ * directory.
*
* Where the filter terminates due to an uncaught error or runtime
- * exception then it propogated to the caller of the iterator's {@link
- * Iterator#hasNext() hasNext} or {@link Iterator#next() next} methods.
+ * 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.
*
* When an implementation supports operations on entries in the
* directory that execute in a race-free manner then the returned directory
@@ -973,14 +998,9 @@ public abstract class Path
* larger than 8K.
* In the case of the default provider, the returned seekable byte channel
- * is a {@link FileChannel}.
+ * is a {@link java.nio.channels.FileChannel}.
*
* Usage Examples:
* This method extends the options defined by the {@code FileRef}
- * interface and to the options specified by the {@link
- * #newByteChannel(Set,FileAttribute[]) newByteChannel} method
- * except that the options are specified by an array. In the case of the
- * default provider, the returned seekable byte channel is a {@link
- * FileChannel}.
+ * This method opens or creates a file in exactly the manner specified
+ * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel}
+ * method.
*
* @param options
* options specifying how the file is opened
@@ -1232,108 +1251,40 @@ public abstract class Path
* if a file of that name already exists and the {@link
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
* (optional specific exception)
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public abstract SeekableByteChannel newByteChannel(OpenOption... options)
- throws IOException;
-
- /**
- * Opens the file located by this path for reading, returning an input
- * stream to read bytes from the file. The stream will not be buffered, and
- * is not required to support the {@link InputStream#mark mark} or {@link
- * InputStream#reset reset} methods. The stream will be safe for access by
- * multiple concurrent threads. Reading commences at the beginning of the file.
- *
- * @return an input stream to read bytes from the 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 the file.
+ * 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 InputStream newInputStream() throws IOException;
+ public abstract SeekableByteChannel newByteChannel(OpenOption... options)
+ throws IOException;
/**
- * Opens or creates the file located by this path for writing, returning an
- * output stream to write bytes to the file.
+ * Opens or creates the file located by this object for writing, returning
+ * an output stream to write bytes to the file.
*
* This method opens or creates a file in exactly the manner specified
* by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel}
* method except that the {@link StandardOpenOption#READ READ} option may not
- * be present in the array of open options. If no open options are present
- * then this method creates a new file for writing or truncates an existing
- * file.
- *
- * The resulting stream will not be buffered. The stream will be safe
- * for access by multiple concurrent threads.
- *
- * Usage Example:
- * Suppose we wish to open a log file for writing so that we append to the
- * file if it already exists, or create it when it doesn't exist.
- * This method opens or creates a file in exactly the manner specified
- * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel}
- * method except that {@code options} parameter may not contain the {@link
- * StandardOpenOption#READ READ} option. If no open options are present
- * then this method creates a new file for writing or truncates an existing
- * file.
- *
- * The resulting stream will not be buffered. The stream will be safe
- * for access by multiple concurrent threads.
- *
- * @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 output stream
*
- * @throws IllegalArgumentException
- * if the set contains an invalid combination of options
- * @throws UnsupportedOperationException
- * if an unsupported open option is specified or the array contains
- * attributes that cannot be set atomically when creating the 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#checkWrite(String) checkWrite}
- * method is invoked to check write access to the file.
+ * @throws IllegalArgumentException {@inheritDoc}
+ * @throws UnsupportedOperationException {@inheritDoc}
+ * @throws IOException {@inheritDoc}
+ * @throws SecurityException {@inheritDoc}
*/
- public abstract OutputStream newOutputStream(Set extends OpenOption> options,
- FileAttribute>... attrs)
+ @Override
+ public abstract OutputStream newOutputStream(OpenOption... options)
throws IOException;
/**
@@ -1358,6 +1309,80 @@ public abstract class Path
*/
public abstract boolean isHidden() throws IOException;
+ /**
+ * Checks the existence and optionally the accessibility of the file
+ * located by this path.
+ *
+ * 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:
+ *
+ * If the {@code modes} parameter is of length zero, then the existence
+ * of the file is checked.
+ *
+ * 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 (optional specific exception)
+ * @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. (optional specific exception)
+ * @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;
+
/**
* Tests whether the file located by this path exists.
*
@@ -1414,6 +1439,30 @@ public abstract class Path
*/
public abstract boolean notExists();
+ /**
+ * Returns the {@link FileStore} representing the file store where an
+ * existing file, located by this path, is stored.
+ *
+ * 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}
+ * ("getFileStoreAttributes")
+ */
+ public abstract FileStore getFileStore() throws IOException;
+
// -- watchable --
/**
@@ -1561,6 +1610,49 @@ public abstract class Path
@Override
public abstract int compareTo(Path other);
+ /**
+ * Tests if the file referenced by this object is the same file referenced
+ * by another object.
+ *
+ * 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.
+ *
+ * If the file system and files remain static, then this method implements
+ * an equivalence relation for non-null {@code FileRefs}.
+ * This method works in exactly the manner specified by the {@link
- * Path#newDirectoryStream newDirectoryStream} method for the case that
+ * Path#newDirectoryStream() newDirectoryStream} method for the case that
* the {@code path} parameter is an {@link Path#isAbsolute absolute} path.
* When the parameter is a relative path then the directory to open is
- * relative to this open directory. The {@code followLinks} parameter
- * determines if links should be followed. If this parameter is {@code
- * false} and the file is a symbolic link then this method fails (by
- * throwing an I/O exception).
+ * relative to this open directory. The {@link
+ * LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to
+ * ensure that this method fails if the file is a symbolic link.
*
* The new directory stream, once created, is not dependent upon the
* directory stream used to create it. Closing this directory stream has no
@@ -92,10 +91,8 @@ public abstract class SecureDirectoryStream
*
* @param path
* the path to the directory to open
- * @param followLinks
- * {@code true} if the links should be followed
- * @param filter
- * the directory stream filter or {@code null}.
+ * @param options
+ * options indicating how symbolic links are handled
*
* @return a new and open {@code SecureDirectoryStream} object
*
@@ -111,9 +108,8 @@ public abstract class SecureDirectoryStream
* installed, the {@link SecurityManager#checkRead(String) checkRead}
* method is invoked to check read access to the directory.
*/
- public abstract SecureDirectoryStream newDirectoryStream(Path path,
- boolean followLinks,
- DirectoryStream.Filter super Path> filter)
+ public abstract SecureDirectoryStream Unlike the {@link FileRef#delete delete()} method, this method
+ * Unlike the {@link Path#delete delete()} method, this method
* does not first examine the file to determine if the file is a directory.
* Whether a directory is deleted by this method is system dependent and
* therefore not specified. If the file is a symbolic-link then the link is
@@ -191,12 +187,12 @@ public abstract class SecureDirectoryStream
* installed, the {@link SecurityManager#checkDelete(String) checkDelete}
* method is invoked to check delete access to the file
*/
- public abstract void deleteFile(Path path) throws IOException;
+ public abstract void deleteFile(T path) throws IOException;
/**
* Deletes a directory.
*
- * Unlike the {@link FileRef#delete delete()} method, this method
+ * Unlike the {@link Path#delete delete()} method, this method
* does not first examine the file to determine if the file is a directory.
* Whether non-directories are deleted by this method is system dependent and
* therefore not specified. When the parameter is a relative path then the
@@ -219,7 +215,7 @@ public abstract class SecureDirectoryStream
* installed, the {@link SecurityManager#checkDelete(String) checkDelete}
* method is invoked to check delete access to the directory
*/
- public abstract void deleteDirectory(Path path) throws IOException;
+ public abstract void deleteDirectory(T path) throws IOException;
/**
* Move a file from this directory to another directory.
@@ -259,7 +255,7 @@ public abstract class SecureDirectoryStream
* method is invoked to check write access to both the source and
* target file.
*/
- public abstract void move(Path srcpath, SecureDirectoryStream targetdir, Path targetpath)
+ public abstract void move(T srcpath, SecureDirectoryStream Note that this method does not wait if there are no events pending.
*
- * @return the list of the events retrieved
+ * @return the list of the events retrieved; may be empty
*/
public abstract List If this watch key has already been cancelled then invoking this
diff --git a/jdk/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java
index c3d28c914a7..4127a78e942 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java
@@ -110,13 +110,13 @@ import java.io.IOException;
*
*
*
- * The {@link #getAttribute getAttribute} or {@link #readAttributes
- * readAttributes} methods may be used to read the ACL or owner attributes as if
- * by invoking the {@link #getAcl getAcl} or {@link #getOwner getOwner} methods.
+ * The {@link FileRef#getAttribute getAttribute} method may be used to read
+ * the ACL or owner attributes as if by invoking the {@link #getAcl getAcl} or
+ * {@link #getOwner getOwner} methods.
*
- * The {@link #setAttribute setAttribute} method may be used to update the
- * ACL or owner attributes as if by invoking the {@link #setAcl setAcl} or {@link
- * #setOwner setOwner} methods.
+ * The {@link FileRef#setAttribute setAttribute} method may be used to
+ * update the ACL or owner attributes as if by invoking the {@link #setAcl setAcl}
+ * or {@link #setOwner setOwner} methods.
*
* The {@code first} and {@code rest} parameters are the names of the
- * attributes to read. If any of the parameters has the value {@code "*"}
- * then all attributes are read. Attributes that are not supported are
- * ignored and will not be present in the returned map. It is implementation
- * specific if all attributes are read as an atomic operation with respect
- * to other file system operations.
- *
- * @param first
- * the name of an attribute to read (case sensitive)
- * @param rest
- * the names of other attributes to read (case sensitive)
- *
- * @return an unmodifiable map of the attributes; may be empty. Its keys are
- * the attribute names, its values are the attribute values
- *
- * @throws IOException
- * if an I/O error occurs
- * @throws SecurityException
- * if a security manager is set and it denies access
- */
- Map The {@code attribute} parameter identifies the attribute to be set
- * and takes the form:
- * view-name is the {@link FileAttributeView#name name} of a {@link
- * FileAttributeView} that identifies a set of file attributes. If not
- * specified then it defaults to {@code "basic"}, the name of the file
- * attribute view that identifies the basic set of file attributes common to
- * many file systems. attribute-name is the name of the attribute
- * within the set.
- *
- * Usage Example:
- * Suppose we want to set the DOS "hidden" attribute:
- * The {@code attribute} parameter identifies the attribute to be read
- * and takes the form:
- * view-name is the {@link FileAttributeView#name name} of a {@link
- * FileAttributeView} that identifies a set of file attributes. If not
- * specified then it defaults to {@code "basic"}, the name of the file
- * attribute view that identifies the basic set of file attributes common to
- * many file systems. attribute-name is the name of the attribute.
- *
- * The {@code options} array may be used to indicate how symbolic links
- * are handled for the case that the file is a symbolic link. By default,
- * symbolic links are followed and the file attribute of the final target
- * of the link is read. If the option {@link LinkOption#NOFOLLOW_LINKS
- * NOFOLLOW_LINKS} is present then symbolic links are not followed and so
- * the method returns the file attribute of the symbolic link.
- *
- * Usage Example:
- * Suppose we require the user ID of the file owner on a system that
- * supports a "{@code unix}" view:
- * The {@code attributes} parameter identifies the attributes to be read
- * and takes the form:
- * view-name is the {@link FileAttributeView#name name} of a {@link
- * FileAttributeView} that identifies a set of file attributes. If not
- * specified then it defaults to {@code "basic"}, the name of the file
- * attribute view that identifies the basic set of file attributes common to
- * many file systems.
- *
- * The attribute-list component is a comma separated list of
- * zero or more names of attributes to read. If the list contains the value
- * {@code "*"} then all attributes are read. Attributes that are not supported
- * are ignored and will not be present in the returned map. It is
- * implementation specific if all attributes are read as an atomic operation
- * with respect to other file system operations.
- *
- * The following examples demonstrate possible values for the {@code
- * attributes} parameter:
- *
- * The {@code options} array may be used to indicate how symbolic links
- * are handled for the case that the file is a symbolic link. By default,
- * symbolic links are followed and the file attributes of the final target
- * of the link are read. If the option {@link LinkOption#NOFOLLOW_LINKS
- * NOFOLLOW_LINKS} is present then symbolic links are not followed and so
- * the method returns the file attributes of the symbolic link.
- *
- * @param file
- * A file reference that locates the file
- * @param attributes
- * The attributes to read
- * @param options
- * Options indicating how symbolic links are handled
- *
- * @return A map of the attributes returned; may be empty. The map's keys
- * are the attribute names, its values are the attribute values
- *
- * @throws IOException
- * If an I/O error occurs
- * @throws SecurityException
- * In the case of the default provider, and a security manager is
- * installed, its {@link SecurityManager#checkRead(String) checkRead}
- * method denies read access to the file. If this method is invoked
- * to read security sensitive attributes then the security manager
- * may be invoke to check for additional permissions.
- */
- public static Map The time value is measured since the epoch
- * (00:00:00 GMT, January 1, 1970) and is converted to the precision supported
- * by the file system. Converting from finer to coarser granularities result
- * in precision loss.
+ * If the file system does not support a last modified time attribute
+ * then this method has no effect.
*
- * If the file system does not support a last modified time attribute then
- * this method has no effect.
+ * Usage Example:
+ * Suppose we want to set the last modified time to the current time:
+ * The time value is measured since the epoch
- * (00:00:00 GMT, January 1, 1970) and is converted to the precision supported
- * by the file system. Converting from finer to coarser granularities result
- * in precision loss.
+ * Updates a file's last access time attribute. The file time is converted
+ * to the epoch and precision supported by the file system. Converting from
+ * finer to coarser granularities result in precision loss. The behavior of
+ * this method when attempting to set a timestamp to a value that is outside
+ * the range supported by the underlying file store is not defined. It may
+ * or not fail by throwing an {@code IOException}.
*
* If the file system does not support a last access time attribute then
* this method has no effect.
*
+ * @param file
+ * A file reference that locates the file
* @param lastAccessTime
- * The new last access time, or {@code -1L} to update it to
- * the current time
- * @param unit
- * A {@code TimeUnit} determining how to interpret the
- * {@code lastModifiedTime} parameter
+ * The new last access time
*
- * @throws IllegalArgumentException
- * If the {@code lastAccessTime} parameter is a negative value other
- * than {@code -1L}
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -623,12 +379,13 @@ public final class Attributes {
* @see BasicFileAttributeView#setTimes
*/
public static void setLastAccessTime(FileRef file,
- long lastAccessTime,
- TimeUnit unit)
+ FileTime lastAccessTime)
throws IOException
{
+ if (lastAccessTime == null)
+ throw new NullPointerException("'lastAccessTime' is null");
file.getFileAttributeView(BasicFileAttributeView.class)
- .setTimes(null, lastAccessTime, null, unit);
+ .setTimes(null, lastAccessTime, null);
}
/**
diff --git a/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java
index 70100834d8f..45a3b20eb17 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java
@@ -25,7 +25,6 @@
package java.nio.file.attribute;
-import java.util.concurrent.TimeUnit;
import java.io.IOException;
/**
@@ -49,19 +48,15 @@ import java.io.IOException;
* The {@link #getAttribute getAttribute} or {@link
- * #readAttributes(String,String[]) readAttributes(String,String[])} methods may
- * be used to read any of these attributes as if by invoking the {@link
+ * The {@link java.nio.file.FileRef#getAttribute getAttribute} method may be
+ * used to read any of these attributes as if by invoking the {@link
* #readAttributes() readAttributes()} method.
*
- * The {@link #setAttribute setAttribute} method may be used to update the
- * file's last modified time, last access time or create time attributes as if
- * by invoking the {@link #setTimes setTimes} method. In that case, the time
- * value is interpreted in {@link TimeUnit#MILLISECONDS milliseconds} and
- * converted to the precision supported by the file system.
+ * The {@link java.nio.file.FileRef#setAttribute setAttribute} method may be
+ * used to update the file's last modified time, last access time or create time
+ * attributes as if by invoking the {@link #setTimes setTimes} method.
*
* @since 1.7
* @see Attributes
@@ -141,11 +129,11 @@ public interface BasicFileAttributeView
* and create time attributes.
*
* This method updates the file's timestamp attributes. The values are
- * measured since the epoch (00:00:00 GMT, January 1, 1970) and converted to
- * the precision supported by the file system. Converting from finer to
- * coarser granularities result in precision loss. If a value is larger
- * than the maximum supported by the file system then the corresponding
- * timestamp is set to its maximum value.
+ * converted to the epoch and precision supported by the file system.
+ * Converting from finer to coarser granularities result in precision loss.
+ * The behavior of this method when attempting to set a timestamp to a value
+ * that is outside the range supported by the underlying file store is not
+ * defined. It may or not fail by throwing an {@code IOException}.
*
* If any of the {@code lastModifiedTime}, {@code lastAccessTime},
* or {@code createTime} parameters has the value {@code null} then the
@@ -153,25 +141,19 @@ public interface BasicFileAttributeView
* read the existing values of the file attributes when only some, but not
* all, of the timestamp attributes are updated. Consequently, this method
* may not be an atomic operation with respect to other file system
- * operations. If all of the {@code lastModifiedTime}, {@code
+ * operations. Reading and re-writing existing values may also result in
+ * precision loss. If all of the {@code lastModifiedTime}, {@code
* lastAccessTime} and {@code createTime} parameters are {@code null} then
* this method has no effect.
*
* @param lastModifiedTime
- * the new last modified time, or {@code -1L} to update it to
- * the current time, or {@code null} to not change the attribute
+ * the new last modified time, or {@code null} to not change the
+ * value
* @param lastAccessTime
- * the last access time, or {@code -1L} to update it to
- * the current time, or {@code null} to not change the attribute.
+ * the last access time, or {@code null} to not change the value
* @param createTime
- * the file's create time, or {@code -1L} to update it to
- * the current time, or {@code null} to not change the attribute
- * @param unit
- * a {@code TimeUnit} determining how to interpret the time values
+ * the file's create time, or {@code null} to not change the value
*
- * @throws IllegalArgumentException
- * if any of the parameters is a negative value other than {@code
- * -1L}
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
@@ -179,8 +161,7 @@ public interface BasicFileAttributeView
* installed, its {@link SecurityManager#checkWrite(String) checkWrite}
* method is invoked to check write access to the file
*/
- void setTimes(Long lastModifiedTime,
- Long lastAccessTime,
- Long createTime,
- TimeUnit unit) throws IOException;
+ void setTimes(FileTime lastModifiedTime,
+ FileTime lastAccessTime,
+ FileTime createTime) throws IOException;
}
diff --git a/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java b/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java
index 64c163bc5a1..6fb3bbf7ee9 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java
@@ -25,8 +25,6 @@
package java.nio.file.attribute;
-import java.util.concurrent.TimeUnit;
-
/**
* Basic attributes associated with a file in a file system.
*
@@ -50,47 +48,27 @@ public interface BasicFileAttributes {
/**
* Returns the time of last modification.
*
- * The {@link #resolution() resolution} method returns the {@link TimeUnit}
- * to interpret the return value of this method.
- *
- * @return a The {@link #resolution() resolution} method returns the {@link TimeUnit}
- * to interpret the return value of this method.
- *
- * @return a The {@link #resolution() resolution} method returns the {@link TimeUnit}
- * to interpret the return value of this method.
- *
- * @return a On file systems where the same file may be in several directories then
- * the link count is the number of directory entries for the file. The return
- * value is {@code 1} on file systems that only allow a file to have a
- * single name in a single directory.
- *
- * @see java.nio.file.Path#createLink
- */
- int linkCount();
-
/**
* Returns an object that uniquely identifies the given file, or {@code
* null} if a file key is not available. On some platforms or file systems
@@ -154,7 +120,7 @@ public interface BasicFileAttributes {
*
* File keys returned by this method can be compared for equality and are
* suitable for use in collections. If the file system and files remain static,
- * and two files are the {@link java.nio.file.FileRef#isSameFile same} with
+ * and two files are the {@link java.nio.file.Path#isSameFile same} with
* non-{@code null} file keys, then their file keys are equal.
*
* @see java.nio.file.Files#walkFileTree
diff --git a/jdk/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java
index c57683999b6..372a4a78060 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java
@@ -65,17 +65,17 @@ import java.io.IOException;
*
*
*
- * The {@link #getAttribute getAttribute} or {@link #readAttributes(String,String[])
- * readAttributes(String,String[])} methods may be used to read any of these
- * attributes, or any of the attributes defined by {@link BasicFileAttributeView}
- * as if by invoking the {@link #readAttributes readAttributes()} method.
+ * The {@link java.nio.file.FileRef#getAttribute getAttribute} method may
+ * be used to read any of these attributes, or any of the attributes defined by
+ * {@link BasicFileAttributeView} as if by invoking the {@link #readAttributes
+ * readAttributes()} method.
*
- * The {@link #setAttribute setAttribute} method may be used to update the
- * file's last modified time, last access time or create time attributes as
- * defined by {@link BasicFileAttributeView}. It may also be used to update
- * the DOS attributes as if by invoking the {@link #setReadOnly setReadOnly},
- * {@link #setHidden setHidden}, {@link #setSystem setSystem}, and {@link
- * #setArchive setArchive} methods respectively.
+ * The {@link java.nio.file.FileRef#setAttribute setAttribute} method may
+ * be used to update the file's last modified time, last access time or create
+ * time attributes as defined by {@link BasicFileAttributeView}. It may also be
+ * used to update the DOS attributes as if by invoking the {@link #setReadOnly
+ * setReadOnly}, {@link #setHidden setHidden}, {@link #setSystem setSystem}, and
+ * {@link #setArchive setArchive} methods respectively.
*
* @since 1.7
*/
diff --git a/jdk/src/share/classes/java/nio/file/attribute/FileAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/FileAttributeView.java
index 78a67b4a4cd..a96f09a387a 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/FileAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/FileAttributeView.java
@@ -34,7 +34,6 @@ package java.nio.file.attribute;
* @since 1.7
*
* @see java.nio.file.FileRef#getFileAttributeView(Class,java.nio.file.LinkOption[])
- * @see java.nio.file.FileRef#getFileAttributeView(String,java.nio.file.LinkOption[])
*/
public interface FileAttributeView
diff --git a/jdk/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java
index 0afc19efbff..f13429be634 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java
@@ -37,11 +37,11 @@ import java.io.IOException;
* The {@link #getOwner getOwner} or {@link #setOwner setOwner} methods may
* be used to read or update the owner of the file.
*
- * Where dynamic access to file attributes is required, the owner attribute
- * is identified by the name {@code "owner"}, and the value of the attribute is
- * a {@link UserPrincipal}. The {@link #readAttributes readAttributes}, {@link
- * #getAttribute getAttribute} and {@link #setAttribute setAttributes} methods
- * may be used to read or update the file owner.
+ * The {@link java.nio.file.FileRef#getAttribute getAttribute} and
+ * {@link java.nio.file.FileRef#setAttribute setAttribute} methods may also be
+ * used to read or update the owner. In that case, the owner attribute is
+ * identified by the name {@code "owner"}, and the value of the attribute is
+ * a {@link UserPrincipal}.
*
* @since 1.7
*/
diff --git a/jdk/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java
index 22d38617cb0..4e9098ab6fb 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java
@@ -52,10 +52,8 @@ import java.io.IOException;
*
*
*
- * The {@link #getAttribute getAttribute} or {@link #readAttributes
- * readAttributes(String,String[])} methods may be used to read any of these
- * attributes as if by invoking the {@link #readAttributes readAttributes()}
- * method.
+ * The {@link java.nio.file.FileStore#getAttribute getAttribute} method may
+ * be used to read any of these attributes.
*
* @since 1.7
*/
diff --git a/jdk/src/share/classes/java/nio/file/attribute/FileTime.java b/jdk/src/share/classes/java/nio/file/attribute/FileTime.java
new file mode 100644
index 00000000000..46b0ab40cad
--- /dev/null
+++ b/jdk/src/share/classes/java/nio/file/attribute/FileTime.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright 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.attribute;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Date;
+import java.util.Formatter;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Represents the value of a file's time stamp attribute. For example, it may
+ * represent the time that the file was last modified, accessed, or created.
+ *
+ * Instances of this class are immutable.
+ *
+ * @since 1.7
+ * @see BasicFileAttributes
+ * @see Attributes#setLastModifiedTime
+ */
+
+public final class FileTime implements Comparable Conversion from a coarser granularity that would numerically overflow
+ * saturate to {@code Long.MIN_VALUE} if negative or {@code Long.MAX_VALUE}
+ * if positive.
+ *
+ * @param unit
+ * the unit of granularity for the return value
+ *
+ * @return value in the given unit of granularity, since the epoch
+ * since the epoch (1970-01-01T00:00:00Z); can be negative
+ */
+ public long to(TimeUnit unit) {
+ return unit.convert(this.value, this.unit);
+ }
+
+ /**
+ * Returns the value in milliseconds.
+ *
+ * Conversion from a coarser granularity that would numerically overflow
+ * saturate to {@code Long.MIN_VALUE} if negative or {@code Long.MAX_VALUE}
+ * if positive.
+ *
+ * @return the value in milliseconds, since the epoch (1970-01-01T00:00:00Z)
+ */
+ public long toMillis() {
+ return unit.toMillis(value);
+ }
+
+ /**
+ * Tests this {@code FileTime} for equality with the given object.
+ *
+ * The result is {@code true} if and only if the argument is not {@code
+ * null} and is a {@code FileTime} that represents the same time. This
+ * method satisfies the general contract of the {@code Object.equals} method.
+ *
+ * @param obj
+ * the object to compare with
+ *
+ * @return {@code true} if, and only if, the given object is a {@code
+ * FileTime} that represents the same time
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj instanceof FileTime) ? compareTo((FileTime)obj) == 0 : false;
+ }
+
+ /**
+ * Computes a hash code for this file time.
+ *
+ * The hash code is based upon the value represented, and satisfies the
+ * general contract of the {@link Object#hashCode} method.
+ *
+ * @return the hash-code value
+ */
+ @Override
+ public int hashCode() {
+ // hash value for fixed granularity to satisfy contract with equals
+ long ms = toMillis();
+ return (int)(ms ^ (ms >>> 32));
+ }
+
+ /**
+ * Compares the value of two {@code FileTime} objects for order.
+ *
+ * @param other
+ * the other {@code FileTime} to be compared
+ *
+ * @return {@code 0} if this {@code FileTime} is equal to {@code other}, a
+ * value less than 0 if this {@code FileTime} represents a time
+ * that is before {@code other}, and a value greater than 0 if this
+ * {@code FileTime} represents a time that is after {@code other}
+ */
+ @Override
+ public int compareTo(FileTime other) {
+ // same granularity
+ if (unit == other.unit)
+ return (value < other.value) ? -1 : (value == other.value ? 0 : 1);
+
+ // compare in days
+ long thisValueInDays = unit.toDays(value);
+ long otherValueInDays = other.unit.toDays(other.value);
+ if (thisValueInDays != otherValueInDays)
+ return (thisValueInDays < otherValueInDays) ? -1 : 1;
+
+ // compare remainder in nanoseconds
+ long thisRemainder = remainderInNanos(thisValueInDays);
+ long otherRemainder = other.remainderInNanos(otherValueInDays);
+ return (thisRemainder < otherRemainder) ? -1 :
+ (thisRemainder == otherRemainder) ? 0 : 1;
+ }
+
+ private long remainderInNanos(long days) {
+ // constants for conversion
+ final long C0 = 1L;
+ final long C1 = C0 * 24L;
+ final long C2 = C1 * 60L;
+ final long C3 = C2 * 60L;
+ final long C4 = C3 * 1000L;
+ final long C5 = C4 * 1000L;
+ final long C6 = C5 * 1000L;
+
+ long scale;
+ switch (unit) {
+ case DAYS : scale = C0; break;
+ case HOURS : scale = C1; break;
+ case MINUTES : scale = C2; break;
+ case SECONDS : scale = C3; break;
+ case MILLISECONDS : scale = C4; break;
+ case MICROSECONDS : scale = C5; break;
+ case NANOSECONDS : scale = C6; break;
+ default:
+ throw new AssertionError("Unit not handled");
+ }
+ long rem = value - (days * scale);
+ return unit.toNanos(rem);
+ }
+
+ /**
+ * Returns the string representation of this {@code FileTime}. The string
+ * is returned in the ISO 8601 format:
+ * A {@code FileTime} is primarly intended to represent the value of a
+ * file's time stamp. Where used to represent extreme values, where
+ * the year is less than "{@code 0001}" or greater than "{@code 9999}" then
+ * the year may be expanded to more than four digits and may be
+ * negative-signed. If more than four digits then leading zeros are not
+ * present. The year before "{@code 0001}" is "{@code -0001}".
+ *
+ * @return the string representation of this file time
+ */
+ @Override
+ public String toString() {
+ String v = valueAsString;
+ if (v == null) {
+ // overflow saturates to Long.MIN_VALUE or Long.MAX_VALUE so this
+ // limits the range:
+ // [-292275056-05-16T16:47:04.192Z,292278994-08-17T07:12:55.807Z]
+ long ms = toMillis();
+
+ // nothing to do when seconds/minutes/hours/days
+ String fractionAsString = "";
+ if (unit.compareTo(TimeUnit.SECONDS) < 0) {
+ // constants for conversion
+ final long C0 = 1L;
+ final long C1 = C0 * 1000L;
+ final long C2 = C1 * 1000L;
+ final long C3 = C2 * 1000L;
+
+ long scale;
+ int width;
+ switch (unit) {
+ case MILLISECONDS : scale = C1; width = 3; break;
+ case MICROSECONDS : scale = C2; width = 6; break;
+ case NANOSECONDS : scale = C3; width = 9; break;
+ default:
+ throw new AssertionError("Unit not handled");
+ }
+ long fraction = value % scale;
+ if (fraction != 0L) {
+ // fraction must be positive
+ if (fraction < 0L) {
+ fraction += scale;
+ if (ms != Long.MIN_VALUE) ms--;
+ }
+
+ // convert to String, adding leading zeros as required and
+ // stripping any trailing zeros
+ String s = Long.toString(fraction);
+ int len = s.length();
+ width -= len;
+ StringBuilder sb = new StringBuilder(".");
+ while (width-- > 0) {
+ sb.append('0');
+ }
+ if (s.charAt(len-1) == '0') {
+ // drop trailing zeros
+ len--;
+ while (s.charAt(len-1) == '0')
+ len--;
+ sb.append(s.substring(0, len));
+ } else {
+ sb.append(s);
+ }
+ fractionAsString = sb.toString();
+ }
+ }
+
+ // create calendar to use with formatter.
+ GregorianCalendar cal =
+ new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ROOT);
+ if (value < 0L)
+ cal.setGregorianChange(new Date(Long.MIN_VALUE));
+ cal.setTimeInMillis(ms);
+
+ // years are negative before common era
+ String sign = (cal.get(Calendar.ERA) == GregorianCalendar.BC) ? "-" : "";
+
+ // [-]YYYY-MM-DDThh:mm:ss[.s]Z
+ v = new Formatter(Locale.ROOT)
+ .format("%s%tFT%tR:%tS%sZ", sign, cal, cal, cal, fractionAsString)
+ .toString();
+ valueAsString = v;
+ }
+ return v;
+ }
+}
diff --git a/jdk/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java
index 285b8bb7d1c..aeec36a941a 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java
@@ -90,14 +90,13 @@ import java.io.IOException;
*
*
*
- * The {@link #getAttribute getAttribute} or {@link
- * #readAttributes(String,String[]) readAttributes(String,String[])} methods may
- * be used to read any of these attributes, or any of the attributes defined by
- * {@link BasicFileAttributeView} as if by invoking the {@link #readAttributes
+ * The {@link FileRef#getAttribute getAttribute} method may be used to read
+ * any of these attributes, or any of the attributes defined by {@link
+ * BasicFileAttributeView} as if by invoking the {@link #readAttributes
* readAttributes()} method.
*
- * The {@link #setAttribute setAttribute} method may be used to update the
- * file's last modified time, last access time or create time attributes as
+ * The {@link FileRef#setAttribute setAttribute} method may be used to update
+ * the file's last modified time, last access time or create time attributes as
* defined by {@link BasicFileAttributeView}. It may also be used to update
* the permissions, owner, or group-owner as if by invoking the {@link
* #setPermissions setPermissions}, {@link #setOwner setOwner}, and {@link
diff --git a/jdk/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java b/jdk/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java
index 97d322c6a59..72570f1243d 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java
@@ -35,7 +35,7 @@ import java.util.*;
* @since 1.7
*/
-public class PosixFilePermissions {
+public final class PosixFilePermissions {
private PosixFilePermissions() { }
// Write string representation of permission bits to {@code sb}.
@@ -58,7 +58,9 @@ public class PosixFilePermissions {
}
/**
- * Returns the {@code String} representation of a set of permissions.
+ * Returns the {@code String} representation of a set of permissions. It
+ * is guaranteed that the returned {@code String} can be parsed by the
+ * {@link #fromString} method.
*
* If the set contains {@code null} or elements that are not of type
* {@code PosixFilePermission} then these elements are ignored.
@@ -67,8 +69,6 @@ public class PosixFilePermissions {
* the set of permissions
*
* @return the string representation of the permission set
- *
- * @see #fromString
*/
public static String toString(Set Where dynamic access to file attributes is required, the {@link
- * #getAttribute getAttribute} or {@link #readAttributes(String,String[])
- * readAttributes(String,String[])} methods may be used to read the attribute
- * value. The attribute value is returned as a byte array (byte[]). The {@link
- * #setAttribute setAttribute} method may be used to write the value of a
- * user-defined attribute from a buffer (as if by invoking the {@link #write
- * write} method), or byte array (byte[]).
+ * java.nio.file.FileRef#getAttribute getAttribute} method may be used to read
+ * the attribute value. The attribute value is returned as a byte array (byte[]).
+ * The {@link java.nio.file.FileRef#setAttribute setAttribute} method may be used
+ * to write the value of a user-defined attribute from a buffer (as if by
+ * invoking the {@link #write write} method), or byte array (byte[]).
*
* @since 1.7
*/
@@ -74,7 +73,7 @@ public interface UserDefinedFileAttributeView
{
/**
* Returns the name of this attribute view. Attribute views of this type
- * have the name {@code "xattr"}.
+ * have the name {@code "user"}.
*/
@Override
String name();
diff --git a/jdk/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java b/jdk/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java
index ba74882ce67..79b6a5307ac 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java
@@ -89,7 +89,7 @@ public abstract class UserPrincipalLookupService {
* @param group
* the string representation of the group to lookup
*
- * @return a user principal
+ * @return a group principal
*
* @throws UserPrincipalNotFoundException
* the principal does not exist or is not a group
diff --git a/jdk/src/share/classes/java/nio/file/spi/AbstractPath.java b/jdk/src/share/classes/java/nio/file/spi/AbstractPath.java
deleted file mode 100644
index 133411e3bf8..00000000000
--- a/jdk/src/share/classes/java/nio/file/spi/AbstractPath.java
+++ /dev/null
@@ -1,568 +0,0 @@
-/*
- * 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.spi;
-
-import java.nio.file.*;
-import static java.nio.file.StandardOpenOption.*;
-import java.nio.file.attribute.*;
-import java.nio.channels.*;
-import java.nio.ByteBuffer;
-import java.io.*;
-import java.util.*;
-
-/**
- * Base implementation class for a {@code Path}.
- *
- * This class is intended to be extended by provider implementors. It
- * implements, or provides default implementations for several of the methods
- * defined by the {@code Path} class. It implements the {@link #copyTo copyTo}
- * and {@link #moveTo moveTo} methods for the case that the source and target
- * are not associated with the same provider.
- *
- * @since 1.7
- */
-
-public abstract class AbstractPath extends Path {
-
- /**
- * Initializes a new instance of this class.
- */
- protected AbstractPath() { }
-
- /**
- * Deletes the file referenced by this object.
- *
- * This method invokes the {@link #delete(boolean) delete(boolean)}
- * method with a parameter of {@code true}. It may be overridden where
- * required.
- *
- * @throws NoSuchFileException {@inheritDoc}
- * @throws DirectoryNotEmptyException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public void delete() throws IOException {
- delete(true);
- }
-
- /**
- * Creates a new and empty file, failing if the file already exists.
- *
- * This method invokes the {@link #newByteChannel(Set,FileAttribute[])
- * newByteChannel(Set,FileAttribute...)} method to create the file. It may be
- * overridden where required.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws FileAlreadyExistsException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public Path createFile(FileAttribute>... attrs)
- throws IOException
- {
- EnumSet This method invokes the {@link #newByteChannel(Set,FileAttribute[])
- * newByteChannel(Set,FileAttribute...)} method to open or create the file.
- * It may be overridden where required.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws FileAlreadyExistsException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public SeekableByteChannel newByteChannel(OpenOption... options)
- throws IOException
- {
- Set This method returns an {@code InputStream} that is constructed by
- * invoking the {@link java.nio.channels.Channels#newInputStream
- * Channels.newInputStream} method. It may be overridden where a more
- * efficient implementation is available.
- *
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public InputStream newInputStream() throws IOException {
- return Channels.newInputStream(newByteChannel());
- }
-
- // opts must be modifiable
- private OutputStream implNewOutputStream(Set This method returns an {@code OutputStream} that is constructed by
- * invoking the {@link java.nio.channels.Channels#newOutputStream
- * Channels.newOutputStream} method. It may be overridden where a more
- * efficient implementation is available.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public OutputStream newOutputStream(OpenOption... options) throws IOException {
- int len = options.length;
- Set This method returns an {@code OutputStream} that is constructed by
- * invoking the {@link java.nio.channels.Channels#newOutputStream
- * Channels.newOutputStream} method. It may be overridden where a more
- * efficient implementation is available.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public OutputStream newOutputStream(Set extends OpenOption> options,
- FileAttribute>... attrs)
- throws IOException
- {
- Set This method invokes the {@link
- * #newDirectoryStream(java.nio.file.DirectoryStream.Filter)
- * newDirectoryStream(Filter)} method with a filter that accept all entries.
- * It may be overridden where required.
- *
- * @throws NotDirectoryException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public DirectoryStream This method constructs a {@link PathMatcher} by invoking the
- * file system's {@link java.nio.file.FileSystem#getPathMatcher
- * getPathMatcher} method. This method may be overridden where a more
- * efficient implementation is available.
- *
- * @throws java.util.regex.PatternSyntaxException {@inheritDoc}
- * @throws UnsupportedOperationException {@inheritDoc}
- * @throws NotDirectoryException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public DirectoryStream This method invokes the {@link #checkAccess checkAccess} method to
- * check if the file exists. It may be overridden where a more efficient
- * implementation is available.
- */
- @Override
- public boolean exists() {
- try {
- checkAccess();
- return true;
- } catch (IOException x) {
- // unable to determine if file exists
- }
- return false;
- }
-
- /**
- * Tests whether the file located by this path does not exist.
- *
- * This method invokes the {@link #checkAccess checkAccess} method to
- * check if the file exists. It may be overridden where a more efficient
- * implementation is available.
- */
- @Override
- public boolean notExists() {
- try {
- checkAccess();
- return false;
- } catch (NoSuchFileException x) {
- // file confirmed not to exist
- return true;
- } catch (IOException x) {
- return false;
- }
- }
-
- /**
- * Registers the file located by this path with a watch service.
- *
- * This method invokes the {@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[])
- * register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier...)}
- * method to register the file. It may be overridden where required.
- */
- @Override
- public WatchKey register(WatchService watcher, WatchEvent.Kind>... events)
- throws IOException
- {
- return register(watcher, events, NO_MODIFIERS);
- }
- private static final WatchEvent.Modifier[] NO_MODIFIERS = new WatchEvent.Modifier[0];
-
- /**
- * Copy the file located by this path to a target location.
- *
- * This method is invoked by the {@link #copyTo copyTo} method for
- * the case that this {@code Path} and the target {@code Path} are
- * associated with the same provider.
- *
- * @param target
- * The target location
- * @param options
- * Options specifying how the copy should be done
- *
- * @throws IllegalArgumentException
- * If an invalid option is specified
- * @throws FileAlreadyExistsException
- * The target file exists and cannot be replaced because the
- * {@code REPLACE_EXISTING} option is not specified, or the target
- * file is a non-empty directory (optional specific exception)
- * @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 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")}.
- */
- protected abstract void implCopyTo(Path target, CopyOption... options)
- throws IOException;
-
- /**
- * Move the file located by this path to a target location.
- *
- * This method is invoked by the {@link #moveTo moveTo} method for
- * the case that this {@code Path} and the target {@code Path} are
- * associated with the same provider.
- *
- * @param target
- * The target location
- * @param options
- * Options specifying how the move should be done
- *
- * @throws IllegalArgumentException
- * If an invalid option is specified
- * @throws FileAlreadyExistsException
- * The target file exists and cannot be replaced because the
- * {@code REPLACE_EXISTING} option is not specified, or the target
- * file is a non-empty directory
- * @throws AtomicMoveNotSupportedException
- * The options array contains the {@code ATOMIC_MOVE} option but
- * the file cannot be moved as an atomic file system operation.
- * @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#checkWrite(String) checkWrite}
- * method is invoked to check write access to both the source and
- * target file.
- */
- protected abstract void implMoveTo(Path target, CopyOption... options)
- throws IOException;
-
- /**
- * Copy the file located by this path to a target location.
- *
- * If this path is associated with the same {@link FileSystemProvider
- * provider} as the {@code target} then the {@link #implCopyTo implCopyTo}
- * method is invoked to copy the file. Otherwise, this method attempts to
- * copy the file to the target location in a manner that may be less
- * efficient than would be the case that target is associated with the same
- * provider as this path.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws FileAlreadyExistsException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public final Path copyTo(Path target, CopyOption... options)
- throws IOException
- {
- if ((getFileSystem().provider() == target.getFileSystem().provider())) {
- implCopyTo(target, options);
- } else {
- xProviderCopyTo(target, options);
- }
- return target;
- }
-
- /**
- * Move or rename the file located by this path to a target location.
- *
- * If this path is associated with the same {@link FileSystemProvider
- * provider} as the {@code target} then the {@link #implCopyTo implMoveTo}
- * method is invoked to move the file. Otherwise, this method attempts to
- * copy the file to the target location and delete the source file. This
- * implementation may be less efficient than would be the case that
- * target is associated with the same provider as this path.
- *
- * @throws IllegalArgumentException {@inheritDoc}
- * @throws FileAlreadyExistsException {@inheritDoc}
- * @throws IOException {@inheritDoc}
- * @throws SecurityException {@inheritDoc}
- */
- @Override
- public final Path moveTo(Path target, CopyOption... options)
- throws IOException
- {
- if ((getFileSystem().provider() == target.getFileSystem().provider())) {
- implMoveTo(target, options);
- } else {
- // different providers so copy + delete
- xProviderCopyTo(target, convertMoveToCopyOptions(options));
- delete(false);
- }
- return target;
- }
-
- /**
- * Converts the given array of options for moving a file to options suitable
- * for copying the file when a move is implemented as copy + delete.
- */
- private static CopyOption[] convertMoveToCopyOptions(CopyOption... options)
- throws AtomicMoveNotSupportedException
- {
- int len = options.length;
- CopyOption[] newOptions = new CopyOption[len+2];
- for (int i=0; i The exact form of the URI is file system provider dependent. In the
* case of the default provider, the URI scheme is {@code "file"} and the
@@ -290,7 +292,8 @@ public abstract class FileSystemProvider {
* If the URI scheme does not identify this provider or other
* preconditions on the uri parameter do not hold
* @throws FileSystemNotFoundException
- * The file system, identified by the URI, does not exist
+ * The file system, identified by the URI, does not exist and
+ * cannot be created automatically
* @throws SecurityException
* If a security manager is installed and it denies an unspecified
* permission.
diff --git a/jdk/src/share/classes/java/util/Scanner.java b/jdk/src/share/classes/java/util/Scanner.java
index 3e3806d1ff4..c1032337bd2 100644
--- a/jdk/src/share/classes/java/util/Scanner.java
+++ b/jdk/src/share/classes/java/util/Scanner.java
@@ -690,7 +690,7 @@ public final class Scanner implements Iterator Usage Example:
- * Suppose we require to perform a task on all class files in a directory:
- * true
, sets the access permission to allow execute
@@ -1748,16 +1751,17 @@ public class File
return fs.getSpace(this, FileSystem.SPACE_USABLE);
}
-
/* -- Temporary files -- */
- private static class TemporaryDirectory {
- private TemporaryDirectory() { }
+ static class TempDirectory {
+ private TempDirectory() { }
- static final String valueAsString = fs.normalize(
- AccessController.doPrivileged(new GetPropertyAction("java.io.tmpdir")));
- static final File valueAsFile =
- new File(valueAsString, fs.prefixLength(valueAsString));
+ // temporary directory location
+ private static final File tmpdir = new File(fs.normalize(AccessController
+ .doPrivileged(new GetPropertyAction("java.io.tmpdir"))));
+ static File location() {
+ return tmpdir;
+ }
// file name generation
private static final SecureRandom random = new SecureRandom();
@@ -1770,25 +1774,6 @@ public class File
}
return new File(dir, prefix + Long.toString(n) + suffix);
}
-
- // default file permissions
- static final FileAttribute{@link #createTempFile(java.lang.String,
* java.lang.String, java.io.File)
* createTempFile(prefix, suffix, null)}
.
*
+ * prefix
argument contains fewer than three
+ * If the {@code prefix} argument contains fewer than three
* characters
* @throws UnsupportedOperationException
* If the array contains an attribute that cannot be set atomically
@@ -1971,74 +1954,19 @@ public class File
* @throws SecurityException
* If a security manager exists and its {@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}
- * method does not allow a file to be created. When the {@code
- * deleteOnExit} parameter has the value {@code true} then the
- * security manager's {@link
- * java.lang.SecurityManager#checkDelete(java.lang.String)} is
- * invoked to check delete access to the file.
+ * method does not allow a file to be created.
+ *
* @since 1.7
*/
- public static File createTempFile(String prefix,
- String suffix,
- boolean deleteOnExit,
- FileAttribute>... attrs)
+ public static File createTemporaryFile(String prefix,
+ String suffix,
+ FileAttribute>... attrs)
throws IOException
{
if (prefix.length() < 3)
throw new IllegalArgumentException("Prefix string too short");
suffix = (suffix == null) ? ".tmp" : suffix;
-
- // special case POSIX environments so that 0600 is used as the file mode
- if (TemporaryDirectory.isPosix) {
- if (attrs.length == 0) {
- // no attributes so use default permissions
- attrs = new FileAttribute>[1];
- attrs[0] = TemporaryDirectory.defaultPosixFilePermissions;
- } else {
- // check if posix permissions given; if not use default
- boolean hasPermissions = false;
- for (int i=0; i
* Subsequent invocations of this method return the same {@code Path}.
*
*
- * {@link FileSystems#getDefault FileSystems.getDefault}().{@link FileSystem#getPath getPath}(this.{@link #getPath getPath}());
+ * {@link java.nio.file.FileSystems#getDefault FileSystems.getDefault}().{@link
+ * java.nio.file.FileSystem#getPath getPath}(this.{@link #getPath getPath}());
*
'\u0020'
) surrounding its components are
- * ignored. The {@code type} parameter is parsed into its primary and subtype
- * components which are used to match the primary and subtype components of
- * each directory entry's content type. Parameters are not allowed. The
- * primary type matches if it has value {@code '*'} or is equal to the
- * primary type of the directory entry's content type without regard to
- * case. The subtype matches if has the value {@code '*'} or is equal to the
- * subtype of the directory entry's content type without regard to case. If
- * both the primary and subtype match then the filter's {@code accept} method
- * returns {@code true}. If the content type of a directory entry cannot be
- * determined then the entry is filtered.
- *
- *
- * DirectoryStream.Filter<FileRef> filter =
- * DirectoryStreamFilters.newContentTypeFilter("text/html");
- *
- *
- * @param type
- * the content type
- *
- * @return a new directory stream filter
- *
- * @throws IllegalArgumentException
- * if the {@code type} parameter cannot be parsed as a MIME type
- * or it has parameters
- */
- public static
- * List<DirectoryStream.Filter<? super Path>> filters = ...
- * DirectoryStream.Filter<Path> filter = DirectoryStreamFilters.allOf(filters);
- *
- *
- * @param filters
- * the sequence of filters
- *
- * @return the resulting filter
- */
- public static
- *
- *
- *
- *
- *
- *
- * Option Description
- *
- * {@link StandardOpenOption#APPEND APPEND}
- * 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.
- *
- *
- * {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING}
- * 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.
- *
- *
- * {@link StandardOpenOption#SYNC SYNC}
- * Requires that every update to the file's content or metadata be
- * written synchronously to the underlying storage device. (see Synchronized I/O file
- * integrity).
- *
- *
- * {@link StandardOpenOption#DSYNC DSYNC}
- * Requires that every update to the file's content be written
- * synchronously to the underlying storage device. (see Synchronized I/O file
- * integrity).
- *
- *
- *
- *
- * Value Description
- *
- * {@link AccessMode#READ READ}
- * Checks that the file exists and that the Java virtual machine has
- * permission to read the file.
- *
- *
- * {@link AccessMode#WRITE WRITE}
- * Checks that the file exists and that the Java virtual machine has
- * permission to write to the file,
- *
- *
- * {@link AccessMode#EXECUTE EXECUTE}
- * 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.
- *
+ * [view-name:]attribute-name
+ *
+ * where square brackets [...] delineate an optional component and the
+ * character {@code ':'} stands for itself.
+ *
+ *
+ * file.setAttribute("dos:hidden", true);
+ *
+ *
+ * @param attribute
+ * the attribute to set
+ * @param value
+ * the attribute value
+ * @param options
+ * options indicating how symbolic links are handled
+ *
+ * @throws UnsupportedOperationException
+ * if the attribute view is not available or it does not support
+ * updating the attribute
+ * @throws IllegalArgumentException
+ * if the attribute value is of the correct type but has an
+ * inappropriate value
+ * @throws ClassCastException
+ * If the attribute value is not of the expected type or is a
+ * collection containing elements that are not of the expected
+ * type
+ * @throws IOException
+ * If an I/O error occurs
+ * @throws SecurityException
+ * In the case of the default provider, and a security manager is
+ * installed, its {@link SecurityManager#checkWrite(String) checkWrite}
+ * method denies write access to the file. If this method is invoked
+ * to set security sensitive attributes then the security manager
+ * may be invoked to check for additional permissions.
+ */
+ void setAttribute(String attribute, Object value, LinkOption... options)
+ throws IOException;
+
+ /**
+ * Reads the value of a file attribute.
+ *
+ *
+ * [view-name:]attribute-name
+ *
+ * where square brackets [...] delineate an optional component and the
+ * character {@code ':'} stands for itself.
+ *
+ *
+ * int uid = (Integer)file.getAttribute("unix:uid");
+ *
+ *
+ * @param attribute
+ * the attribute to read
+ * @param options
+ * options indicating how symbolic links are handled
+ * @return the attribute value or {@code null} if the attribute view
+ * is not available or it does not support reading the attribute
+ *
+ * reading the attribute
+ * @throws IOException
+ * if an I/O error occurs
+ * @throws SecurityException
+ * In the case of the default provider, and a security manager is
+ * installed, its {@link SecurityManager#checkRead(String) checkRead}
+ * method denies read access to the file. If this method is invoked
+ * to read security sensitive attributes then the security manager
+ * may be invoked to check for additional permissions.
+ */
+ Object getAttribute(String attribute, LinkOption... options) throws IOException;
+
+ /**
+ * Reads a set of file attributes as a bulk operation.
+ *
+ *
+ * [view-name:]attribute-list
+ *
+ * where square brackets [...] delineate an optional component and the
+ * character {@code ':'} stands for itself.
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * {@code "*"}
+ * Read all {@link BasicFileAttributes basic-file-attributes}.
+ *
+ *
+ * {@code "size,lastModifiedTime,lastAccessTime"}
+ * Reads the file size, last modified time, and last access time
+ * attributes.
+ *
+ *
+ * {@code "posix:*"}
+ * Read all {@link PosixFileAttributes POSIX-file-attributes}..
+ *
+ *
+ * {@code "posix:permissions,owner,size"}
+ * Reads the POSX file permissions, owner, and file size.
+ *
- *
- *
- * @param other
- * The other file reference
- *
- * @return {@code true} if, and only if, this object and the given object
- * locate the same file
+ * @return A map of the attributes returned; may be empty. The map's keys
+ * are the attribute names, its values are the attribute values
*
* @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
+ * installed, its {@link SecurityManager#checkRead(String) checkRead}
+ * method denies read access to the file. If this method is invoked
+ * to read security sensitive attributes then the security manager
+ * may be invoke to check for additional permissions.
*/
- boolean isSameFile(FileRef other) throws IOException;
-
- /**
- * Deletes the file referenced by this object.
- *
- *
+ * view-name:attribute-name
+ *
+ * where the character {@code ':'} stands for itself.
+ *
+ *
+ * boolean compression = (Boolean)fs.getAttribute("zfs:compression");
+ *
*
- * @return a file store attribute view of the given name, or {@code null}
- * if the attribute view is not available
+ * @param attribute
+ * the attribute to read
+
+ * @return the attribute value; {@code null} may be a valid valid for some
+ * attributes
+ *
+ * @throws UnsupportedOperationException
+ * if the attribute view is not available or it does not support
+ * reading the attribute
+ * @throws IOException
+ * if an I/O error occurs
*/
- public abstract FileStoreAttributeView getFileStoreAttributeView(String name);
+ public abstract Object getAttribute(String attribute) throws IOException;
}
diff --git a/jdk/src/share/classes/java/nio/file/FileTreeWalker.java b/jdk/src/share/classes/java/nio/file/FileTreeWalker.java
index 95148a5b50d..71cb86eb88a 100644
--- a/jdk/src/share/classes/java/nio/file/FileTreeWalker.java
+++ b/jdk/src/share/classes/java/nio/file/FileTreeWalker.java
@@ -50,8 +50,6 @@ class FileTreeWalker {
case FOLLOW_LINKS : fl = true; break;
case DETECT_CYCLES : dc = true; break;
default:
- if (option == null)
- throw new NullPointerException("Visit options contains 'null'");
throw new AssertionError("Should not get here");
}
}
@@ -239,13 +237,13 @@ class FileTreeWalker {
}
private static class AncestorDirectory {
- private final FileRef dir;
+ private final Path dir;
private final Object key;
- AncestorDirectory(FileRef dir, Object key) {
+ AncestorDirectory(Path dir, Object key) {
this.dir = dir;
this.key = key;
}
- FileRef file() {
+ Path file() {
return dir;
}
Object fileKey() {
diff --git a/jdk/src/share/classes/java/nio/file/FileVisitor.java b/jdk/src/share/classes/java/nio/file/FileVisitor.java
index 6d65eba27a9..26e5abbeed0 100644
--- a/jdk/src/share/classes/java/nio/file/FileVisitor.java
+++ b/jdk/src/share/classes/java/nio/file/FileVisitor.java
@@ -42,9 +42,9 @@ import java.io.IOException;
* @Override
* public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
* try {
- * file.delete(false);
+ * file.delete();
* } catch (IOException exc) {
- * // failed to delete
+ * // failed to delete, do error handling here
* }
* return FileVisitResult.CONTINUE;
* }
@@ -52,9 +52,9 @@ import java.io.IOException;
* public FileVisitResult postVisitDirectory(Path dir, IOException e) {
* if (e == null) {
* try {
- * dir.delete(false);
+ * dir.delete();
* } catch (IOException exc) {
- * // failed to delete
+ * // failed to delete, do error handling here
* }
* } else {
* // directory iteration failed
@@ -80,7 +80,8 @@ import java.io.IOException;
* } catch (FileAlreadyExistsException e) {
* // ignore
* } catch (IOException e) {
- * // copy failed, skip rest of directory and descendants
+ * // copy failed, do error handling here
+ * // skip rest of directory and descendants
* return SKIP_SUBTREE;
* }
* return CONTINUE;
@@ -90,7 +91,7 @@ import java.io.IOException;
* try {
* file.copyTo(target.resolve(source.relativize(file)));
* } catch (IOException e) {
- * // copy failed
+ * // copy failed, do error handling here
* }
* return CONTINUE;
* }
@@ -100,7 +101,7 @@ import java.io.IOException;
* @since 1.7
*/
-public interface FileVisitor
- *
- * @param dir
- * The directory
- * @param action
- * The {@code FileAction} to invoke for each entry
- *
- * @throws NotDirectoryException
- * If the {@code dir} parameter is not a directory (optional
- * specific exception)
- * @throws IOException
- * If an I/O error occurs or the {@code invoke} method terminates
- * due to an uncaught {@code IOException}
- * @throws SecurityException
- * In the case of the default provider, the {@link
- * SecurityManager#checkRead(String) checkRead} method is invoked
- * to check read access to the directory.
- */
- public static void withDirectory(Path dir, FileAction super Path> action)
- throws IOException
- {
- withDirectory(dir, "*", action);
- }
-
/**
* Walks a file tree.
*
@@ -328,7 +176,7 @@ public final class Files {
* arises when there is an entry in a directory that is an ancestor of the
* directory. Cycle detection is done by recording the {@link
* java.nio.file.attribute.BasicFileAttributes#fileKey file-key} of directories,
- * or if file keys are not available, by invoking the {@link FileRef#isSameFile
+ * or if file keys are not available, by invoking the {@link Path#isSameFile
* isSameFile} method to test if a directory is the same file as an
* ancestor. When a cycle is detected the {@link FileVisitor#visitFile
* visitFile} is invoked with the attributes of the directory. The {@link
@@ -403,4 +251,108 @@ public final class Files {
Integer.MAX_VALUE,
visitor);
}
+
+ /**
+ * Creates a directory by creating all nonexistent parent directories first.
+ *
+ *
- * withDirectory(dir, "*", action)
- *
+ *
File attributes
*
- * The {@code java.nio.file.attribute}
- * package provides access to file attributes or meta-data 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 basic meta-data are obtained, in bulk, by
- * invoking the {@link Attributes#readBasicFileAttributes
- * Attributes.readBasicFileAttributes} method:
+ * In addition to the {@link #setAttribute setAttribute} and {@link #getAttribute
+ * getAttribute} methods, the {@code
+ * java.nio.file.attribute} package provides type-safe and efficient access
+ * to file attributes or meta-data 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
+ * basic meta-data are obtained, in bulk, by invoking the {@link
+ * Attributes#readBasicFileAttributes Attributes.readBasicFileAttributes} method:
*
* Path file = ...
* BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file);
@@ -417,12 +428,38 @@ public abstract class Path
/**
* Deletes the file located by this path.
*
- *
*
* {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS}
@@ -867,10 +898,7 @@ public abstract class Path
*
*
* DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
- * public boolean accept(Path file) {
- * try {
- * long size = Attributes.readBasicFileAttributes(file).size();
- * return (size > 8192L);
- * } catch (IOException e) {
- * // failed to get size
- * return false;
- * }
+ * public boolean accept(Path file) throws IOException {
+ * long size = Attributes.readBasicFileAttributes(file).size();
+ * return (size > 8192L);
* }
* };
* Path dir = ...
@@ -1071,6 +1091,8 @@ public abstract class Path
* 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.
+ *
+ * @see Files#createDirectories
*/
public abstract Path createDirectory(FileAttribute>... attrs)
throws IOException;
@@ -1159,7 +1181,7 @@ public abstract class Path
* FileAttribute file-attributes} to set atomically when a new file is created.
*
*
@@ -1212,12 +1234,9 @@ public abstract class Path
* Opens or creates a file, returning a seekable byte channel to access the
* file.
*
- *
- * Path logfile = ...
- * OutputStream out = new BufferedOutputStream(logfile.newOutputStream(CREATE, APPEND));
- *
+ * be present in the array of open options.
*
* @param options
* options specifying how the file is opened
*
- * @return a new seekable byte channel
- *
- * @throws IllegalArgumentException
- * if {@code options} contains an invalid combination of options
- * @throws UnsupportedOperationException
- * if an unsupported open option is specified
- * @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#checkWrite(String) checkWrite}
- * method is invoked to check write access to the file.
- */
- public abstract OutputStream newOutputStream(OpenOption... options)
- throws IOException;
-
- /**
- * Opens or creates the file located by this path for writing, returning an
- * output stream to write bytes to the file.
- *
- *
+ *
+ *
+ *
+ * Value Description
+ *
+ * {@link AccessMode#READ READ}
+ * Checks that the file exists and that the Java virtual machine has
+ * permission to read the file.
+ *
+ *
+ * {@link AccessMode#WRITE WRITE}
+ * Checks that the file exists and that the Java virtual machine has
+ * permission to write to the file,
+ *
+ *
+ * {@link AccessMode#EXECUTE EXECUTE}
+ * 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.
+ *
+ *
+ *
+ * @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;
+
/**
* Tests this path for equality with the given object.
*
diff --git a/jdk/src/share/classes/java/nio/file/Paths.java b/jdk/src/share/classes/java/nio/file/Paths.java
index 2cd7a091213..8f456846f16 100644
--- a/jdk/src/share/classes/java/nio/file/Paths.java
+++ b/jdk/src/share/classes/java/nio/file/Paths.java
@@ -35,7 +35,7 @@ import java.net.URI;
* @since 1.7
*/
-public class Paths {
+public final class Paths {
private Paths() { }
/**
@@ -106,8 +106,9 @@ public class Paths {
* if preconditions on the {@code uri} parameter do not hold. The
* format of the URI is provider specific.
* @throws FileSystemNotFoundException
- * if the file system identified by the URI does not exist or the
- * provider identified by the URI's scheme component is not installed
+ * The file system, identified by the URI, does not exist and
+ * cannot be created automatically, or the provider identified by
+ * the URI's scheme component is not installed
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission to access the file system
diff --git a/jdk/src/share/classes/java/nio/file/SecureDirectoryStream.java b/jdk/src/share/classes/java/nio/file/SecureDirectoryStream.java
index 7268c41c54d..9655695d301 100644
--- a/jdk/src/share/classes/java/nio/file/SecureDirectoryStream.java
+++ b/jdk/src/share/classes/java/nio/file/SecureDirectoryStream.java
@@ -36,7 +36,7 @@ import java.io.IOException;
* traverse file trees or otherwise operate on directories in a race-free manner.
* Race conditions can arise when a sequence of file operations cannot be
* carried out in isolation. Each of the file operations defined by this
- * interface specify a relative {@link Path}. All access to the file is relative
+ * interface specify a relative path. All access to the file is relative
* to the open directory irrespective of if the directory is moved or replaced
* by an attacker while the directory is open. A {@code SecureDirectoryStream}
* may also be used as a virtual working directory.
@@ -65,8 +65,8 @@ import java.io.IOException;
* @since 1.7
*/
-public abstract class SecureDirectoryStream
- implements DirectoryStream Setting the ACL when creating a file
*
diff --git a/jdk/src/share/classes/java/nio/file/attribute/AttributeView.java b/jdk/src/share/classes/java/nio/file/attribute/AttributeView.java
index 6b0934e7af0..0e10f3341ac 100644
--- a/jdk/src/share/classes/java/nio/file/attribute/AttributeView.java
+++ b/jdk/src/share/classes/java/nio/file/attribute/AttributeView.java
@@ -25,20 +25,12 @@
package java.nio.file.attribute;
-import java.util.*;
-import java.io.IOException;
-
/**
* An object that provides a read-only or updatable view of non-opaque
* values associated with an object in a filesystem. This interface is extended
* or implemented by specific attribute views that define the attributes
* supported by the view. A specific attribute view will typically define
- * type-safe methods to read or update the attributes that it supports. It also
- * provides dynamic access where the {@link #readAttributes
- * readAttributes}, {@link #getAttribute getAttribute} and {@link #setAttribute
- * setAttributs} methods are used to access the attributes by names defined
- * by the attribute view. Implementations must ensure that the attribute names
- * do not contain the colon (':') or comma (',') characters.
+ * type-safe methods to read or update the attributes that it supports.
*
* @since 1.7
*/
@@ -48,71 +40,4 @@ public interface AttributeView {
* Returns the name of the attribute view.
*/
String name();
-
- /**
- * Reads the value of an attribute.
- *
- * @param attribute
- * the attribute name (case sensitive)
- *
- * @return the value of the attribute, or {@code null} if the attribute is
- * not supported
- *
- * @throws IOException
- * if an I/O error occurs
- * @throws SecurityException
- * if a security manager is set and it denies access
- */
- Object getAttribute(String attribute) throws IOException;
-
- /**
- * Sets/updates the value of an attribute.
- *
- * @param attribute
- * the attribute name (case sensitive)
- * @param value
- * the attribute value
- *
- * @throws UnsupportedOperationException
- * if the attribute is not supported or this attribute view does
- * not support updating the value of the attribute
- * @throws IllegalArgumentException
- * if the attribute value is of the correct type but has an
- * inappropriate value
- * @throws ClassCastException
- * if the attribute value is not of the expected type or is a
- * collection containing elements that are not of the expected
- * type
- * @throws IOException
- * if an I/O error occurs
- * @throws SecurityException
- * if a security manager is set and it denies access
- */
- void setAttribute(String attribute, Object value) throws IOException;
-
- /**
- * Reads all, or a subset, of the attributes supported by this file attribute
- * view.
- *
- *
- * [view-name:]attribute-name
- *
- * where square brackets [...] delineate an optional component and the
- * character {@code ':'} stands for itself.
- *
- *
- * Attributes.setAttribute(file, "dos:hidden", true);
- *
- *
- * @param file
- * A file reference that locates the file
- * @param attribute
- * The attribute to set
- * @param value
- * The attribute value
- *
- * @throws UnsupportedOperationException
- * If the attribute view is not available or it does not
- * support updating the attribute
- * @throws IllegalArgumentException
- * If the attribute value is of the correct type but has an
- * inappropriate value
- * @throws ClassCastException
- * If the attribute value is not of the expected type or is a
- * collection containing elements that are not of the expected
- * type
- * @throws IOException
- * If an I/O error occurs
- * @throws SecurityException
- * In the case of the default provider, and a security manager is
- * installed, its {@link SecurityManager#checkWrite(String) checkWrite}
- * method denies write access to the file. If this method is invoked
- * to set security sensitive attributes then the security manager
- * may be invoked to check for additional permissions.
- */
- public static void setAttribute(FileRef file, String attribute, Object value)
- throws IOException
- {
- String[] s = split(attribute);
- FileAttributeView view = file.getFileAttributeView(s[0]);
- if (view == null)
- throw new UnsupportedOperationException("View '" + s[0] + "' not available");
- view.setAttribute(s[1], value);
- }
-
- /**
- * Reads the value of a file attribute.
- *
- *
- * [view-name:]attribute-name
- *
- * where square brackets [...] delineate an optional component and the
- * character {@code ':'} stands for itself.
- *
- *
- * int uid = (Integer)Attributes.getAttribute(file, "unix:uid");
- *
- *
- * @param file
- * A file reference that locates the file
- * @param attribute
- * The attribute to read
- * @param options
- * Options indicating how symbolic links are handled
- *
- * @return The attribute value, or {@code null} if the attribute view
- * is not available or it does not support reading the attribute
- *
- * @throws IOException
- * If an I/O error occurs
- * @throws SecurityException
- * In the case of the default provider, and a security manager is
- * installed, its {@link SecurityManager#checkRead(String) checkRead}
- * method denies read access to the file. If this method is invoked
- * to read security sensitive attributes then the security manager
- * may be invoked to check for additional permissions.
- */
- public static Object getAttribute(FileRef file,
- String attribute,
- LinkOption... options)
- throws IOException
- {
- String[] s = split(attribute);
- FileAttributeView view = file.getFileAttributeView(s[0], options);
- if (view != null)
- return view.getAttribute(s[1]);
- // view not available
- return null;
- }
-
- /**
- * Reads a set of file attributes as a bulk operation.
- *
- *
- * [view-name:]attribute-list
- *
- * where square brackets [...] delineate an optional component and the
- * character {@code ':'} stands for itself.
- *
- *
- *
- *
- *
- *
- *
- *
- * {@code "*"}
- * Read all {@link BasicFileAttributes basic-file-attributes}.
- *
- *
- * {@code "size,lastModifiedTime,lastAccessTime"}
- * Reads the file size, last modified time, and last access time
- * attributes.
- *
- *
- * {@code "posix:*"}
- * Read all {@link PosixFileAttributes POSIX-file-attributes}..
- *
- *
- * {@code "posix:permissions,owner,size"}
- * Reads the POSX file permissions, owner, and file size.
- *
+ * FileTime now = FileTime.fromMillis(System.currentTimeMillis());
+ * Attributes.setLastModifiedTime(file, now);
+ *
*
* @param file
* A file reference that locates the file
- *
* @param lastModifiedTime
- * The new last modified time, or {@code -1L} to update it to
- * the current time
- * @param unit
- * A {@code TimeUnit} determining how to interpret the
- * {@code lastModifiedTime} parameter
+ * The new last modified time
*
- * @throws IllegalArgumentException
- * If the {@code lastModifiedime} parameter is a negative value other
- * than {@code -1L}
* @throws IOException
* If an I/O error occurs
* @throws SecurityException
@@ -584,35 +344,31 @@ public final class Attributes {
* @see BasicFileAttributeView#setTimes
*/
public static void setLastModifiedTime(FileRef file,
- long lastModifiedTime,
- TimeUnit unit)
+ FileTime lastModifiedTime)
throws IOException
{
+ if (lastModifiedTime == null)
+ throw new NullPointerException("'lastModifiedTime' is null");
file.getFileAttributeView(BasicFileAttributeView.class)
- .setTimes(lastModifiedTime, null, null, unit);
+ .setTimes(lastModifiedTime, null, null);
}
/**
- * Updates the value of a file's last access time attribute.
- *
- *
*
* "lastModifiedTime"
- * {@link Long}
+ * {@link FileTime}
*
*
* "lastAccessTime"
- * {@link Long}
+ * {@link FileTime}
*
*
- * "creationTime"
- * {@link Long}
- *
- *
* "resolution"
- * {@link java.util.concurrent.TimeUnit}
+ * {@link FileTime}
*
*
* "size"
@@ -84,26 +79,19 @@ import java.io.IOException;
* {@link Boolean}
*
- *
- * "linkCount"
- * {@link Integer}
- *
*
*
*
*
- * "fileKey"
* {@link Object}
* long
value representing the time the file was
- * last modified since the epoch (00:00:00 GMT, January 1, 1970),
- * or {@code -1L} if the attribute is not supported.
+ * @return a {@code FileTime} representing the time the file was last
+ * modified or {@code null} if the attribute is not supported.
*/
- long lastModifiedTime();
+ FileTime lastModifiedTime();
/**
* Returns the time of last access if supported.
*
- * long
value representing the time of last access
- * since the epoch (00:00:00 GMT, January 1, 1970), or {@code -1L}
- * if the attribute is not supported.
+ * @return a {@code FileTime} representing the time of last access or
+ * {@code null} if the attribute is not supported.
*/
- long lastAccessTime();
+ FileTime lastAccessTime();
/**
* Returns the creation time if supported. The creation time is the time
* that the file was created.
*
- * long
value representing the time the file was
- * created since the epoch (00:00:00 GMT, January 1, 1970), or
- * {@code -1L} if the attribute is not supported.
+ * @return a {@code FileTime} representing the time the file was created
+ * or {@code null} if the attribute is not supported.
*/
- long creationTime();
-
- /**
- * Returns the {@link TimeUnit} required to interpret the time of last
- * modification, time of last access, and creation time.
- *
- * @return the {@code TimeUnit} required to interpret the file time stamps
- */
- TimeUnit resolution();
+ FileTime creationTime();
/**
* Tells whether the file is a regular file with opaque content.
@@ -124,18 +102,6 @@ public interface BasicFileAttributes {
*/
long size();
- /**
- * Returns the number of links to this file.
- *
- *
+ * YYYY-MM-DDThh:mm:ss[.s+]Z
+ *
+ * where "{@code [.s+]}" represents a dot followed by one of more digits
+ * for the decimal fraction of a second. It is only present when the decimal
+ * fraction of a second is not zero. For example, {@code
+ * FileTime.fromMillis(1234567890000L).toString()} yields {@code
+ * "2009-02-13T23:31:30Z"}, and {@code FileTime.fromMillis(1234567890123L).toString()}
+ * yields {@code "2009-02-13T23:31:30.123Z"}.
+ *
+ *
- * Path dir = ...
- * Files.withDirectory(dir, "*.class", new FileAction<Path>() {
- * public void invoke(Path entry) {
- * :
- * }
- * });
- *
- *
- * @param