SecureDirectoryStream.java revision 1319
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk/*
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Copyright 2007-2009 Sun Microsystems, Inc. All Rights Reserved.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * This code is free software; you can redistribute it and/or modify it
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * under the terms of the GNU General Public License version 2 only, as
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * published by the Free Software Foundation. Sun designates this
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * particular file as subject to the "Classpath" exception as provided
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * by Sun in the LICENSE file that accompanied this code.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * This code is distributed in the hope that it will be useful, but WITHOUT
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * version 2 for more details (a copy is included in the LICENSE file that
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * accompanied this code).
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * You should have received a copy of the GNU General Public License version
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * 2 along with this work; if not, write to the Free Software Foundation,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * CA 95054 USA or visit www.sun.com if you need additional information or
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * have any questions.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkpackage java.nio.file;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkimport java.nio.file.attribute.*;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkimport java.nio.channels.SeekableByteChannel;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkimport java.util.Set;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkimport java.io.IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk/**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * A {@code DirectoryStream} that defines operations on files that are located
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * relative to an open directory. A {@code SecureDirectoryStream} is intended
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * for use by sophisticated or security sensitive applications requiring to
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * traverse file trees or otherwise operate on directories in a race-free manner.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Race conditions can arise when a sequence of file operations cannot be
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * carried out in isolation. Each of the file operations defined by this
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * interface specify a relative path. All access to the file is relative
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * to the open directory irrespective of if the directory is moved or replaced
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * by an attacker while the directory is open. A {@code SecureDirectoryStream}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * may also be used as a virtual <em>working directory</em>.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> A {@code SecureDirectoryStream} requires corresponding support from the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * underlying operating system. Where an implementation supports this features
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * then the {@code DirectoryStream} returned by the {@link Path#newDirectoryStream
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * newDirectoryStream} method will be a {@code SecureDirectoryStream} and must
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * be cast to that type in order to invoke the methods defined by this interface.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> As specified by {@code DirectoryStream}, the iterator's {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * java.util.Iterator#remove() remove} method removes the directory entry for
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the last element returned by the iterator. In the case of a {@code
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * SecureDirectoryStream} the {@code remove} method behaves as if by invoking
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the {@link #deleteFile deleteFile} or {@link #deleteDirectory deleteDirectory}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * methods defined by this interface. The {@code remove} may require to examine
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the file to determine if the file is a directory, and consequently, it may
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * not be atomic with respect to other file system operations.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> In the case of the default {@link java.nio.file.spi.FileSystemProvider
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * provider}, and a security manager is set, then the permission checks are
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * performed using the path obtained by resolving the given relative path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * against the <i>original path</i> of the directory (irrespective of if the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * directory is moved since it was opened).
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @since 1.7
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenkpublic abstract class SecureDirectoryStream<T>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk implements DirectoryStream<T>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk{
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Initialize a new instance of this class.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk protected SecureDirectoryStream() { }
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Opens the directory identified by the given path, returning a {@code
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * SecureDirectoryStream} to iterate over the entries in the directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> This method works in exactly the manner specified by the {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Path#newDirectoryStream() newDirectoryStream} method for the case that
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the {@code path} parameter is an {@link Path#isAbsolute absolute} path.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * When the parameter is a relative path then the directory to open is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * relative to this open directory. The {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * ensure that this method fails if the file is a symbolic link.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The new directory stream, once created, is not dependent upon the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * directory stream used to create it. Closing this directory stream has no
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * effect upon newly created directory stream.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the path to the directory to open
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param options
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * options indicating how symbolic links are handled
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @return a new and open {@code SecureDirectoryStream} object
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws ClosedDirectoryStreamException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory stream is closed
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws NotDirectoryException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the file could not otherwise be opened because it is not
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * a directory <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IOException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an I/O error occurs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws SecurityException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * In the case of the default provider, and a security manager is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * installed, the {@link SecurityManager#checkRead(String) checkRead}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method is invoked to check read access to the directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract SecureDirectoryStream<T> newDirectoryStream(T path,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk LinkOption... options)
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk throws IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Opens or creates a file in this directory, returning a seekable byte
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * channel to access the file.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> This method works in exactly the manner specified by the {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Path#newByteChannel Path.newByteChannel} method for the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * case that the {@code path} parameter is an {@link Path#isAbsolute absolute}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * path. When the parameter is a relative path then the file to open or
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * create is relative to this open directory. In addition to the options
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * defined by the {@code Path.newByteChannel} method, the {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * ensure that this method fails if the file is a symbolic link.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The channel, once created, is not dependent upon the directory stream
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * used to create it. Closing this directory stream has no effect upon the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * channel.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the path of the file to open open or create
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param options
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * options specifying how the file is opened
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param attrs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * an optional list of attributes to set atomically when creating
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws ClosedDirectoryStreamException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory stream is closed
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IllegalArgumentException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the set contains an invalid combination of options
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws UnsupportedOperationException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an unsupported open option is specified or the array contains
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * attributes that cannot be set atomically when creating the file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws FileAlreadyExistsException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if a file of that name already exists and the {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IOException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an I/O error occurs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws SecurityException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * In the case of the default provider, and a security manager is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * installed, the {@link SecurityManager#checkRead(String) checkRead}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method is invoked to check read access to the path if the file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * is opened for reading. The {@link SecurityManager#checkWrite(String)
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * checkWrite} method is invoked to check write access to the path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the file is opened for writing.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract SeekableByteChannel newByteChannel(T path,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk Set<? extends OpenOption> options,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk FileAttribute<?>... attrs)
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk throws IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Deletes a file.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> Unlike the {@link Path#delete delete()} method, this method
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * does not first examine the file to determine if the file is a directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Whether a directory is deleted by this method is system dependent and
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * therefore not specified. If the file is a symbolic-link then the link is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * deleted (not the final target of the link). When the parameter is a
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * relative path then the file to delete is relative to this open directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the path of the file to delete
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws ClosedDirectoryStreamException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory stream is closed
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws NoSuchFileException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the file does not exist <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IOException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an I/O error occurs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws SecurityException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * In the case of the default provider, and a security manager is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * installed, the {@link SecurityManager#checkDelete(String) checkDelete}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method is invoked to check delete access to the file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract void deleteFile(T path) throws IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Deletes a directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> Unlike the {@link Path#delete delete()} method, this method
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * does not first examine the file to determine if the file is a directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Whether non-directories are deleted by this method is system dependent and
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * therefore not specified. When the parameter is a relative path then the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * directory to delete is relative to this open directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the path of the directory to delete
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws ClosedDirectoryStreamException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory stream is closed
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws NoSuchFileException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory does not exist <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws DirectoryNotEmptyException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the directory could not otherwise be deleted because it is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * not empty <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IOException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an I/O error occurs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws SecurityException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * In the case of the default provider, and a security manager is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * installed, the {@link SecurityManager#checkDelete(String) checkDelete}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method is invoked to check delete access to the directory
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract void deleteDirectory(T path) throws IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Move a file from this directory to another directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> This method works in a similar manner to {@link Path#moveTo moveTo}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method when the {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} option
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * is specified. That is, this method moves a file as an atomic file system
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * operation. If the {@code srcpath} parameter is an {@link Path#isAbsolute
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * absolute} path then it locates the source file. If the parameter is a
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * relative path then it is located relative to this open directory. If
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the {@code targetpath} parameter is absolute then it locates the target
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * file (the {@code targetdir} parameter is ignored). If the parameter is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * a relative path it is located relative to the open directory identified
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * by the {@code targetdir} parameter. In all cases, if the target file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * exists then it is implementation specific if it is replaced or this
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method fails.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param srcpath
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the name of the file to move
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param targetdir
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the destination directory
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param targetpath
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the name to give the file in the destination directory
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws ClosedDirectoryStreamException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if this or the target directory stream is closed
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws FileAlreadyExistsException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the file already exists in the target directory and cannot
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * be replaced <i>(optional specific exception)</i>
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws AtomicMoveNotSupportedException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if the file cannot be moved as an atomic file system operation
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws IOException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * if an I/O error occurs
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @throws SecurityException
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * In the case of the default provider, and a security manager is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * method is invoked to check write access to both the source and
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * target file.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract void move(T srcpath, SecureDirectoryStream<T> targetdir, T targetpath)
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk throws IOException;
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Returns a new file attribute view to access the file attributes of this
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The resulting file attribute view can be used to read or update the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * attributes of this (open) directory. The {@code type} parameter specifies
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the type of the attribute view and the method returns an instance of that
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * type if supported. Invoking this method to obtain a {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * BasicFileAttributeView} always returns an instance of that class that is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * bound to this open directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The state of resulting file attribute view is intimately connected
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * to this directory stream. Once the directory stream is {@link #close closed},
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * then all methods to read or update attributes will throw {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * ClosedDirectoryStreamException ClosedDirectoryStreamException}.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param type
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the {@code Class} object corresponding to the file attribute view
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @return a new file attribute view of the specified type bound to
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * this directory stream, or {@code null} if the attribute view
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * type is not available
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract <V extends FileAttributeView> V getFileAttributeView(Class<V> type);
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk /**
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * Returns a new file attribute view to access the file attributes of a file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * in this directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The resulting file attribute view can be used to read or update the
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * attributes of file in this directory. The {@code type} parameter specifies
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the type of the attribute view and the method returns an instance of that
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * type if supported. Invoking this method to obtain a {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * BasicFileAttributeView} always returns an instance of that class that is
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * bound to the file in the directory.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * <p> The state of resulting file attribute view is intimately connected
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * to this directory stream. Once the directory stream {@link #close closed},
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * then all methods to read or update attributes will throw {@link
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * ClosedDirectoryStreamException ClosedDirectoryStreamException}. The
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * file is not required to exist at the time that the file attribute view
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * is created but methods to read or update attributes of the file will
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * fail when invoked and the file does not exist.
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param path
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the path of the file
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param type
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * the {@code Class} object corresponding to the file attribute view
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @param options
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * options indicating how symbolic links are handled
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * @return a new file attribute view of the specified type bound to a
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * this directory stream, or {@code null} if the attribute view
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk * type is not available
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk *
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk */
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk public abstract <V extends FileAttributeView> V getFileAttributeView(T path,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk Class<V> type,
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk LinkOption... options);
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk}
c1350cf5bc50458ba79cc93ff9e0e5fe3f1aeeb0jeff.schenk