- 
- All Superinterfaces:
- AutoCloseable,- Closeable,- DirectoryStream<T>,- Iterable<T>
 
 
 public interface SecureDirectoryStream<T> extends DirectoryStream<T> ADirectoryStreamthat defines operations on files that are located relative to an open directory. ASecureDirectoryStreamis intended for use by sophisticated or security sensitive applications requiring to 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 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. ASecureDirectoryStreammay also be used as a virtual working directory.A SecureDirectoryStreamrequires corresponding support from the underlying operating system. Where an implementation supports this features then theDirectoryStreamreturned by thenewDirectoryStreammethod will be aSecureDirectoryStreamand must be cast to that type in order to invoke the methods defined by this interface.In the case of the default provider, and a security manager is set, then the permission checks are performed using the path obtained by resolving the given relative path against the original path of the directory (irrespective of if the directory is moved since it was opened).- Since:
- 1.7
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface java.nio.file.DirectoryStreamDirectoryStream.Filter<T>
 
- 
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddeleteDirectory(T path)Deletes a directory.voiddeleteFile(T path)Deletes a file.<V extends FileAttributeView>
 VgetFileAttributeView(Class<V> type)Returns a new file attribute view to access the file attributes of this directory.<V extends FileAttributeView>
 VgetFileAttributeView(T path, Class<V> type, LinkOption... options)Returns a new file attribute view to access the file attributes of a file in this directory.voidmove(T srcpath, SecureDirectoryStream<T> targetdir, T targetpath)Move a file from this directory to another directory.SeekableByteChannelnewByteChannel(T path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)Opens or creates a file in this directory, returning a seekable byte channel to access the file.SecureDirectoryStream<T>newDirectoryStream(T path, LinkOption... options)Opens the directory identified by the given path, returning aSecureDirectoryStreamto iterate over the entries in the directory.- 
Methods inherited from interface java.nio.file.DirectoryStreamiterator
 - 
Methods inherited from interface java.lang.IterableforEach, spliterator
 
- 
 
- 
- 
- 
Method Detail- 
newDirectoryStreamSecureDirectoryStream<T> newDirectoryStream(T path, LinkOption... options) throws IOException Opens the directory identified by the given path, returning aSecureDirectoryStreamto iterate over the entries in the directory.This method works in exactly the manner specified by the newDirectoryStreammethod for the case that thepathparameter is anabsolutepath. When the parameter is a relative path then the directory to open is relative to this open directory. TheNOFOLLOW_LINKSoption 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 effect upon newly created directory stream. - Parameters:
- path- the path to the directory to open
- options- options indicating how symbolic links are handled
- Returns:
- a new and open SecureDirectoryStreamobject
- Throws:
- ClosedDirectoryStreamException- if the directory stream is closed
- NotDirectoryException- if the file could not otherwise be opened because it is not a directory (optional specific exception)
- IOException- if an I/O error occurs
- SecurityException- In the case of the default provider, and a security manager is installed, the- checkReadmethod is invoked to check read access to the directory.
 
 - 
