|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.classpath.icedtea.java.nio.file.SecureDirectoryStream
public abstract class SecureDirectoryStream
A DirectoryStream
that defines operations on files that are located
relative to an open directory. A SecureDirectoryStream
is 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. A SecureDirectoryStream
may also be used as a virtual working directory.
A SecureDirectoryStream
requires corresponding support from the
underlying operating system. Where an implementation supports this features
then the DirectoryStream
returned by the newDirectoryStream
method will be a SecureDirectoryStream
and must
be cast to that type in order to invoke the methods defined by this interface.
As specified by DirectoryStream
, the iterator's remove
method removes the directory entry for
the last element returned by the iterator. In the case of a SecureDirectoryStream
the remove
method behaves as if by invoking
the deleteFile
or deleteDirectory
methods defined by this interface. The remove
may require to examine
the file to determine if the file is a directory, and consequently, it may
not be atomic with respect to other file system operations.
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).
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.classpath.icedtea.java.nio.file.DirectoryStream |
---|
DirectoryStream.Filter<T> |
Constructor Summary | |
---|---|
protected |
SecureDirectoryStream()
Initialize a new instance of this class. |
Method Summary | ||
---|---|---|
abstract void |
deleteDirectory(Path path)
Deletes a directory. |
|
abstract void |
deleteFile(Path path)
Deletes a file. |
|
abstract
|
getFileAttributeView(java.lang.Class<V> type)
Returns a new file attribute view to access the file attributes of this directory. |
|
abstract
|
getFileAttributeView(Path path,
java.lang.Class<V> type,
LinkOption... options)
Returns a new file attribute view to access the file attributes of a file in this directory. |
|
abstract void |
move(Path srcpath,
SecureDirectoryStream targetdir,
Path targetpath)
Move a file from this directory to another directory. |
|
abstract SeekableByteChannel |
newByteChannel(Path path,
java.util.Set<? extends OpenOption> options,
FileAttribute<?>... attrs)
Opens or creates a file in this directory, returning a seekable byte channel to access the file. |
|
abstract SecureDirectoryStream |
newDirectoryStream(Path path,
boolean followLinks,
DirectoryStream.Filter<? super Path> filter)
Opens the directory identified by the given path, returning a SecureDirectoryStream to iterate over the entries in the directory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.classpath.icedtea.java.nio.file.DirectoryStream |
---|
iterator |
Methods inherited from interface java.io.Closeable |
---|
close |
Constructor Detail |
---|
protected SecureDirectoryStream()
Method Detail |
---|
public abstract SecureDirectoryStream newDirectoryStream(Path path, boolean followLinks, DirectoryStream.Filter<? super Path> filter) throws java.io.IOException
SecureDirectoryStream
to iterate over the entries in the directory.
This method works in exactly the manner specified by the newDirectoryStream
method for the case that
the path
parameter is an absolute
path.
When the parameter is a relative path then the directory to open is
relative to this open directory. The followLinks
parameter
determines if links should be followed. If this parameter is false
and the file is a symbolic link then this method fails (by
throwing an I/O exception).
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.
path
- The path to the directory to openfollowLinks
- true
if the links should be followedfilter
- The directory stream filter or null
.
SecureDirectoryStream
object
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)
java.io.IOException
- If an I/O error occurs
java.lang.SecurityException
- In the case of the default provider, and a security manager is
installed, the checkRead
method is invoked to check read access to the directory.public abstract SeekableByteChannel newByteChannel(Path path, java.util.Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws java.io.IOException
This method works in exactly the manner specified by the Path.newByteChannel
method for the
case that the path
parameter is an absolute
path. 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 the Path.newByteChannel
method, the NOFOLLOW_LINKS
option 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.
path
- The path of the file to open open or createoptions
- Options specifying how the file is openedattrs
- An optional list of attributes to set atomically when creating
the file
ClosedDirectoryStreamException
- If the directory stream is closed
java.lang.IllegalArgumentException
- If the set contains an invalid combination of options
java.lang.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_NEW
option is specified
(optional specific exception)
java.io.IOException
- If an I/O error occurs
java.lang.SecurityException
- In the case of the default provider, and a security manager is
installed, the checkRead
method is invoked to check read access to the path if the file
is opened for reading. The checkWrite
method is invoked to check write access to the path
if the file is opened for writing.public abstract void deleteFile(Path path) throws java.io.IOException
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 is
deleted (not the final target of the link). When the parameter is a
relative path then the file to delete is relative to this open directory.
path
- The path of the file to delete
ClosedDirectoryStreamException
- If the directory stream is closed
NoSuchFileException
- If the the file does not exist (optional specific exception)
java.io.IOException
- If an I/O error occurs
java.lang.SecurityException
- In the case of the default provider, and a security manager is
installed, the checkDelete
method is invoked to check delete access to the filepublic abstract void deleteDirectory(Path path) throws java.io.IOException
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.
path
- The path of the directory to delete
ClosedDirectoryStreamException
- If the directory stream is closed
NoSuchFileException
- If the 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)
java.io.IOException
- If an I/O error occurs
java.lang.SecurityException
- In the case of the default provider, and a security manager is
installed, the checkDelete
method is invoked to check delete access to the directorypublic abstract void move(Path srcpath, SecureDirectoryStream targetdir, Path targetpath) throws java.io.IOException
This method works in a similar manner to moveTo
method when the ATOMIC_MOVE
option
is specified. That is, this method moves a file as an atomic file system
operation. If the srcpath
parameter is an absolute
path then it locates the source file. If the parameter is a
relative path then it is located relative to this open directory. If
the targetpath
parameter is absolute then it locates the target
file (the targetdir
parameter is ignored). If the parameter is
a relative path it is located relative to the open directory identified
by the targetdir
parameter. In all cases, if the target file
exists then it is implementation specific if it is replaced or this
method fails.
srcpath
- The name of the file to movetargetdir
- The destination directorytargetpath
- The name to give the file in the destination directory
ClosedDirectoryStreamException
- If this or the target directory stream is closed
FileAlreadyExistsException
- The file already exists in the target directory and cannot
be replaced (optional specific exception)
AtomicMoveNotSupportedException
- The file cannot be moved as an atomic file system operation
java.io.IOException
- If an I/O error occurs
java.lang.SecurityException
- In the case of the default provider, and a security manager is
installed, the checkWrite
method is invoked to check write access to both the source and
target file.public abstract <V extends FileAttributeView> V getFileAttributeView(java.lang.Class<V> type)
The resulting file attribute view can be used to read or update the
attributes of this (open) directory. The type
parameter specifies
the type of the attribute view and the method returns an instance of that
type if supported. Invoking this method to obtain a BasicFileAttributeView
always 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 throw ClosedDirectoryStreamException
.
type
- The Class
object corresponding to the file attribute view
null
if the attribute view
type is not availablepublic abstract <V extends FileAttributeView> V getFileAttributeView(Path path, java.lang.Class<V> type, LinkOption... options)
The resulting file attribute view can be used to read or update the
attributes of file in this directory. The type
parameter specifies
the type of the attribute view and the method returns an instance of that
type if supported. Invoking this method to obtain a BasicFileAttributeView
always 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 throw ClosedDirectoryStreamException
. 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.
path
- The path of the filetype
- The Class
object corresponding to the file attribute viewoptions
- Options indicating how symbolic links are handled
null
if the attribute view
type is not available
|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2010 Sun Microsystems, Inc. All rights reserved. Use is subject to the terms of the GNU General Public License.