newByteChannelSeekableByteChannel newByteChannel(T path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException Opens or creates a file in this directory, returning a seekable byte channel to access the file.This method works in exactly the manner specified by the Files.newByteChannelmethod for the case that thepathparameter is anabsolutepath. When the parameter is a relative path then the file to open or create is relative to this open directory. In addition to the options defined by theFiles.newByteChannelmethod, theNOFOLLOW_LINKSoption may be used to ensure that this method fails if the file is a symbolic link.The channel, once created, is not dependent upon the directory stream used to create it. Closing this directory stream has no effect upon the channel. - Parameters:
- path- the path of the file to open or create
- options- options specifying how the file is opened
- attrs- an optional list of attributes to set atomically when creating the file
- Returns:
- the seekable byte channel
- Throws:
- ClosedDirectoryStreamException- if the directory stream is closed
- IllegalArgumentException- if the set contains an invalid combination of options
- UnsupportedOperationException- if an unsupported open option is specified or the array contains attributes that cannot be set atomically when creating the file
- FileAlreadyExistsException- if a file of that name already exists and the- CREATE_NEWoption is specified (optional specific exception)
- IOException- if an I/O error occurs
- SecurityException- In the case of the default provider, and a security manager is installed, the- checkReadmethod is invoked to check read access to the path if the file is opened for reading. The- checkWritemethod is invoked to check write access to the path if the file is opened for writing.
 
 - 
deleteFilevoid deleteFile(T path) throws IOException Deletes a file.Unlike the 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 itself, not the final target of the link, is deleted. When the parameter is a relative path then the file to delete is relative to this open directory.- Parameters:
- path- the path of the file to delete
- Throws:
- ClosedDirectoryStreamException- if the directory stream is closed
- NoSuchFileException- if the file does not exist (optional specific exception)
- IOException- if an I/O error occurs
- SecurityException- In the case of the default provider, and a security manager is installed, the- checkDeletemethod is invoked to check delete access to the file
 
 - 
deleteDirectoryvoid deleteDirectory(T path) throws IOException Deletes a directory.Unlike the 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 directory to delete is relative to this open directory.- Parameters:
- path- the path of the directory to delete
- Throws:
- ClosedDirectoryStreamException- if the directory stream is closed
- NoSuchFileException- if the directory does not exist (optional specific exception)
- DirectoryNotEmptyException- if the directory could not otherwise be deleted because it is not empty (optional specific exception)
- IOException- if an I/O error occurs
- SecurityException- In the case of the default provider, and a security manager is installed, the- checkDeletemethod is invoked to check delete access to the directory
 
 - 
movevoid move(T srcpath, SecureDirectoryStream<T> targetdir, T targetpath) throws IOException Move a file from this directory to another directory.This method works in a similar manner to movemethod when theATOMIC_MOVEoption is specified. That is, this method moves a file as an atomic file system operation. If thesrcpathparameter is anabsolutepath then it locates the source file. If the parameter is a relative path then it is located relative to this open directory. If thetargetpathparameter is absolute then it locates the target file (thetargetdirparameter is ignored). If the parameter is a relative path it is located relative to the open directory identified by thetargetdirparameter. In all cases, if the target file exists then it is implementation specific if it is replaced or this method fails.- Parameters:
- srcpath- the name of the file to move
- targetdir- the destination directory
- targetpath- the name to give the file in the destination directory
- Throws:
- ClosedDirectoryStreamException- if this or the target directory stream is closed
- FileAlreadyExistsException- if the file already exists in the target directory and cannot be replaced (optional specific exception)
- AtomicMoveNotSupportedException- if the file cannot be moved as an atomic file system operation
- IOException- if an I/O error occurs
- SecurityException- In the case of the default provider, and a security manager is installed, the- checkWritemethod is invoked to check write access to both the source and target file.
 
 - 
getFileAttributeView<V extends FileAttributeView> V getFileAttributeView(Class<V> type) Returns a new file attribute view to access the file attributes of this directory.The resulting file attribute view can be used to read or update the attributes of this (open) directory. The typeparameter specifies the type of the attribute view and the method returns an instance of that type if supported. Invoking this method to obtain aBasicFileAttributeViewalways returns an instance of that class that is bound to this open directory.The state of resulting file attribute view is intimately connected to this directory stream. Once the directory stream is closed, then all methods to read or update attributes will throwClosedDirectoryStreamException.- Type Parameters:
- V- The- FileAttributeViewtype
- Parameters:
- type- the- Classobject corresponding to the file attribute view
- Returns:
- a new file attribute view of the specified type bound to
          this directory stream, or nullif the attribute view type is not available
 
 - 
getFileAttributeView<V extends FileAttributeView> V getFileAttributeView(T path, Class<V> type, LinkOption... options) Returns a new file attribute view to access the file attributes of a file in this directory.The resulting file attribute view can be used to read or update the attributes of file in this directory. The typeparameter specifies the type of the attribute view and the method returns an instance of that type if supported. Invoking this method to obtain aBasicFileAttributeViewalways returns an instance of that class that is bound to the file in the directory.The state of resulting file attribute view is intimately connected to this directory stream. Once the directory stream closed, then all methods to read or update attributes will throwClosedDirectoryStreamException. The file is not required to exist at the time that the file attribute view is created but methods to read or update attributes of the file will fail when invoked and the file does not exist.- Type Parameters:
- V- The- FileAttributeViewtype
- Parameters:
- path- the path of the file
- type- the- Classobject corresponding to the file attribute view
- options- options indicating how symbolic links are handled
- Returns:
- a new file attribute view of the specified type bound to a
          this directory stream, or nullif the attribute view type is not available
 
 
- 
 
-