feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
68
jdkSrc/jdk8/java/nio/file/AccessDeniedException.java
Normal file
68
jdkSrc/jdk8/java/nio/file/AccessDeniedException.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file system operation is denied, typically
|
||||
* due to a file permission or other access check.
|
||||
*
|
||||
* <p> This exception is not related to the {@link
|
||||
* java.security.AccessControlException AccessControlException} or {@link
|
||||
* SecurityException} thrown by access controllers or security managers when
|
||||
* access to a file is denied.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class AccessDeniedException
|
||||
extends FileSystemException
|
||||
{
|
||||
private static final long serialVersionUID = 4943049599949219617L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
*/
|
||||
public AccessDeniedException(String file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
* @param other
|
||||
* a string identifying the other file or {@code null} if not known
|
||||
* @param reason
|
||||
* a reason message with additional information or {@code null}
|
||||
*/
|
||||
public AccessDeniedException(String file, String other, String reason) {
|
||||
super(file, other, reason);
|
||||
}
|
||||
}
|
47
jdkSrc/jdk8/java/nio/file/AccessMode.java
Normal file
47
jdkSrc/jdk8/java/nio/file/AccessMode.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines access modes used to test the accessibility of a file.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum AccessMode {
|
||||
/**
|
||||
* Test read access.
|
||||
*/
|
||||
READ,
|
||||
/**
|
||||
* Test write access.
|
||||
*/
|
||||
WRITE,
|
||||
/**
|
||||
* Test execute access.
|
||||
*/
|
||||
EXECUTE;
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file cannot be moved as an atomic file system
|
||||
* operation.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class AtomicMoveNotSupportedException
|
||||
extends FileSystemException
|
||||
{
|
||||
static final long serialVersionUID = 5402760225333135579L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param source
|
||||
* a string identifying the source file or {@code null} if not known
|
||||
* @param target
|
||||
* a string identifying the target file or {@code null} if not known
|
||||
* @param reason
|
||||
* a reason message with additional information
|
||||
*/
|
||||
public AtomicMoveNotSupportedException(String source,
|
||||
String target,
|
||||
String reason)
|
||||
{
|
||||
super(source, target, reason);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to invoke an operation on
|
||||
* a directory stream that is closed.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class ClosedDirectoryStreamException
|
||||
extends IllegalStateException
|
||||
{
|
||||
static final long serialVersionUID = 4228386650900895400L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ClosedDirectoryStreamException() {
|
||||
}
|
||||
}
|
43
jdkSrc/jdk8/java/nio/file/ClosedFileSystemException.java
Normal file
43
jdkSrc/jdk8/java/nio/file/ClosedFileSystemException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to invoke an operation on
|
||||
* a file and the file system is closed.
|
||||
*/
|
||||
|
||||
public class ClosedFileSystemException
|
||||
extends IllegalStateException
|
||||
{
|
||||
static final long serialVersionUID = -8158336077256193488L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ClosedFileSystemException() {
|
||||
}
|
||||
}
|
43
jdkSrc/jdk8/java/nio/file/ClosedWatchServiceException.java
Normal file
43
jdkSrc/jdk8/java/nio/file/ClosedWatchServiceException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to invoke an operation on
|
||||
* a watch service that is closed.
|
||||
*/
|
||||
|
||||
public class ClosedWatchServiceException
|
||||
extends IllegalStateException
|
||||
{
|
||||
static final long serialVersionUID = 1853336266231677732L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ClosedWatchServiceException() {
|
||||
}
|
||||
}
|
160
jdkSrc/jdk8/java/nio/file/CopyMoveHelper.java
Normal file
160
jdkSrc/jdk8/java/nio/file/CopyMoveHelper.java
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.*;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Helper class to support copying or moving files when the source and target
|
||||
* are associated with different providers.
|
||||
*/
|
||||
|
||||
class CopyMoveHelper {
|
||||
private CopyMoveHelper() { }
|
||||
|
||||
/**
|
||||
* Parses the arguments for a file copy operation.
|
||||
*/
|
||||
private static class CopyOptions {
|
||||
boolean replaceExisting = false;
|
||||
boolean copyAttributes = false;
|
||||
boolean followLinks = true;
|
||||
|
||||
private CopyOptions() { }
|
||||
|
||||
static CopyOptions parse(CopyOption... options) {
|
||||
CopyOptions result = new CopyOptions();
|
||||
for (CopyOption option: options) {
|
||||
if (option == StandardCopyOption.REPLACE_EXISTING) {
|
||||
result.replaceExisting = true;
|
||||
continue;
|
||||
}
|
||||
if (option == LinkOption.NOFOLLOW_LINKS) {
|
||||
result.followLinks = false;
|
||||
continue;
|
||||
}
|
||||
if (option == StandardCopyOption.COPY_ATTRIBUTES) {
|
||||
result.copyAttributes = true;
|
||||
continue;
|
||||
}
|
||||
if (option == null)
|
||||
throw new NullPointerException();
|
||||
throw new UnsupportedOperationException("'" + option +
|
||||
"' is not a recognized copy option");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<len; i++) {
|
||||
CopyOption option = options[i];
|
||||
if (option == StandardCopyOption.ATOMIC_MOVE) {
|
||||
throw new AtomicMoveNotSupportedException(null, null,
|
||||
"Atomic move between providers is not supported");
|
||||
}
|
||||
newOptions[i] = option;
|
||||
}
|
||||
newOptions[len] = LinkOption.NOFOLLOW_LINKS;
|
||||
newOptions[len+1] = StandardCopyOption.COPY_ATTRIBUTES;
|
||||
return newOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple copy for use when source and target are associated with different
|
||||
* providers
|
||||
*/
|
||||
static void copyToForeignTarget(Path source, Path target,
|
||||
CopyOption... options)
|
||||
throws IOException
|
||||
{
|
||||
CopyOptions opts = CopyOptions.parse(options);
|
||||
LinkOption[] linkOptions = (opts.followLinks) ? new LinkOption[0] :
|
||||
new LinkOption[] { LinkOption.NOFOLLOW_LINKS };
|
||||
|
||||
// attributes of source file
|
||||
BasicFileAttributes attrs = Files.readAttributes(source,
|
||||
BasicFileAttributes.class,
|
||||
linkOptions);
|
||||
if (attrs.isSymbolicLink())
|
||||
throw new IOException("Copying of symbolic links not supported");
|
||||
|
||||
// delete target if it exists and REPLACE_EXISTING is specified
|
||||
if (opts.replaceExisting) {
|
||||
Files.deleteIfExists(target);
|
||||
} else if (Files.exists(target))
|
||||
throw new FileAlreadyExistsException(target.toString());
|
||||
|
||||
// create directory or copy file
|
||||
if (attrs.isDirectory()) {
|
||||
Files.createDirectory(target);
|
||||
} else {
|
||||
try (InputStream in = Files.newInputStream(source)) {
|
||||
Files.copy(in, target);
|
||||
}
|
||||
}
|
||||
|
||||
// copy basic attributes to target
|
||||
if (opts.copyAttributes) {
|
||||
BasicFileAttributeView view =
|
||||
Files.getFileAttributeView(target, BasicFileAttributeView.class);
|
||||
try {
|
||||
view.setTimes(attrs.lastModifiedTime(),
|
||||
attrs.lastAccessTime(),
|
||||
attrs.creationTime());
|
||||
} catch (Throwable x) {
|
||||
// rollback
|
||||
try {
|
||||
Files.delete(target);
|
||||
} catch (Throwable suppressed) {
|
||||
x.addSuppressed(suppressed);
|
||||
}
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple move implements as copy+delete for use when source and target are
|
||||
* associated with different providers
|
||||
*/
|
||||
static void moveToForeignTarget(Path source, Path target,
|
||||
CopyOption... options) throws IOException
|
||||
{
|
||||
copyToForeignTarget(source, target, convertMoveToCopyOptions(options));
|
||||
Files.delete(source);
|
||||
}
|
||||
}
|
45
jdkSrc/jdk8/java/nio/file/CopyOption.java
Normal file
45
jdkSrc/jdk8/java/nio/file/CopyOption.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* An object that configures how to copy or move a file.
|
||||
*
|
||||
* <p> Objects of this type may be used with the {@link
|
||||
* Files#copy(Path,Path,CopyOption[]) Files.copy(Path,Path,CopyOption...)},
|
||||
* {@link Files#copy(java.io.InputStream,Path,CopyOption[])
|
||||
* Files.copy(InputStream,Path,CopyOption...)} and {@link Files#move
|
||||
* Files.move(Path,Path,CopyOption...)} methods to configure how a file is
|
||||
* copied or moved.
|
||||
*
|
||||
* <p> The {@link StandardCopyOption} enumeration type defines the
|
||||
* <i>standard</i> options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface CopyOption {
|
||||
}
|
87
jdkSrc/jdk8/java/nio/file/DirectoryIteratorException.java
Normal file
87
jdkSrc/jdk8/java/nio/file/DirectoryIteratorException.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Objects;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.InvalidObjectException;
|
||||
|
||||
/**
|
||||
* Runtime exception thrown if an I/O error is encountered when iterating over
|
||||
* the entries in a directory. The I/O error is retrieved as an {@link
|
||||
* IOException} using the {@link #getCause() getCause()} method.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see DirectoryStream
|
||||
*/
|
||||
|
||||
public final class DirectoryIteratorException
|
||||
extends ConcurrentModificationException
|
||||
{
|
||||
private static final long serialVersionUID = -6012699886086212874L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param cause
|
||||
* the {@code IOException} that caused the directory iteration
|
||||
* to fail
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if the cause is {@code null}
|
||||
*/
|
||||
public DirectoryIteratorException(IOException cause) {
|
||||
super(Objects.requireNonNull(cause));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception.
|
||||
*
|
||||
* @return the cause
|
||||
*/
|
||||
@Override
|
||||
public IOException getCause() {
|
||||
return (IOException)super.getCause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to read the object from a stream.
|
||||
*
|
||||
* @throws InvalidObjectException
|
||||
* if the object is invalid or has a cause that is not
|
||||
* an {@code IOException}
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
s.defaultReadObject();
|
||||
Throwable cause = super.getCause();
|
||||
if (!(cause instanceof IOException))
|
||||
throw new InvalidObjectException("Cause must be an IOException");
|
||||
}
|
||||
}
|
49
jdkSrc/jdk8/java/nio/file/DirectoryNotEmptyException.java
Normal file
49
jdkSrc/jdk8/java/nio/file/DirectoryNotEmptyException.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file system operation fails because a
|
||||
* directory is not empty.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class DirectoryNotEmptyException
|
||||
extends FileSystemException
|
||||
{
|
||||
static final long serialVersionUID = 3056667871802779003L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param dir
|
||||
* a string identifying the directory or {@code null} if not known
|
||||
*/
|
||||
public DirectoryNotEmptyException(String dir) {
|
||||
super(dir);
|
||||
}
|
||||
}
|
159
jdkSrc/jdk8/java/nio/file/DirectoryStream.java
Normal file
159
jdkSrc/jdk8/java/nio/file/DirectoryStream.java
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An object to iterate over the entries in a directory. A directory stream
|
||||
* allows for the convenient use of the for-each construct to iterate over a
|
||||
* directory.
|
||||
*
|
||||
* <p> <b> While {@code DirectoryStream} extends {@code Iterable}, it is not a
|
||||
* general-purpose {@code Iterable} as it supports only a single {@code
|
||||
* Iterator}; invoking the {@link #iterator iterator} method to obtain a second
|
||||
* or subsequent iterator throws {@code IllegalStateException}. </b>
|
||||
*
|
||||
* <p> An important property of the directory stream's {@code Iterator} is that
|
||||
* its {@link Iterator#hasNext() hasNext} method is guaranteed to read-ahead by
|
||||
* at least one element. If {@code hasNext} method returns {@code true}, and is
|
||||
* followed by a call to the {@code next} method, it is guaranteed that the
|
||||
* {@code next} method will not throw an exception due to an I/O error, or
|
||||
* because the stream has been {@link #close closed}. The {@code Iterator} does
|
||||
* not support the {@link Iterator#remove remove} operation.
|
||||
*
|
||||
* <p> A {@code DirectoryStream} is opened upon creation and is closed by
|
||||
* invoking the {@code close} method. Closing a directory stream releases any
|
||||
* resources associated with the stream. Failure to close the stream may result
|
||||
* in a resource leak. The try-with-resources statement provides a useful
|
||||
* construct to ensure that the stream is closed:
|
||||
* <pre>
|
||||
* Path dir = ...
|
||||
* try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
|
||||
* for (Path entry: stream) {
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p> Once a directory stream is closed, then further access to the directory,
|
||||
* using the {@code Iterator}, behaves as if the end of stream has been reached.
|
||||
* Due to read-ahead, the {@code Iterator} may return one or more elements
|
||||
* after the directory stream has been closed. Once these buffered elements
|
||||
* have been read, then subsequent calls to the {@code hasNext} method returns
|
||||
* {@code false}, and subsequent calls to the {@code next} method will throw
|
||||
* {@code NoSuchElementException}.
|
||||
*
|
||||
* <p> A directory stream is not required to be <i>asynchronously closeable</i>.
|
||||
* If a thread is blocked on the directory stream's iterator reading from the
|
||||
* directory, and another thread invokes the {@code close} method, then the
|
||||
* second thread may block until the read operation is complete.
|
||||
*
|
||||
* <p> If an I/O error is encountered when accessing the directory then it
|
||||
* causes the {@code Iterator}'s {@code hasNext} or {@code next} methods to
|
||||
* throw {@link DirectoryIteratorException} with the {@link IOException} as the
|
||||
* cause. As stated above, the {@code hasNext} method is guaranteed to
|
||||
* read-ahead by at least one element. This means that if {@code hasNext} method
|
||||
* returns {@code true}, and is followed by a call to the {@code next} method,
|
||||
* then it is guaranteed that the {@code next} method will not fail with a
|
||||
* {@code DirectoryIteratorException}.
|
||||
*
|
||||
* <p> The elements returned by the iterator are in no specific order. Some file
|
||||
* systems maintain special links to the directory itself and the directory's
|
||||
* parent directory. Entries representing these links are not returned by the
|
||||
* iterator.
|
||||
*
|
||||
* <p> The iterator is <i>weakly consistent</i>. It is thread safe but does not
|
||||
* freeze the directory while iterating, so it may (or may not) reflect updates
|
||||
* to the directory that occur after the {@code DirectoryStream} is created.
|
||||
*
|
||||
* <p> <b>Usage Examples:</b>
|
||||
* Suppose we want a list of the source files in a directory. This example uses
|
||||
* both the for-each and try-with-resources constructs.
|
||||
* <pre>
|
||||
* List<Path> listSourceFiles(Path dir) throws IOException {
|
||||
* List<Path> result = new ArrayList<>();
|
||||
* try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) {
|
||||
* for (Path entry: stream) {
|
||||
* result.add(entry);
|
||||
* }
|
||||
* } catch (DirectoryIteratorException ex) {
|
||||
* // I/O error encounted during the iteration, the cause is an IOException
|
||||
* throw ex.getCause();
|
||||
* }
|
||||
* return result;
|
||||
* }
|
||||
* </pre>
|
||||
* @param <T> The type of element returned by the iterator
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see Files#newDirectoryStream(Path)
|
||||
*/
|
||||
|
||||
public interface DirectoryStream<T>
|
||||
extends Closeable, Iterable<T> {
|
||||
/**
|
||||
* An interface that is implemented by objects that decide if a directory
|
||||
* entry should be accepted or filtered. A {@code Filter} is passed as the
|
||||
* parameter to the {@link Files#newDirectoryStream(Path,DirectoryStream.Filter)}
|
||||
* method when opening a directory to iterate over the entries in the
|
||||
* directory.
|
||||
*
|
||||
* @param <T> the type of the directory entry
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public static interface Filter<T> {
|
||||
/**
|
||||
* Decides if the given directory entry should be accepted or filtered.
|
||||
*
|
||||
* @param entry
|
||||
* the directory entry to be tested
|
||||
*
|
||||
* @return {@code true} if the directory entry should be accepted
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
boolean accept(T entry) throws IOException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the iterator associated with this {@code DirectoryStream}.
|
||||
*
|
||||
* @return the iterator associated with this {@code DirectoryStream}
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if this directory stream is closed or the iterator has already
|
||||
* been returned
|
||||
*/
|
||||
@Override
|
||||
Iterator<T> iterator();
|
||||
}
|
63
jdkSrc/jdk8/java/nio/file/FileAlreadyExistsException.java
Normal file
63
jdkSrc/jdk8/java/nio/file/FileAlreadyExistsException.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when an attempt is made to create a file or
|
||||
* directory and a file of that name already exists.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class FileAlreadyExistsException
|
||||
extends FileSystemException
|
||||
{
|
||||
static final long serialVersionUID = 7579540934498831181L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
*/
|
||||
public FileAlreadyExistsException(String file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
* @param other
|
||||
* a string identifying the other file or {@code null} if not known
|
||||
* @param reason
|
||||
* a reason message with additional information or {@code null}
|
||||
*/
|
||||
public FileAlreadyExistsException(String file, String other, String reason) {
|
||||
super(file, other, reason);
|
||||
}
|
||||
}
|
221
jdkSrc/jdk8/java/nio/file/FileStore.java
Normal file
221
jdkSrc/jdk8/java/nio/file/FileStore.java
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Storage for files. A {@code FileStore} represents a storage pool, device,
|
||||
* partition, volume, concrete file system or other implementation specific means
|
||||
* of file storage. The {@code FileStore} for where a file is stored is obtained
|
||||
* by invoking the {@link Files#getFileStore getFileStore} method, or all file
|
||||
* stores can be enumerated by invoking the {@link FileSystem#getFileStores
|
||||
* getFileStores} method.
|
||||
*
|
||||
* <p> In addition to the methods defined by this class, a file store may support
|
||||
* one or more {@link FileStoreAttributeView FileStoreAttributeView} classes
|
||||
* that provide a read-only or updatable view of a set of file store attributes.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public abstract class FileStore {
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected FileStore() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this file store. The format of the name is highly
|
||||
* implementation specific. It will typically be the name of the storage
|
||||
* pool or volume.
|
||||
*
|
||||
* <p> The string returned by this method may differ from the string
|
||||
* returned by the {@link Object#toString() toString} method.
|
||||
*
|
||||
* @return the name of this file store
|
||||
*/
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* Returns the <em>type</em> of this file store. The format of the string
|
||||
* returned by this method is highly implementation specific. It may
|
||||
* indicate, for example, the format used or if the file store is local
|
||||
* or remote.
|
||||
*
|
||||
* @return a string representing the type of this file store
|
||||
*/
|
||||
public abstract String type();
|
||||
|
||||
/**
|
||||
* Tells whether this file store is read-only. A file store is read-only if
|
||||
* it does not support write operations or other changes to files. Any
|
||||
* attempt to create a file, open an existing file for writing etc. causes
|
||||
* an {@code IOException} to be thrown.
|
||||
*
|
||||
* @return {@code true} if, and only if, this file store is read-only
|
||||
*/
|
||||
public abstract boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Returns the size, in bytes, of the file store.
|
||||
*
|
||||
* @return the size of the file store, in bytes
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
public abstract long getTotalSpace() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available to this Java virtual machine on the
|
||||
* file store.
|
||||
*
|
||||
* <p> The returned number of available bytes is a hint, but not a
|
||||
* guarantee, that it is possible to use most or any of these bytes. The
|
||||
* number of usable bytes is most likely to be accurate immediately
|
||||
* after the space attributes are obtained. It is likely to be made inaccurate
|
||||
* by any external I/O operations including those made on the system outside
|
||||
* of this Java virtual machine.
|
||||
*
|
||||
* @return the number of bytes available
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
public abstract long getUsableSpace() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the number of unallocated bytes in the file store.
|
||||
*
|
||||
* <p> The returned number of unallocated bytes is a hint, but not a
|
||||
* guarantee, that it is possible to use most or any of these bytes. The
|
||||
* number of unallocated bytes is most likely to be accurate immediately
|
||||
* after the space attributes are obtained. It is likely to be
|
||||
* made inaccurate by any external I/O operations including those made on
|
||||
* the system outside of this virtual machine.
|
||||
*
|
||||
* @return the number of unallocated bytes
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
public abstract long getUnallocatedSpace() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not this file store supports the file attributes
|
||||
* identified by the given file attribute view.
|
||||
*
|
||||
* <p> Invoking this method to test if the file store supports {@link
|
||||
* BasicFileAttributeView} will always return {@code true}. In the case of
|
||||
* the default provider, this method cannot guarantee to give the correct
|
||||
* result when the file store is not a local storage device. The reasons for
|
||||
* this are implementation specific and therefore unspecified.
|
||||
*
|
||||
* @param type
|
||||
* the file attribute view type
|
||||
*
|
||||
* @return {@code true} if, and only if, the file attribute view is
|
||||
* supported
|
||||
*/
|
||||
public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type);
|
||||
|
||||
/**
|
||||
* Tells whether or not this file store supports the file attributes
|
||||
* identified by the given file attribute view.
|
||||
*
|
||||
* <p> Invoking this method to test if the file store supports {@link
|
||||
* BasicFileAttributeView}, identified by the name "{@code basic}" will
|
||||
* always return {@code true}. In the case of the default provider, this
|
||||
* method cannot guarantee to give the correct result when the file store is
|
||||
* not a local storage device. The reasons for this are implementation
|
||||
* specific and therefore unspecified.
|
||||
*
|
||||
* @param name
|
||||
* the {@link FileAttributeView#name name} of file attribute view
|
||||
*
|
||||
* @return {@code true} if, and only if, the file attribute view is
|
||||
* supported
|
||||
*/
|
||||
public abstract boolean supportsFileAttributeView(String name);
|
||||
|
||||
/**
|
||||
* Returns a {@code FileStoreAttributeView} of the given type.
|
||||
*
|
||||
* <p> This method is intended to be used where the file store attribute
|
||||
* view defines type-safe methods to read or update the file store attributes.
|
||||
* The {@code type} parameter is the type of the attribute view required and
|
||||
* the method returns an instance of that type if supported.
|
||||
*
|
||||
* @param <V>
|
||||
* The {@code FileStoreAttributeView} type
|
||||
* @param type
|
||||
* the {@code Class} object corresponding to the attribute view
|
||||
*
|
||||
* @return a file store attribute view of the specified type or
|
||||
* {@code null} if the attribute view is not available
|
||||
*/
|
||||
public abstract <V extends FileStoreAttributeView> V
|
||||
getFileStoreAttributeView(Class<V> type);
|
||||
|
||||
/**
|
||||
* Reads the value of a file store attribute.
|
||||
*
|
||||
* <p> The {@code attribute} parameter identifies the attribute to be read
|
||||
* and takes the form:
|
||||
* <blockquote>
|
||||
* <i>view-name</i><b>:</b><i>attribute-name</i>
|
||||
* </blockquote>
|
||||
* where the character {@code ':'} stands for itself.
|
||||
*
|
||||
* <p> <i>view-name</i> is the {@link FileStoreAttributeView#name name} of
|
||||
* a {@link FileStore AttributeView} that identifies a set of file attributes.
|
||||
* <i>attribute-name</i> is the name of the attribute.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to know if ZFS compression is enabled (assuming the "zfs"
|
||||
* view is supported):
|
||||
* <pre>
|
||||
* boolean compression = (Boolean)fs.getAttribute("zfs:compression");
|
||||
* </pre>
|
||||
*
|
||||
* @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 Object getAttribute(String attribute) throws IOException;
|
||||
}
|
468
jdkSrc/jdk8/java/nio/file/FileSystem.java
Normal file
468
jdkSrc/jdk8/java/nio/file/FileSystem.java
Normal file
@@ -0,0 +1,468 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.*;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.Set;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Provides an interface to a file system and is the factory for objects to
|
||||
* access files and other objects in the file system.
|
||||
*
|
||||
* <p> The default file system, obtained by invoking the {@link FileSystems#getDefault
|
||||
* FileSystems.getDefault} method, provides access to the file system that is
|
||||
* accessible to the Java virtual machine. The {@link FileSystems} class defines
|
||||
* methods to create file systems that provide access to other types of (custom)
|
||||
* file systems.
|
||||
*
|
||||
* <p> A file system is the factory for several types of objects:
|
||||
*
|
||||
* <ul>
|
||||
* <li><p> The {@link #getPath getPath} method converts a system dependent
|
||||
* <em>path string</em>, returning a {@link Path} object that may be used
|
||||
* to locate and access a file. </p></li>
|
||||
* <li><p> The {@link #getPathMatcher getPathMatcher} method is used
|
||||
* to create a {@link PathMatcher} that performs match operations on
|
||||
* paths. </p></li>
|
||||
* <li><p> The {@link #getFileStores getFileStores} method returns an iterator
|
||||
* over the underlying {@link FileStore file-stores}. </p></li>
|
||||
* <li><p> The {@link #getUserPrincipalLookupService getUserPrincipalLookupService}
|
||||
* method returns the {@link UserPrincipalLookupService} to lookup users or
|
||||
* groups by name. </p></li>
|
||||
* <li><p> The {@link #newWatchService newWatchService} method creates a
|
||||
* {@link WatchService} that may be used to watch objects for changes and
|
||||
* events. </p></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> File systems vary greatly. In some cases the file system is a single
|
||||
* hierarchy of files with one top-level root directory. In other cases it may
|
||||
* have several distinct file hierarchies, each with its own top-level root
|
||||
* directory. The {@link #getRootDirectories getRootDirectories} method may be
|
||||
* used to iterate over the root directories in the file system. A file system
|
||||
* is typically composed of one or more underlying {@link FileStore file-stores}
|
||||
* that provide the storage for the files. Theses file stores can also vary in
|
||||
* the features they support, and the file attributes or <em>meta-data</em> that
|
||||
* they associate with files.
|
||||
*
|
||||
* <p> A file system is open upon creation and can be closed by invoking its
|
||||
* {@link #close() close} method. Once closed, any further attempt to access
|
||||
* objects in the file system cause {@link ClosedFileSystemException} to be
|
||||
* thrown. File systems created by the default {@link FileSystemProvider provider}
|
||||
* cannot be closed.
|
||||
*
|
||||
* <p> A {@code FileSystem} can provide read-only or read-write access to the
|
||||
* file system. Whether or not a file system provides read-only access is
|
||||
* established when the {@code FileSystem} is created and can be tested by invoking
|
||||
* its {@link #isReadOnly() isReadOnly} method. Attempts to write to file stores
|
||||
* by means of an object associated with a read-only file system throws {@link
|
||||
* ReadOnlyFileSystemException}.
|
||||
*
|
||||
* <p> File systems are safe for use by multiple concurrent threads. The {@link
|
||||
* #close close} method may be invoked at any time to close a file system but
|
||||
* whether a file system is <i>asynchronously closeable</i> is provider specific
|
||||
* and therefore unspecified. In other words, if a thread is accessing an
|
||||
* object in a file system, and another thread invokes the {@code close} method
|
||||
* then it may require to block until the first operation is complete. Closing
|
||||
* a file system causes all open channels, watch services, and other {@link
|
||||
* Closeable closeable} objects associated with the file system to be closed.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public abstract class FileSystem
|
||||
implements Closeable
|
||||
{
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected FileSystem() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider that created this file system.
|
||||
*
|
||||
* @return The provider that created this file system.
|
||||
*/
|
||||
public abstract FileSystemProvider provider();
|
||||
|
||||
/**
|
||||
* Closes this file system.
|
||||
*
|
||||
* <p> After a file system is closed then all subsequent access to the file
|
||||
* system, either by methods defined by this class or on objects associated
|
||||
* with this file system, throw {@link ClosedFileSystemException}. If the
|
||||
* file system is already closed then invoking this method has no effect.
|
||||
*
|
||||
* <p> Closing a file system will close all open {@link
|
||||
* java.nio.channels.Channel channels}, {@link DirectoryStream directory-streams},
|
||||
* {@link WatchService watch-service}, and other closeable objects associated
|
||||
* with this file system. The {@link FileSystems#getDefault default} file
|
||||
* system cannot be closed.
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
* @throws UnsupportedOperationException
|
||||
* Thrown in the case of the default file system
|
||||
*/
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not this file system is open.
|
||||
*
|
||||
* <p> File systems created by the default provider are always open.
|
||||
*
|
||||
* @return {@code true} if, and only if, this file system is open
|
||||
*/
|
||||
public abstract boolean isOpen();
|
||||
|
||||
/**
|
||||
* Tells whether or not this file system allows only read-only access to
|
||||
* its file stores.
|
||||
*
|
||||
* @return {@code true} if, and only if, this file system provides
|
||||
* read-only access
|
||||
*/
|
||||
public abstract boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Returns the name separator, represented as a string.
|
||||
*
|
||||
* <p> The name separator is used to separate names in a path string. An
|
||||
* implementation may support multiple name separators in which case this
|
||||
* method returns an implementation specific <em>default</em> name separator.
|
||||
* This separator is used when creating path strings by invoking the {@link
|
||||
* Path#toString() toString()} method.
|
||||
*
|
||||
* <p> In the case of the default provider, this method returns the same
|
||||
* separator as {@link java.io.File#separator}.
|
||||
*
|
||||
* @return The name separator
|
||||
*/
|
||||
public abstract String getSeparator();
|
||||
|
||||
/**
|
||||
* Returns an object to iterate over the paths of the root directories.
|
||||
*
|
||||
* <p> A file system provides access to a file store that may be composed
|
||||
* of a number of distinct file hierarchies, each with its own top-level
|
||||
* root directory. Unless denied by the security manager, each element in
|
||||
* the returned iterator corresponds to the root directory of a distinct
|
||||
* file hierarchy. The order of the elements is not defined. The file
|
||||
* hierarchies may change during the lifetime of the Java virtual machine.
|
||||
* For example, in some implementations, the insertion of removable media
|
||||
* may result in the creation of a new file hierarchy with its own
|
||||
* top-level directory.
|
||||
*
|
||||
* <p> When a security manager is installed, it is invoked to check access
|
||||
* to the each root directory. If denied, the root directory is not returned
|
||||
* by the iterator. In the case of the default provider, the {@link
|
||||
* SecurityManager#checkRead(String)} method is invoked to check read access
|
||||
* to each root directory. It is system dependent if the permission checks
|
||||
* are done when the iterator is obtained or during iteration.
|
||||
*
|
||||
* @return An object to iterate over the root directories
|
||||
*/
|
||||
public abstract Iterable<Path> getRootDirectories();
|
||||
|
||||
/**
|
||||
* Returns an object to iterate over the underlying file stores.
|
||||
*
|
||||
* <p> The elements of the returned iterator are the {@link
|
||||
* FileStore FileStores} for this file system. The order of the elements is
|
||||
* not defined and the file stores may change during the lifetime of the
|
||||
* Java virtual machine. When an I/O error occurs, perhaps because a file
|
||||
* store is not accessible, then it is not returned by the iterator.
|
||||
*
|
||||
* <p> In the case of the default provider, and a security manager is
|
||||
* installed, the security manager is invoked to check {@link
|
||||
* RuntimePermission}<tt>("getFileStoreAttributes")</tt>. If denied, then
|
||||
* no file stores are returned by the iterator. In addition, the security
|
||||
* manager's {@link SecurityManager#checkRead(String)} method is invoked to
|
||||
* check read access to the file store's <em>top-most</em> directory. If
|
||||
* denied, the file store is not returned by the iterator. It is system
|
||||
* dependent if the permission checks are done when the iterator is obtained
|
||||
* or during iteration.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to print the space usage for all file stores:
|
||||
* <pre>
|
||||
* for (FileStore store: FileSystems.getDefault().getFileStores()) {
|
||||
* long total = store.getTotalSpace() / 1024;
|
||||
* long used = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024;
|
||||
* long avail = store.getUsableSpace() / 1024;
|
||||
* System.out.format("%-20s %12d %12d %12d%n", store, total, used, avail);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @return An object to iterate over the backing file stores
|
||||
*/
|
||||
public abstract Iterable<FileStore> getFileStores();
|
||||
|
||||
/**
|
||||
* Returns the set of the {@link FileAttributeView#name names} of the file
|
||||
* attribute views supported by this {@code FileSystem}.
|
||||
*
|
||||
* <p> The {@link BasicFileAttributeView} is required to be supported and
|
||||
* therefore the set contains at least one element, "basic".
|
||||
*
|
||||
* <p> The {@link FileStore#supportsFileAttributeView(String)
|
||||
* supportsFileAttributeView(String)} method may be used to test if an
|
||||
* underlying {@link FileStore} supports the file attributes identified by a
|
||||
* file attribute view.
|
||||
*
|
||||
* @return An unmodifiable set of the names of the supported file attribute
|
||||
* views
|
||||
*/
|
||||
public abstract Set<String> supportedFileAttributeViews();
|
||||
|
||||
/**
|
||||
* Converts a path string, or a sequence of strings that when joined form
|
||||
* a path string, to a {@code Path}. If {@code more} does not specify any
|
||||
* elements then the value of the {@code first} parameter is the path string
|
||||
* to convert. If {@code more} specifies one or more elements then each
|
||||
* non-empty string, including {@code first}, is considered to be a sequence
|
||||
* of name elements (see {@link Path}) and is joined to form a path string.
|
||||
* The details as to how the Strings are joined is provider specific but
|
||||
* typically they will be joined using the {@link #getSeparator
|
||||
* name-separator} as the separator. For example, if the name separator is
|
||||
* "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the
|
||||
* path string {@code "/foo/bar/gus"} is converted to a {@code Path}.
|
||||
* A {@code Path} representing an empty path is returned if {@code first}
|
||||
* is the empty string and {@code more} does not contain any non-empty
|
||||
* strings.
|
||||
*
|
||||
* <p> The parsing and conversion to a path object is inherently
|
||||
* implementation dependent. In the simplest case, the path string is rejected,
|
||||
* and {@link InvalidPathException} thrown, if the path string contains
|
||||
* characters that cannot be converted to characters that are <em>legal</em>
|
||||
* to the file store. For example, on UNIX systems, the NUL (\u0000)
|
||||
* character is not allowed to be present in a path. An implementation may
|
||||
* choose to reject path strings that contain names that are longer than those
|
||||
* allowed by any file store, and where an implementation supports a complex
|
||||
* path syntax, it may choose to reject path strings that are <em>badly
|
||||
* formed</em>.
|
||||
*
|
||||
* <p> In the case of the default provider, path strings are parsed based
|
||||
* on the definition of paths at the platform or virtual file system level.
|
||||
* For example, an operating system may not allow specific characters to be
|
||||
* present in a file name, but a specific underlying file store may impose
|
||||
* different or additional restrictions on the set of legal
|
||||
* characters.
|
||||
*
|
||||
* <p> This method throws {@link InvalidPathException} when the path string
|
||||
* cannot be converted to a path. Where possible, and where applicable,
|
||||
* the exception is created with an {@link InvalidPathException#getIndex
|
||||
* index} value indicating the first position in the {@code path} parameter
|
||||
* that caused the path string to be rejected.
|
||||
*
|
||||
* @param first
|
||||
* the path string or initial part of the path string
|
||||
* @param more
|
||||
* additional strings to be joined to form the path string
|
||||
*
|
||||
* @return the resulting {@code Path}
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* If the path string cannot be converted
|
||||
*/
|
||||
public abstract Path getPath(String first, String... more);
|
||||
|
||||
/**
|
||||
* Returns a {@code PathMatcher} that performs match operations on the
|
||||
* {@code String} representation of {@link Path} objects by interpreting a
|
||||
* given pattern.
|
||||
*
|
||||
* The {@code syntaxAndPattern} parameter identifies the syntax and the
|
||||
* pattern and takes the form:
|
||||
* <blockquote><pre>
|
||||
* <i>syntax</i><b>:</b><i>pattern</i>
|
||||
* </pre></blockquote>
|
||||
* where {@code ':'} stands for itself.
|
||||
*
|
||||
* <p> A {@code FileSystem} implementation supports the "{@code glob}" and
|
||||
* "{@code regex}" syntaxes, and may support others. The value of the syntax
|
||||
* component is compared without regard to case.
|
||||
*
|
||||
* <p> When the syntax is "{@code glob}" then the {@code String}
|
||||
* representation of the path is matched using a limited pattern language
|
||||
* that resembles regular expressions but with a simpler syntax. For example:
|
||||
*
|
||||
* <blockquote>
|
||||
* <table border="0" summary="Pattern Language">
|
||||
* <tr>
|
||||
* <td>{@code *.java}</td>
|
||||
* <td>Matches a path that represents a file name ending in {@code .java}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code *.*}</td>
|
||||
* <td>Matches file names containing a dot</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code *.{java,class}}</td>
|
||||
* <td>Matches file names ending with {@code .java} or {@code .class}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code foo.?}</td>
|
||||
* <td>Matches file names starting with {@code foo.} and a single
|
||||
* character extension</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><tt>/home/*/*</tt>
|
||||
* <td>Matches <tt>/home/gus/data</tt> on UNIX platforms</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><tt>/home/**</tt>
|
||||
* <td>Matches <tt>/home/gus</tt> and
|
||||
* <tt>/home/gus/data</tt> on UNIX platforms</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><tt>C:\\*</tt>
|
||||
* <td>Matches <tt>C:\foo</tt> and <tt>C:\bar</tt> on the Windows
|
||||
* platform (note that the backslash is escaped; as a string literal in the
|
||||
* Java Language the pattern would be <tt>"C:\\\\*"</tt>) </td>
|
||||
* </tr>
|
||||
*
|
||||
* </table>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> The following rules are used to interpret glob patterns:
|
||||
*
|
||||
* <ul>
|
||||
* <li><p> The {@code *} character matches zero or more {@link Character
|
||||
* characters} of a {@link Path#getName(int) name} component without
|
||||
* crossing directory boundaries. </p></li>
|
||||
*
|
||||
* <li><p> The {@code **} characters matches zero or more {@link Character
|
||||
* characters} crossing directory boundaries. </p></li>
|
||||
*
|
||||
* <li><p> The {@code ?} character matches exactly one character of a
|
||||
* name component.</p></li>
|
||||
*
|
||||
* <li><p> The backslash character ({@code \}) is used to escape characters
|
||||
* that would otherwise be interpreted as special characters. The expression
|
||||
* {@code \\} matches a single backslash and "\{" matches a left brace
|
||||
* for example. </p></li>
|
||||
*
|
||||
* <li><p> The {@code [ ]} characters are a <i>bracket expression</i> that
|
||||
* match a single character of a name component out of a set of characters.
|
||||
* For example, {@code [abc]} matches {@code "a"}, {@code "b"}, or {@code "c"}.
|
||||
* The hyphen ({@code -}) may be used to specify a range so {@code [a-z]}
|
||||
* specifies a range that matches from {@code "a"} to {@code "z"} (inclusive).
|
||||
* These forms can be mixed so [abce-g] matches {@code "a"}, {@code "b"},
|
||||
* {@code "c"}, {@code "e"}, {@code "f"} or {@code "g"}. If the character
|
||||
* after the {@code [} is a {@code !} then it is used for negation so {@code
|
||||
* [!a-c]} matches any character except {@code "a"}, {@code "b"}, or {@code
|
||||
* "c"}.
|
||||
* <p> Within a bracket expression the {@code *}, {@code ?} and {@code \}
|
||||
* characters match themselves. The ({@code -}) character matches itself if
|
||||
* it is the first character within the brackets, or the first character
|
||||
* after the {@code !} if negating.</p></li>
|
||||
*
|
||||
* <li><p> The {@code { }} characters are a group of subpatterns, where
|
||||
* the group matches if any subpattern in the group matches. The {@code ","}
|
||||
* character is used to separate the subpatterns. Groups cannot be nested.
|
||||
* </p></li>
|
||||
*
|
||||
* <li><p> Leading period<tt>/</tt>dot characters in file name are
|
||||
* treated as regular characters in match operations. For example,
|
||||
* the {@code "*"} glob pattern matches file name {@code ".login"}.
|
||||
* The {@link Files#isHidden} method may be used to test whether a file
|
||||
* is considered hidden.
|
||||
* </p></li>
|
||||
*
|
||||
* <li><p> All other characters match themselves in an implementation
|
||||
* dependent manner. This includes characters representing any {@link
|
||||
* FileSystem#getSeparator name-separators}. </p></li>
|
||||
*
|
||||
* <li><p> The matching of {@link Path#getRoot root} components is highly
|
||||
* implementation-dependent and is not specified. </p></li>
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* <p> When the syntax is "{@code regex}" then the pattern component is a
|
||||
* regular expression as defined by the {@link java.util.regex.Pattern}
|
||||
* class.
|
||||
*
|
||||
* <p> For both the glob and regex syntaxes, the matching details, such as
|
||||
* whether the matching is case sensitive, are implementation-dependent
|
||||
* and therefore not specified.
|
||||
*
|
||||
* @param syntaxAndPattern
|
||||
* The syntax and pattern
|
||||
*
|
||||
* @return A path matcher that may be used to match paths against the pattern
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the parameter does not take the form: {@code syntax:pattern}
|
||||
* @throws java.util.regex.PatternSyntaxException
|
||||
* If the pattern is invalid
|
||||
* @throws UnsupportedOperationException
|
||||
* If the pattern syntax is not known to the implementation
|
||||
*
|
||||
* @see Files#newDirectoryStream(Path,String)
|
||||
*/
|
||||
public abstract PathMatcher getPathMatcher(String syntaxAndPattern);
|
||||
|
||||
/**
|
||||
* Returns the {@code UserPrincipalLookupService} for this file system
|
||||
* <i>(optional operation)</i>. The resulting lookup service may be used to
|
||||
* lookup user or group names.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to make "joe" the owner of a file:
|
||||
* <pre>
|
||||
* UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
|
||||
* Files.setOwner(path, lookupService.lookupPrincipalByName("joe"));
|
||||
* </pre>
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If this {@code FileSystem} does not does have a lookup service
|
||||
*
|
||||
* @return The {@code UserPrincipalLookupService} for this file system
|
||||
*/
|
||||
public abstract UserPrincipalLookupService getUserPrincipalLookupService();
|
||||
|
||||
/**
|
||||
* Constructs a new {@link WatchService} <i>(optional operation)</i>.
|
||||
*
|
||||
* <p> This method constructs a new watch service that may be used to watch
|
||||
* registered objects for changes and events.
|
||||
*
|
||||
* @return a new watch service
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If this {@code FileSystem} does not support watching file system
|
||||
* objects for changes and events. This exception is not thrown
|
||||
* by {@code FileSystems} created by the default provider.
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract WatchService newWatchService() throws IOException;
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Runtime exception thrown when an attempt is made to create a file system that
|
||||
* already exists.
|
||||
*/
|
||||
|
||||
public class FileSystemAlreadyExistsException
|
||||
extends RuntimeException
|
||||
{
|
||||
static final long serialVersionUID = -5438419127181131148L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public FileSystemAlreadyExistsException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public FileSystemAlreadyExistsException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
125
jdkSrc/jdk8/java/nio/file/FileSystemException.java
Normal file
125
jdkSrc/jdk8/java/nio/file/FileSystemException.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Thrown when a file system operation fails on one or two files. This class is
|
||||
* the general class for file system exceptions.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class FileSystemException
|
||||
extends IOException
|
||||
{
|
||||
static final long serialVersionUID = -3055425747967319812L;
|
||||
|
||||
private final String file;
|
||||
private final String other;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class. This constructor should be used
|
||||
* when an operation involving one file fails and there isn't any additional
|
||||
* information to explain the reason.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known.
|
||||
*/
|
||||
public FileSystemException(String file) {
|
||||
super((String)null);
|
||||
this.file = file;
|
||||
this.other = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class. This constructor should be used
|
||||
* when an operation involving two files fails, or there is additional
|
||||
* information to explain the reason.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known.
|
||||
* @param other
|
||||
* a string identifying the other file or {@code null} if there
|
||||
* isn't another file or if not known
|
||||
* @param reason
|
||||
* a reason message with additional information or {@code null}
|
||||
*/
|
||||
public FileSystemException(String file, String other, String reason) {
|
||||
super(reason);
|
||||
this.file = file;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file used to create this exception.
|
||||
*
|
||||
* @return the file (can be {@code null})
|
||||
*/
|
||||
public String getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the other file used to create this exception.
|
||||
*
|
||||
* @return the other file (can be {@code null})
|
||||
*/
|
||||
public String getOtherFile() {
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string explaining why the file system operation failed.
|
||||
*
|
||||
* @return the string explaining why the file system operation failed
|
||||
*/
|
||||
public String getReason() {
|
||||
return super.getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message string.
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
if (file == null && other == null)
|
||||
return getReason();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (file != null)
|
||||
sb.append(file);
|
||||
if (other != null) {
|
||||
sb.append(" -> ");
|
||||
sb.append(other);
|
||||
}
|
||||
if (getReason() != null) {
|
||||
sb.append(": ");
|
||||
sb.append(getReason());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
50
jdkSrc/jdk8/java/nio/file/FileSystemLoopException.java
Normal file
50
jdkSrc/jdk8/java/nio/file/FileSystemLoopException.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file system loop, or cycle, is encountered.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see Files#walkFileTree
|
||||
*/
|
||||
|
||||
public class FileSystemLoopException
|
||||
extends FileSystemException
|
||||
{
|
||||
private static final long serialVersionUID = 4843039591949217617L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file causing the cycle or {@code null} if
|
||||
* not known
|
||||
*/
|
||||
public FileSystemLoopException(String file) {
|
||||
super(file);
|
||||
}
|
||||
}
|
52
jdkSrc/jdk8/java/nio/file/FileSystemNotFoundException.java
Normal file
52
jdkSrc/jdk8/java/nio/file/FileSystemNotFoundException.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Runtime exception thrown when a file system cannot be found.
|
||||
*/
|
||||
|
||||
public class FileSystemNotFoundException
|
||||
extends RuntimeException
|
||||
{
|
||||
static final long serialVersionUID = 7999581764446402397L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public FileSystemNotFoundException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public FileSystemNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
409
jdkSrc/jdk8/java/nio/file/FileSystems.java
Normal file
409
jdkSrc/jdk8/java/nio/file/FileSystems.java
Normal file
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.net.URI;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* Factory methods for file systems. This class defines the {@link #getDefault
|
||||
* getDefault} method to get the default file system and factory methods to
|
||||
* construct other types of file systems.
|
||||
*
|
||||
* <p> The first invocation of any of the methods defined by this class causes
|
||||
* the default {@link FileSystemProvider provider} to be loaded. The default
|
||||
* provider, identified by the URI scheme "file", creates the {@link FileSystem}
|
||||
* that provides access to the file systems accessible to the Java virtual
|
||||
* machine. If the process of loading or initializing the default provider fails
|
||||
* then an unspecified error is thrown.
|
||||
*
|
||||
* <p> The first invocation of the {@link FileSystemProvider#installedProviders
|
||||
* installedProviders} method, by way of invoking any of the {@code
|
||||
* newFileSystem} methods defined by this class, locates and loads all
|
||||
* installed file system providers. Installed providers are loaded using the
|
||||
* service-provider loading facility defined by the {@link ServiceLoader} class.
|
||||
* Installed providers are loaded using the system class loader. If the
|
||||
* system class loader cannot be found then the extension class loader is used;
|
||||
* if there is no extension class loader then the bootstrap class loader is used.
|
||||
* Providers are typically installed by placing them in a JAR file on the
|
||||
* application class path or in the extension directory, the JAR file contains a
|
||||
* provider-configuration file named {@code java.nio.file.spi.FileSystemProvider}
|
||||
* in the resource directory {@code META-INF/services}, and the file lists one or
|
||||
* more fully-qualified names of concrete subclass of {@link FileSystemProvider}
|
||||
* that have a zero argument constructor.
|
||||
* The ordering that installed providers are located is implementation specific.
|
||||
* If a provider is instantiated and its {@link FileSystemProvider#getScheme()
|
||||
* getScheme} returns the same URI scheme of a provider that was previously
|
||||
* instantiated then the most recently instantiated duplicate is discarded. URI
|
||||
* schemes are compared without regard to case. During construction a provider
|
||||
* may safely access files associated with the default provider but care needs
|
||||
* to be taken to avoid circular loading of other installed providers. If
|
||||
* circular loading of installed providers is detected then an unspecified error
|
||||
* is thrown.
|
||||
*
|
||||
* <p> This class also defines factory methods that allow a {@link ClassLoader}
|
||||
* to be specified when locating a provider. As with installed providers, the
|
||||
* provider classes are identified by placing the provider configuration file
|
||||
* in the resource directory {@code META-INF/services}.
|
||||
*
|
||||
* <p> If a thread initiates the loading of the installed file system providers
|
||||
* and another thread invokes a method that also attempts to load the providers
|
||||
* then the method will block until the loading completes.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public final class FileSystems {
|
||||
private FileSystems() {
|
||||
}
|
||||
|
||||
// lazy initialization of default file system
|
||||
private static class DefaultFileSystemHolder {
|
||||
static final FileSystem defaultFileSystem = defaultFileSystem();
|
||||
|
||||
// returns default file system
|
||||
private static FileSystem defaultFileSystem() {
|
||||
// load default provider
|
||||
FileSystemProvider provider = AccessController
|
||||
.doPrivileged(new PrivilegedAction<FileSystemProvider>() {
|
||||
public FileSystemProvider run() {
|
||||
return getDefaultProvider();
|
||||
}
|
||||
});
|
||||
|
||||
// return file system
|
||||
return provider.getFileSystem(URI.create("file:///"));
|
||||
}
|
||||
|
||||
// returns default provider
|
||||
private static FileSystemProvider getDefaultProvider() {
|
||||
FileSystemProvider provider = sun.nio.fs.DefaultFileSystemProvider.create();
|
||||
|
||||
// if the property java.nio.file.spi.DefaultFileSystemProvider is
|
||||
// set then its value is the name of the default provider (or a list)
|
||||
String propValue = System
|
||||
.getProperty("java.nio.file.spi.DefaultFileSystemProvider");
|
||||
if (propValue != null) {
|
||||
for (String cn: propValue.split(",")) {
|
||||
try {
|
||||
Class<?> c = Class
|
||||
.forName(cn, true, ClassLoader.getSystemClassLoader());
|
||||
Constructor<?> ctor = c
|
||||
.getDeclaredConstructor(FileSystemProvider.class);
|
||||
provider = (FileSystemProvider)ctor.newInstance(provider);
|
||||
|
||||
// must be "file"
|
||||
if (!provider.getScheme().equals("file"))
|
||||
throw new Error("Default provider must use scheme 'file'");
|
||||
|
||||
} catch (Exception x) {
|
||||
throw new Error(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default {@code FileSystem}. The default file system creates
|
||||
* objects that provide access to the file systems accessible to the Java
|
||||
* virtual machine. The <em>working directory</em> of the file system is
|
||||
* the current user directory, named by the system property {@code user.dir}.
|
||||
* This allows for interoperability with the {@link java.io.File java.io.File}
|
||||
* class.
|
||||
*
|
||||
* <p> The first invocation of any of the methods defined by this class
|
||||
* locates the default {@link FileSystemProvider provider} object. Where the
|
||||
* system property {@code java.nio.file.spi.DefaultFileSystemProvider} is
|
||||
* not defined then the default provider is a system-default provider that
|
||||
* is invoked to create the default file system.
|
||||
*
|
||||
* <p> If the system property {@code java.nio.file.spi.DefaultFileSystemProvider}
|
||||
* is defined then it is taken to be a list of one or more fully-qualified
|
||||
* names of concrete provider classes identified by the URI scheme
|
||||
* {@code "file"}. Where the property is a list of more than one name then
|
||||
* the names are separated by a comma. Each class is loaded, using the system
|
||||
* class loader, and instantiated by invoking a one argument constructor
|
||||
* whose formal parameter type is {@code FileSystemProvider}. The providers
|
||||
* are loaded and instantiated in the order they are listed in the property.
|
||||
* If this process fails or a provider's scheme is not equal to {@code "file"}
|
||||
* then an unspecified error is thrown. URI schemes are normally compared
|
||||
* without regard to case but for the default provider, the scheme is
|
||||
* required to be {@code "file"}. The first provider class is instantiated
|
||||
* by invoking it with a reference to the system-default provider.
|
||||
* The second provider class is instantiated by invoking it with a reference
|
||||
* to the first provider instance. The third provider class is instantiated
|
||||
* by invoking it with a reference to the second instance, and so on. The
|
||||
* last provider to be instantiated becomes the default provider; its {@code
|
||||
* getFileSystem} method is invoked with the URI {@code "file:///"} to
|
||||
* get a reference to the default file system.
|
||||
*
|
||||
* <p> Subsequent invocations of this method return the file system that was
|
||||
* returned by the first invocation.
|
||||
*
|
||||
* @return the default file system
|
||||
*/
|
||||
public static FileSystem getDefault() {
|
||||
return DefaultFileSystemHolder.defaultFileSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to an existing {@code FileSystem}.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers to locate the provider that is identified by the URI
|
||||
* {@link URI#getScheme scheme} of the given URI. URI schemes are compared
|
||||
* without regard to case. The exact form of the URI is highly provider
|
||||
* dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
|
||||
* getFileSystem} method is invoked to obtain a reference to the {@code
|
||||
* FileSystem}.
|
||||
*
|
||||
* <p> Once a file system created by this provider is {@link FileSystem#close
|
||||
* closed} it is provider-dependent if this method returns a reference to
|
||||
* the closed file system or throws {@link FileSystemNotFoundException}.
|
||||
* If the provider allows a new file system to be created with the same URI
|
||||
* as a file system it previously created then this method throws the
|
||||
* exception if invoked after the file system is closed (and before a new
|
||||
* instance is created by the {@link #newFileSystem newFileSystem} method).
|
||||
*
|
||||
* <p> If a security manager is installed then a provider implementation
|
||||
* may require to check a permission before returning a reference to an
|
||||
* existing file system. In the case of the {@link FileSystems#getDefault
|
||||
* default} file system, no permission check is required.
|
||||
*
|
||||
* @param uri the URI to locate the file system
|
||||
*
|
||||
* @return the reference to the file system
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the pre-conditions for the {@code uri} parameter are not met
|
||||
* @throws FileSystemNotFoundException
|
||||
* if the file system, identified by the URI, does not exist
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting the URI scheme is not installed
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission
|
||||
*/
|
||||
public static FileSystem getFileSystem(URI uri) {
|
||||
String scheme = uri.getScheme();
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
if (scheme.equalsIgnoreCase(provider.getScheme())) {
|
||||
return provider.getFileSystem(uri);
|
||||
}
|
||||
}
|
||||
throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new file system that is identified by a {@link URI}
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers to locate the provider that is identified by the URI
|
||||
* {@link URI#getScheme scheme} of the given URI. URI schemes are compared
|
||||
* without regard to case. The exact form of the URI is highly provider
|
||||
* dependent. If found, the provider's {@link FileSystemProvider#newFileSystem(URI,Map)
|
||||
* newFileSystem(URI,Map)} method is invoked to construct the new file system.
|
||||
*
|
||||
* <p> Once a file system is {@link FileSystem#close closed} it is
|
||||
* provider-dependent if the provider allows a new file system to be created
|
||||
* with the same URI as a file system it previously created.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose there is a provider identified by the scheme {@code "memory"}
|
||||
* installed:
|
||||
* <pre>
|
||||
* Map<String,String> env = new HashMap<>();
|
||||
* env.put("capacity", "16G");
|
||||
* env.put("blockSize", "4k");
|
||||
* FileSystem fs = FileSystems.newFileSystem(URI.create("memory:///?name=logfs"), env);
|
||||
* </pre>
|
||||
*
|
||||
* @param uri
|
||||
* the URI identifying the file system
|
||||
* @param env
|
||||
* a map of provider specific properties to configure the file system;
|
||||
* may be empty
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the pre-conditions for the {@code uri} parameter are not met,
|
||||
* or the {@code env} parameter does not contain properties required
|
||||
* by the provider, or a property value is invalid
|
||||
* @throws FileSystemAlreadyExistsException
|
||||
* if the file system has already been created
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting the URI scheme is not installed
|
||||
* @throws IOException
|
||||
* if an I/O error occurs creating the file system
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission required by the file system provider implementation
|
||||
*/
|
||||
public static FileSystem newFileSystem(URI uri, Map<String,?> env)
|
||||
throws IOException
|
||||
{
|
||||
return newFileSystem(uri, env, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new file system that is identified by a {@link URI}
|
||||
*
|
||||
* <p> This method first attempts to locate an installed provider in exactly
|
||||
* the same manner as the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)}
|
||||
* method. If none of the installed providers support the URI scheme then an
|
||||
* attempt is made to locate the provider using the given class loader. If a
|
||||
* provider supporting the URI scheme is located then its {@link
|
||||
* FileSystemProvider#newFileSystem(URI,Map) newFileSystem(URI,Map)} is
|
||||
* invoked to construct the new file system.
|
||||
*
|
||||
* @param uri
|
||||
* the URI identifying the file system
|
||||
* @param env
|
||||
* a map of provider specific properties to configure the file system;
|
||||
* may be empty
|
||||
* @param loader
|
||||
* the class loader to locate the provider or {@code null} to only
|
||||
* attempt to locate an installed provider
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the pre-conditions for the {@code uri} parameter are not met,
|
||||
* or the {@code env} parameter does not contain properties required
|
||||
* by the provider, or a property value is invalid
|
||||
* @throws FileSystemAlreadyExistsException
|
||||
* if the URI scheme identifies an installed provider and the file
|
||||
* system has already been created
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting the URI scheme is not found
|
||||
* @throws ServiceConfigurationError
|
||||
* when an error occurs while loading a service provider
|
||||
* @throws IOException
|
||||
* an I/O error occurs creating the file system
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission required by the file system provider implementation
|
||||
*/
|
||||
public static FileSystem newFileSystem(URI uri, Map<String,?> env, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
String scheme = uri.getScheme();
|
||||
|
||||
// check installed providers
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
if (scheme.equalsIgnoreCase(provider.getScheme())) {
|
||||
return provider.newFileSystem(uri, env);
|
||||
}
|
||||
}
|
||||
|
||||
// if not found, use service-provider loading facility
|
||||
if (loader != null) {
|
||||
ServiceLoader<FileSystemProvider> sl = ServiceLoader
|
||||
.load(FileSystemProvider.class, loader);
|
||||
for (FileSystemProvider provider: sl) {
|
||||
if (scheme.equalsIgnoreCase(provider.getScheme())) {
|
||||
return provider.newFileSystem(uri, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FileSystem} to access the contents of a file as a
|
||||
* file system.
|
||||
*
|
||||
* <p> This method makes use of specialized providers that create pseudo file
|
||||
* systems where the contents of one or more files is treated as a file
|
||||
* system.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers. It invokes, in turn, each provider's {@link
|
||||
* FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} method
|
||||
* with an empty map. If a provider returns a file system then the iteration
|
||||
* terminates and the file system is returned. If none of the installed
|
||||
* providers return a {@code FileSystem} then an attempt is made to locate
|
||||
* the provider using the given class loader. If a provider returns a file
|
||||
* system then the lookup terminates and the file system is returned.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file
|
||||
* @param loader
|
||||
* the class loader to locate the provider or {@code null} to only
|
||||
* attempt to locate an installed provider
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting this file type cannot be located
|
||||
* @throws ServiceConfigurationError
|
||||
* when an error occurs while loading a service provider
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission
|
||||
*/
|
||||
public static FileSystem newFileSystem(Path path,
|
||||
ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
if (path == null)
|
||||
throw new NullPointerException();
|
||||
Map<String,?> env = Collections.emptyMap();
|
||||
|
||||
// check installed providers
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
try {
|
||||
return provider.newFileSystem(path, env);
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
}
|
||||
}
|
||||
|
||||
// if not found, use service-provider loading facility
|
||||
if (loader != null) {
|
||||
ServiceLoader<FileSystemProvider> sl = ServiceLoader
|
||||
.load(FileSystemProvider.class, loader);
|
||||
for (FileSystemProvider provider: sl) {
|
||||
try {
|
||||
return provider.newFileSystem(path, env);
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProviderNotFoundException("Provider not found");
|
||||
}
|
||||
}
|
124
jdkSrc/jdk8/java/nio/file/FileTreeIterator.java
Normal file
124
jdkSrc/jdk8/java/nio/file/FileTreeIterator.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.nio.file.FileTreeWalker.Event;
|
||||
|
||||
/**
|
||||
* An {@code Iterator to iterate over the nodes of a file tree.
|
||||
*
|
||||
* <pre>{@code
|
||||
* try (FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options)) {
|
||||
* while (iterator.hasNext()) {
|
||||
* Event ev = iterator.next();
|
||||
* Path path = ev.file();
|
||||
* BasicFileAttributes attrs = ev.attributes();
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
|
||||
class FileTreeIterator implements Iterator<Event>, Closeable {
|
||||
private final FileTreeWalker walker;
|
||||
private Event next;
|
||||
|
||||
/**
|
||||
* Creates a new iterator to walk the file tree starting at the given file.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code maxDepth} is negative
|
||||
* @throws IOException
|
||||
* if an I/O errors occurs opening the starting file
|
||||
* @throws SecurityException
|
||||
* if the security manager denies access to the starting file
|
||||
* @throws NullPointerException
|
||||
* if {@code start} or {@code options} is {@ocde null} or
|
||||
* the options array contains a {@code null} element
|
||||
*/
|
||||
FileTreeIterator(Path start, int maxDepth, FileVisitOption... options)
|
||||
throws IOException
|
||||
{
|
||||
this.walker = new FileTreeWalker(Arrays.asList(options), maxDepth);
|
||||
this.next = walker.walk(start);
|
||||
assert next.type() == FileTreeWalker.EventType.ENTRY ||
|
||||
next.type() == FileTreeWalker.EventType.START_DIRECTORY;
|
||||
|
||||
// IOException if there a problem accessing the starting file
|
||||
IOException ioe = next.ioeException();
|
||||
if (ioe != null)
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
private void fetchNextIfNeeded() {
|
||||
if (next == null) {
|
||||
FileTreeWalker.Event ev = walker.next();
|
||||
while (ev != null) {
|
||||
IOException ioe = ev.ioeException();
|
||||
if (ioe != null)
|
||||
throw new UncheckedIOException(ioe);
|
||||
|
||||
// END_DIRECTORY events are ignored
|
||||
if (ev.type() != FileTreeWalker.EventType.END_DIRECTORY) {
|
||||
next = ev;
|
||||
return;
|
||||
}
|
||||
ev = walker.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (!walker.isOpen())
|
||||
throw new IllegalStateException();
|
||||
fetchNextIfNeeded();
|
||||
return next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event next() {
|
||||
if (!walker.isOpen())
|
||||
throw new IllegalStateException();
|
||||
fetchNextIfNeeded();
|
||||
if (next == null)
|
||||
throw new NoSuchElementException();
|
||||
Event result = next;
|
||||
next = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
walker.close();
|
||||
}
|
||||
}
|
425
jdkSrc/jdk8/java/nio/file/FileTreeWalker.java
Normal file
425
jdkSrc/jdk8/java/nio/file/FileTreeWalker.java
Normal file
@@ -0,0 +1,425 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import sun.nio.fs.BasicFileAttributesHolder;
|
||||
|
||||
/**
|
||||
* Walks a file tree, generating a sequence of events corresponding to the files
|
||||
* in the tree.
|
||||
*
|
||||
* <pre>{@code
|
||||
* Path top = ...
|
||||
* Set<FileVisitOption> options = ...
|
||||
* int maxDepth = ...
|
||||
*
|
||||
* try (FileTreeWalker walker = new FileTreeWalker(options, maxDepth)) {
|
||||
* FileTreeWalker.Event ev = walker.walk(top);
|
||||
* do {
|
||||
* process(ev);
|
||||
* ev = walker.next();
|
||||
* } while (ev != null);
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* @see Files#walkFileTree
|
||||
*/
|
||||
|
||||
class FileTreeWalker implements Closeable {
|
||||
private final boolean followLinks;
|
||||
private final LinkOption[] linkOptions;
|
||||
private final int maxDepth;
|
||||
private final ArrayDeque<DirectoryNode> stack = new ArrayDeque<>();
|
||||
private boolean closed;
|
||||
|
||||
/**
|
||||
* The element on the walking stack corresponding to a directory node.
|
||||
*/
|
||||
private static class DirectoryNode {
|
||||
private final Path dir;
|
||||
private final Object key;
|
||||
private final DirectoryStream<Path> stream;
|
||||
private final Iterator<Path> iterator;
|
||||
private boolean skipped;
|
||||
|
||||
DirectoryNode(Path dir, Object key, DirectoryStream<Path> stream) {
|
||||
this.dir = dir;
|
||||
this.key = key;
|
||||
this.stream = stream;
|
||||
this.iterator = stream.iterator();
|
||||
}
|
||||
|
||||
Path directory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
Object key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
DirectoryStream<Path> stream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
Iterator<Path> iterator() {
|
||||
return iterator;
|
||||
}
|
||||
|
||||
void skip() {
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
boolean skipped() {
|
||||
return skipped;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The event types.
|
||||
*/
|
||||
static enum EventType {
|
||||
/**
|
||||
* Start of a directory
|
||||
*/
|
||||
START_DIRECTORY,
|
||||
/**
|
||||
* End of a directory
|
||||
*/
|
||||
END_DIRECTORY,
|
||||
/**
|
||||
* An entry in a directory
|
||||
*/
|
||||
ENTRY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Events returned by the {@link #walk} and {@link #next} methods.
|
||||
*/
|
||||
static class Event {
|
||||
private final EventType type;
|
||||
private final Path file;
|
||||
private final BasicFileAttributes attrs;
|
||||
private final IOException ioe;
|
||||
|
||||
private Event(EventType type, Path file, BasicFileAttributes attrs, IOException ioe) {
|
||||
this.type = type;
|
||||
this.file = file;
|
||||
this.attrs = attrs;
|
||||
this.ioe = ioe;
|
||||
}
|
||||
|
||||
Event(EventType type, Path file, BasicFileAttributes attrs) {
|
||||
this(type, file, attrs, null);
|
||||
}
|
||||
|
||||
Event(EventType type, Path file, IOException ioe) {
|
||||
this(type, file, null, ioe);
|
||||
}
|
||||
|
||||
EventType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
Path file() {
|
||||
return file;
|
||||
}
|
||||
|
||||
BasicFileAttributes attributes() {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
IOException ioeException() {
|
||||
return ioe;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code FileTreeWalker}.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code maxDepth} is negative
|
||||
* @throws ClassCastException
|
||||
* if (@code options} contains an element that is not a
|
||||
* {@code FileVisitOption}
|
||||
* @throws NullPointerException
|
||||
* if {@code options} is {@ocde null} or the options
|
||||
* array contains a {@code null} element
|
||||
*/
|
||||
FileTreeWalker(Collection<FileVisitOption> options, int maxDepth) {
|
||||
boolean fl = false;
|
||||
for (FileVisitOption option: options) {
|
||||
// will throw NPE if options contains null
|
||||
switch (option) {
|
||||
case FOLLOW_LINKS : fl = true; break;
|
||||
default:
|
||||
throw new AssertionError("Should not get here");
|
||||
}
|
||||
}
|
||||
if (maxDepth < 0)
|
||||
throw new IllegalArgumentException("'maxDepth' is negative");
|
||||
|
||||
this.followLinks = fl;
|
||||
this.linkOptions = (fl) ? new LinkOption[0] :
|
||||
new LinkOption[] { LinkOption.NOFOLLOW_LINKS };
|
||||
this.maxDepth = maxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attributes of the given file, taking into account whether
|
||||
* the walk is following sym links is not. The {@code canUseCached}
|
||||
* argument determines whether this method can use cached attributes.
|
||||
*/
|
||||
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
|
||||
throws IOException
|
||||
{
|
||||
// if attributes are cached then use them if possible
|
||||
if (canUseCached &&
|
||||
(file instanceof BasicFileAttributesHolder) &&
|
||||
(System.getSecurityManager() == null))
|
||||
{
|
||||
BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
|
||||
if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
// attempt to get attributes of file. If fails and we are following
|
||||
// links then a link target might not exist so get attributes of link
|
||||
BasicFileAttributes attrs;
|
||||
try {
|
||||
attrs = Files.readAttributes(file, BasicFileAttributes.class, linkOptions);
|
||||
} catch (IOException ioe) {
|
||||
if (!followLinks)
|
||||
throw ioe;
|
||||
|
||||
// attempt to get attrmptes without following links
|
||||
attrs = Files.readAttributes(file,
|
||||
BasicFileAttributes.class,
|
||||
LinkOption.NOFOLLOW_LINKS);
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if walking into the given directory would result in a
|
||||
* file system loop/cycle.
|
||||
*/
|
||||
private boolean wouldLoop(Path dir, Object key) {
|
||||
// if this directory and ancestor has a file key then we compare
|
||||
// them; otherwise we use less efficient isSameFile test.
|
||||
for (DirectoryNode ancestor: stack) {
|
||||
Object ancestorKey = ancestor.key();
|
||||
if (key != null && ancestorKey != null) {
|
||||
if (key.equals(ancestorKey)) {
|
||||
// cycle detected
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (Files.isSameFile(dir, ancestor.directory())) {
|
||||
// cycle detected
|
||||
return true;
|
||||
}
|
||||
} catch (IOException | SecurityException x) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the given file, returning the {@code Event} corresponding to that
|
||||
* visit.
|
||||
*
|
||||
* The {@code ignoreSecurityException} parameter determines whether
|
||||
* any SecurityException should be ignored or not. If a SecurityException
|
||||
* is thrown, and is ignored, then this method returns {@code null} to
|
||||
* mean that there is no event corresponding to a visit to the file.
|
||||
*
|
||||
* The {@code canUseCached} parameter determines whether cached attributes
|
||||
* for the file can be used or not.
|
||||
*/
|
||||
private Event visit(Path entry, boolean ignoreSecurityException, boolean canUseCached) {
|
||||
// need the file attributes
|
||||
BasicFileAttributes attrs;
|
||||
try {
|
||||
attrs = getAttributes(entry, canUseCached);
|
||||
} catch (IOException ioe) {
|
||||
return new Event(EventType.ENTRY, entry, ioe);
|
||||
} catch (SecurityException se) {
|
||||
if (ignoreSecurityException)
|
||||
return null;
|
||||
throw se;
|
||||
}
|
||||
|
||||
// at maximum depth or file is not a directory
|
||||
int depth = stack.size();
|
||||
if (depth >= maxDepth || !attrs.isDirectory()) {
|
||||
return new Event(EventType.ENTRY, entry, attrs);
|
||||
}
|
||||
|
||||
// check for cycles when following links
|
||||
if (followLinks && wouldLoop(entry, attrs.fileKey())) {
|
||||
return new Event(EventType.ENTRY, entry,
|
||||
new FileSystemLoopException(entry.toString()));
|
||||
}
|
||||
|
||||
// file is a directory, attempt to open it
|
||||
DirectoryStream<Path> stream = null;
|
||||
try {
|
||||
stream = Files.newDirectoryStream(entry);
|
||||
} catch (IOException ioe) {
|
||||
return new Event(EventType.ENTRY, entry, ioe);
|
||||
} catch (SecurityException se) {
|
||||
if (ignoreSecurityException)
|
||||
return null;
|
||||
throw se;
|
||||
}
|
||||
|
||||
// push a directory node to the stack and return an event
|
||||
stack.push(new DirectoryNode(entry, attrs.fileKey(), stream));
|
||||
return new Event(EventType.START_DIRECTORY, entry, attrs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start walking from the given file.
|
||||
*/
|
||||
Event walk(Path file) {
|
||||
if (closed)
|
||||
throw new IllegalStateException("Closed");
|
||||
|
||||
Event ev = visit(file,
|
||||
false, // ignoreSecurityException
|
||||
false); // canUseCached
|
||||
assert ev != null;
|
||||
return ev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next Event or {@code null} if there are no more events or
|
||||
* the walker is closed.
|
||||
*/
|
||||
Event next() {
|
||||
DirectoryNode top = stack.peek();
|
||||
if (top == null)
|
||||
return null; // stack is empty, we are done
|
||||
|
||||
// continue iteration of the directory at the top of the stack
|
||||
Event ev;
|
||||
do {
|
||||
Path entry = null;
|
||||
IOException ioe = null;
|
||||
|
||||
// get next entry in the directory
|
||||
if (!top.skipped()) {
|
||||
Iterator<Path> iterator = top.iterator();
|
||||
try {
|
||||
if (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
}
|
||||
} catch (DirectoryIteratorException x) {
|
||||
ioe = x.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
// no next entry so close and pop directory, creating corresponding event
|
||||
if (entry == null) {
|
||||
try {
|
||||
top.stream().close();
|
||||
} catch (IOException e) {
|
||||
if (ioe != null) {
|
||||
ioe = e;
|
||||
} else {
|
||||
ioe.addSuppressed(e);
|
||||
}
|
||||
}
|
||||
stack.pop();
|
||||
return new Event(EventType.END_DIRECTORY, top.directory(), ioe);
|
||||
}
|
||||
|
||||
// visit the entry
|
||||
ev = visit(entry,
|
||||
true, // ignoreSecurityException
|
||||
true); // canUseCached
|
||||
|
||||
} while (ev == null);
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the directory node that is the current top of the stack so that
|
||||
* there are no more events for the directory (including no END_DIRECTORY)
|
||||
* event. This method is a no-op if the stack is empty or the walker is
|
||||
* closed.
|
||||
*/
|
||||
void pop() {
|
||||
if (!stack.isEmpty()) {
|
||||
DirectoryNode node = stack.pop();
|
||||
try {
|
||||
node.stream().close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the remaining entries in the directory at the top of the stack.
|
||||
* This method is a no-op if the stack is empty or the walker is closed.
|
||||
*/
|
||||
void skipRemainingSiblings() {
|
||||
if (!stack.isEmpty()) {
|
||||
stack.peek().skip();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the walker is open.
|
||||
*/
|
||||
boolean isOpen() {
|
||||
return !closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes/pops all directories on the stack.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
if (!closed) {
|
||||
while (!stack.isEmpty()) {
|
||||
pop();
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
}
|
41
jdkSrc/jdk8/java/nio/file/FileVisitOption.java
Normal file
41
jdkSrc/jdk8/java/nio/file/FileVisitOption.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines the file tree traversal options.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see Files#walkFileTree
|
||||
*/
|
||||
|
||||
public enum FileVisitOption {
|
||||
/**
|
||||
* Follow symbolic links.
|
||||
*/
|
||||
FOLLOW_LINKS;
|
||||
}
|
62
jdkSrc/jdk8/java/nio/file/FileVisitResult.java
Normal file
62
jdkSrc/jdk8/java/nio/file/FileVisitResult.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* The result type of a {@link FileVisitor FileVisitor}.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see Files#walkFileTree
|
||||
*/
|
||||
|
||||
public enum FileVisitResult {
|
||||
/**
|
||||
* Continue. When returned from a {@link FileVisitor#preVisitDirectory
|
||||
* preVisitDirectory} method then the entries in the directory should also
|
||||
* be visited.
|
||||
*/
|
||||
CONTINUE,
|
||||
/**
|
||||
* Terminate.
|
||||
*/
|
||||
TERMINATE,
|
||||
/**
|
||||
* Continue without visiting the entries in this directory. This result
|
||||
* is only meaningful when returned from the {@link
|
||||
* FileVisitor#preVisitDirectory preVisitDirectory} method; otherwise
|
||||
* this result type is the same as returning {@link #CONTINUE}.
|
||||
*/
|
||||
SKIP_SUBTREE,
|
||||
/**
|
||||
* Continue without visiting the <em>siblings</em> of this file or directory.
|
||||
* If returned from the {@link FileVisitor#preVisitDirectory
|
||||
* preVisitDirectory} method then the entries in the directory are also
|
||||
* skipped and the {@link FileVisitor#postVisitDirectory postVisitDirectory}
|
||||
* method is not invoked.
|
||||
*/
|
||||
SKIP_SIBLINGS;
|
||||
}
|
177
jdkSrc/jdk8/java/nio/file/FileVisitor.java
Normal file
177
jdkSrc/jdk8/java/nio/file/FileVisitor.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A visitor of files. An implementation of this interface is provided to the
|
||||
* {@link Files#walkFileTree Files.walkFileTree} methods to visit each file in
|
||||
* a file tree.
|
||||
*
|
||||
* <p> <b>Usage Examples:</b>
|
||||
* Suppose we want to delete a file tree. In that case, each directory should
|
||||
* be deleted after the entries in the directory are deleted.
|
||||
* <pre>
|
||||
* Path start = ...
|
||||
* Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
|
||||
* @Override
|
||||
* public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||
* throws IOException
|
||||
* {
|
||||
* Files.delete(file);
|
||||
* return FileVisitResult.CONTINUE;
|
||||
* }
|
||||
* @Override
|
||||
* public FileVisitResult postVisitDirectory(Path dir, IOException e)
|
||||
* throws IOException
|
||||
* {
|
||||
* if (e == null) {
|
||||
* Files.delete(dir);
|
||||
* return FileVisitResult.CONTINUE;
|
||||
* } else {
|
||||
* // directory iteration failed
|
||||
* throw e;
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
* </pre>
|
||||
* <p> Furthermore, suppose we want to copy a file tree to a target location.
|
||||
* In that case, symbolic links should be followed and the target directory
|
||||
* should be created before the entries in the directory are copied.
|
||||
* <pre>
|
||||
* final Path source = ...
|
||||
* final Path target = ...
|
||||
*
|
||||
* Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
|
||||
* new SimpleFileVisitor<Path>() {
|
||||
* @Override
|
||||
* public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
||||
* throws IOException
|
||||
* {
|
||||
* Path targetdir = target.resolve(source.relativize(dir));
|
||||
* try {
|
||||
* Files.copy(dir, targetdir);
|
||||
* } catch (FileAlreadyExistsException e) {
|
||||
* if (!Files.isDirectory(targetdir))
|
||||
* throw e;
|
||||
* }
|
||||
* return CONTINUE;
|
||||
* }
|
||||
* @Override
|
||||
* public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||
* throws IOException
|
||||
* {
|
||||
* Files.copy(file, target.resolve(source.relativize(file)));
|
||||
* return CONTINUE;
|
||||
* }
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface FileVisitor<T> {
|
||||
|
||||
/**
|
||||
* Invoked for a directory before entries in the directory are visited.
|
||||
*
|
||||
* <p> If this method returns {@link FileVisitResult#CONTINUE CONTINUE},
|
||||
* then entries in the directory are visited. If this method returns {@link
|
||||
* FileVisitResult#SKIP_SUBTREE SKIP_SUBTREE} or {@link
|
||||
* FileVisitResult#SKIP_SIBLINGS SKIP_SIBLINGS} then entries in the
|
||||
* directory (and any descendants) will not be visited.
|
||||
*
|
||||
* @param dir
|
||||
* a reference to the directory
|
||||
* @param attrs
|
||||
* the directory's basic attributes
|
||||
*
|
||||
* @return the visit result
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Invoked for a file in a directory.
|
||||
*
|
||||
* @param file
|
||||
* a reference to the file
|
||||
* @param attrs
|
||||
* the file's basic attributes
|
||||
*
|
||||
* @return the visit result
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
FileVisitResult visitFile(T file, BasicFileAttributes attrs)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Invoked for a file that could not be visited. This method is invoked
|
||||
* if the file's attributes could not be read, the file is a directory
|
||||
* that could not be opened, and other reasons.
|
||||
*
|
||||
* @param file
|
||||
* a reference to the file
|
||||
* @param exc
|
||||
* the I/O exception that prevented the file from being visited
|
||||
*
|
||||
* @return the visit result
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
FileVisitResult visitFileFailed(T file, IOException exc)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Invoked for a directory after entries in the directory, and all of their
|
||||
* descendants, have been visited. This method is also invoked when iteration
|
||||
* of the directory completes prematurely (by a {@link #visitFile visitFile}
|
||||
* method returning {@link FileVisitResult#SKIP_SIBLINGS SKIP_SIBLINGS},
|
||||
* or an I/O error when iterating over the directory).
|
||||
*
|
||||
* @param dir
|
||||
* a reference to the directory
|
||||
* @param exc
|
||||
* {@code null} if the iteration of the directory completes without
|
||||
* an error; otherwise the I/O exception that caused the iteration
|
||||
* of the directory to complete prematurely
|
||||
*
|
||||
* @return the visit result
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
FileVisitResult postVisitDirectory(T dir, IOException exc)
|
||||
throws IOException;
|
||||
}
|
3787
jdkSrc/jdk8/java/nio/file/Files.java
Normal file
3787
jdkSrc/jdk8/java/nio/file/Files.java
Normal file
File diff suppressed because it is too large
Load Diff
130
jdkSrc/jdk8/java/nio/file/InvalidPathException.java
Normal file
130
jdkSrc/jdk8/java/nio/file/InvalidPathException.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when path string cannot be converted into a
|
||||
* {@link Path} because the path string contains invalid characters, or
|
||||
* the path string is invalid for other file system specific reasons.
|
||||
*/
|
||||
|
||||
public class InvalidPathException
|
||||
extends IllegalArgumentException
|
||||
{
|
||||
static final long serialVersionUID = 4355821422286746137L;
|
||||
|
||||
private String input;
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* Constructs an instance from the given input string, reason, and error
|
||||
* index.
|
||||
*
|
||||
* @param input the input string
|
||||
* @param reason a string explaining why the input was rejected
|
||||
* @param index the index at which the error occurred,
|
||||
* or <tt>-1</tt> if the index is not known
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if either the input or reason strings are <tt>null</tt>
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the error index is less than <tt>-1</tt>
|
||||
*/
|
||||
public InvalidPathException(String input, String reason, int index) {
|
||||
super(reason);
|
||||
if ((input == null) || (reason == null))
|
||||
throw new NullPointerException();
|
||||
if (index < -1)
|
||||
throw new IllegalArgumentException();
|
||||
this.input = input;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance from the given input string and reason. The
|
||||
* resulting object will have an error index of <tt>-1</tt>.
|
||||
*
|
||||
* @param input the input string
|
||||
* @param reason a string explaining why the input was rejected
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* if either the input or reason strings are <tt>null</tt>
|
||||
*/
|
||||
public InvalidPathException(String input, String reason) {
|
||||
this(input, reason, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input string.
|
||||
*
|
||||
* @return the input string
|
||||
*/
|
||||
public String getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string explaining why the input string was rejected.
|
||||
*
|
||||
* @return the reason string
|
||||
*/
|
||||
public String getReason() {
|
||||
return super.getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an index into the input string of the position at which the
|
||||
* error occurred, or <tt>-1</tt> if this position is not known.
|
||||
*
|
||||
* @return the error index
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing the error. The resulting string
|
||||
* consists of the reason string followed by a colon character
|
||||
* (<tt>':'</tt>), a space, and the input string. If the error index is
|
||||
* defined then the string <tt>" at index "</tt> followed by the index, in
|
||||
* decimal, is inserted after the reason string and before the colon
|
||||
* character.
|
||||
*
|
||||
* @return a string describing the error
|
||||
*/
|
||||
public String getMessage() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getReason());
|
||||
if (index > -1) {
|
||||
sb.append(" at index ");
|
||||
sb.append(index);
|
||||
}
|
||||
sb.append(": ");
|
||||
sb.append(input);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
43
jdkSrc/jdk8/java/nio/file/LinkOption.java
Normal file
43
jdkSrc/jdk8/java/nio/file/LinkOption.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines the options as to how symbolic links are handled.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum LinkOption implements OpenOption, CopyOption {
|
||||
/**
|
||||
* Do not follow symbolic links.
|
||||
*
|
||||
* @see Files#getFileAttributeView(Path,Class,LinkOption[])
|
||||
* @see Files#copy
|
||||
* @see SecureDirectoryStream#newByteChannel
|
||||
*/
|
||||
NOFOLLOW_LINKS;
|
||||
}
|
107
jdkSrc/jdk8/java/nio/file/LinkPermission.java
Normal file
107
jdkSrc/jdk8/java/nio/file/LinkPermission.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
|
||||
/**
|
||||
* The {@code Permission} class for link creation operations.
|
||||
*
|
||||
* <p> The following table provides a summary description of what the permission
|
||||
* allows, and discusses the risks of granting code the permission.
|
||||
*
|
||||
* <table border=1 cellpadding=5
|
||||
* summary="Table shows permission target name, what the permission allows, and associated risks">
|
||||
* <tr>
|
||||
* <th>Permission Target Name</th>
|
||||
* <th>What the Permission Allows</th>
|
||||
* <th>Risks of Allowing this Permission</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>hard</td>
|
||||
* <td> Ability to add an existing file to a directory. This is sometimes
|
||||
* known as creating a link, or hard link. </td>
|
||||
* <td> Extreme care should be taken when granting this permission. It allows
|
||||
* linking to any file or directory in the file system thus allowing the
|
||||
* attacker access to all files. </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>symbolic</td>
|
||||
* <td> Ability to create symbolic links. </td>
|
||||
* <td> Extreme care should be taken when granting this permission. It allows
|
||||
* linking to any file or directory in the file system thus allowing the
|
||||
* attacker to access to all files. </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see Files#createLink
|
||||
* @see Files#createSymbolicLink
|
||||
*/
|
||||
public final class LinkPermission extends BasicPermission {
|
||||
static final long serialVersionUID = -1441492453772213220L;
|
||||
|
||||
private void checkName(String name) {
|
||||
if (!name.equals("hard") && !name.equals("symbolic")) {
|
||||
throw new IllegalArgumentException("name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code LinkPermission} with the specified name.
|
||||
*
|
||||
* @param name
|
||||
* the name of the permission. It must be "hard" or "symbolic".
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if name is empty or invalid
|
||||
*/
|
||||
public LinkPermission(String name) {
|
||||
super(name);
|
||||
checkName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code LinkPermission} with the specified name.
|
||||
*
|
||||
* @param name
|
||||
* the name of the permission; must be "hard" or "symbolic".
|
||||
* @param actions
|
||||
* the actions for the permission; must be the empty string or
|
||||
* {@code null}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if name is empty or invalid, or actions is a non-empty string
|
||||
*/
|
||||
public LinkPermission(String name, String actions) {
|
||||
super(name);
|
||||
checkName(name);
|
||||
if (actions != null && actions.length() > 0) {
|
||||
throw new IllegalArgumentException("actions: " + actions);
|
||||
}
|
||||
}
|
||||
}
|
63
jdkSrc/jdk8/java/nio/file/NoSuchFileException.java
Normal file
63
jdkSrc/jdk8/java/nio/file/NoSuchFileException.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when an attempt is made to access a file that does
|
||||
* not exist.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class NoSuchFileException
|
||||
extends FileSystemException
|
||||
{
|
||||
static final long serialVersionUID = -1390291775875351931L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known.
|
||||
*/
|
||||
public NoSuchFileException(String file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known.
|
||||
* @param other
|
||||
* a string identifying the other file or {@code null} if not known.
|
||||
* @param reason
|
||||
* a reason message with additional information or {@code null}
|
||||
*/
|
||||
public NoSuchFileException(String file, String other, String reason) {
|
||||
super(file, other, reason);
|
||||
}
|
||||
}
|
49
jdkSrc/jdk8/java/nio/file/NotDirectoryException.java
Normal file
49
jdkSrc/jdk8/java/nio/file/NotDirectoryException.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file system operation, intended for a
|
||||
* directory, fails because the file is not a directory.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class NotDirectoryException
|
||||
extends FileSystemException
|
||||
{
|
||||
private static final long serialVersionUID = -9011457427178200199L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
*/
|
||||
public NotDirectoryException(String file) {
|
||||
super(file);
|
||||
}
|
||||
}
|
63
jdkSrc/jdk8/java/nio/file/NotLinkException.java
Normal file
63
jdkSrc/jdk8/java/nio/file/NotLinkException.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a file system operation fails because a file
|
||||
* is not a symbolic link.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class NotLinkException
|
||||
extends FileSystemException
|
||||
{
|
||||
static final long serialVersionUID = -388655596416518021L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
*/
|
||||
public NotLinkException(String file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param file
|
||||
* a string identifying the file or {@code null} if not known
|
||||
* @param other
|
||||
* a string identifying the other file or {@code null} if not known
|
||||
* @param reason
|
||||
* a reason message with additional information or {@code null}
|
||||
*/
|
||||
public NotLinkException(String file, String other, String reason) {
|
||||
super(file, other, reason);
|
||||
}
|
||||
}
|
45
jdkSrc/jdk8/java/nio/file/OpenOption.java
Normal file
45
jdkSrc/jdk8/java/nio/file/OpenOption.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* An object that configures how to open or create a file.
|
||||
*
|
||||
* <p> Objects of this type are used by methods such as {@link
|
||||
* Files#newOutputStream(Path,OpenOption[]) newOutputStream}, {@link
|
||||
* Files#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.
|
||||
*
|
||||
* <p> The {@link StandardOpenOption} enumeration type defines the
|
||||
* <i>standard</i> options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface OpenOption {
|
||||
}
|
801
jdkSrc/jdk8/java/nio/file/Path.java
Normal file
801
jdkSrc/jdk8/java/nio/file/Path.java
Normal file
@@ -0,0 +1,801 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* An object that may be used to locate a file in a file system. It will
|
||||
* typically represent a system dependent file path.
|
||||
*
|
||||
* <p> A {@code Path} represents a path that is hierarchical and composed of a
|
||||
* sequence of directory and file name elements separated by a special separator
|
||||
* or delimiter. A <em>root component</em>, that identifies a file system
|
||||
* hierarchy, may also be present. The name element that is <em>farthest</em>
|
||||
* from the root of the directory hierarchy is the name of a file or directory.
|
||||
* The other name elements are directory names. A {@code Path} can represent a
|
||||
* root, a root and a sequence of names, or simply one or more name elements.
|
||||
* A {@code Path} is considered to be an <i>empty path</i> if it consists
|
||||
* solely of one name element that is empty. Accessing a file using an
|
||||
* <i>empty path</i> is equivalent to accessing the default directory of the
|
||||
* file system. {@code Path} defines the {@link #getFileName() getFileName},
|
||||
* {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath
|
||||
* subpath} methods to access the path components or a subsequence of its name
|
||||
* elements.
|
||||
*
|
||||
* <p> In addition to accessing the components of a path, a {@code Path} also
|
||||
* defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path)
|
||||
* resolveSibling} methods to combine paths. The {@link #relativize relativize}
|
||||
* method that can be used to construct a relative path between two paths.
|
||||
* Paths can be {@link #compareTo compared}, and tested against each other using
|
||||
* the {@link #startsWith startsWith} and {@link #endsWith endsWith} methods.
|
||||
*
|
||||
* <p> This interface extends {@link Watchable} interface so that a directory
|
||||
* located by a path can be {@link #register registered} with a {@link
|
||||
* WatchService} and entries in the directory watched. </p>
|
||||
*
|
||||
* <p> <b>WARNING:</b> This interface is only intended to be implemented by
|
||||
* those developing custom file system implementations. Methods may be added to
|
||||
* this interface in future releases. </p>
|
||||
*
|
||||
* <h2>Accessing Files</h2>
|
||||
* <p> Paths may be used with the {@link Files} class to operate on files,
|
||||
* directories, and other types of files. For example, suppose we want a {@link
|
||||
* java.io.BufferedReader} to read text from a file "{@code access.log}". The
|
||||
* file is located in a directory "{@code logs}" relative to the current working
|
||||
* directory and is UTF-8 encoded.
|
||||
* <pre>
|
||||
* Path path = FileSystems.getDefault().getPath("logs", "access.log");
|
||||
* BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
|
||||
* </pre>
|
||||
*
|
||||
* <a name="interop"></a><h2>Interoperability</h2>
|
||||
* <p> Paths associated with the default {@link
|
||||
* java.nio.file.spi.FileSystemProvider provider} are generally interoperable
|
||||
* with the {@link java.io.File java.io.File} class. Paths created by other
|
||||
* providers are unlikely to be interoperable with the abstract path names
|
||||
* represented by {@code java.io.File}. The {@link java.io.File#toPath toPath}
|
||||
* method may be used to obtain a {@code Path} from the abstract path name
|
||||
* represented by a {@code java.io.File} object. The resulting {@code Path} can
|
||||
* be used to operate on the same file as the {@code java.io.File} object. In
|
||||
* addition, the {@link #toFile toFile} method is useful to construct a {@code
|
||||
* File} from the {@code String} representation of a {@code Path}.
|
||||
*
|
||||
* <h2>Concurrency</h2>
|
||||
* <p> Implementations of this interface are immutable and safe for use by
|
||||
* multiple concurrent threads.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see Paths
|
||||
*/
|
||||
|
||||
public interface Path
|
||||
extends Comparable<Path>, Iterable<Path>, Watchable
|
||||
{
|
||||
/**
|
||||
* Returns the file system that created this object.
|
||||
*
|
||||
* @return the file system that created this object
|
||||
*/
|
||||
FileSystem getFileSystem();
|
||||
|
||||
/**
|
||||
* Tells whether or not this path is absolute.
|
||||
*
|
||||
* <p> An absolute path is complete in that it doesn't need to be combined
|
||||
* with other path information in order to locate a file.
|
||||
*
|
||||
* @return {@code true} if, and only if, this path is absolute
|
||||
*/
|
||||
boolean isAbsolute();
|
||||
|
||||
/**
|
||||
* Returns the root component of this path as a {@code Path} object,
|
||||
* or {@code null} if this path does not have a root component.
|
||||
*
|
||||
* @return a path representing the root component of this path,
|
||||
* or {@code null}
|
||||
*/
|
||||
Path getRoot();
|
||||
|
||||
/**
|
||||
* Returns the name of the file or directory denoted by this path as a
|
||||
* {@code Path} object. The file name is the <em>farthest</em> element from
|
||||
* the root in the directory hierarchy.
|
||||
*
|
||||
* @return a path representing the name of the file or directory, or
|
||||
* {@code null} if this path has zero elements
|
||||
*/
|
||||
Path getFileName();
|
||||
|
||||
/**
|
||||
* Returns the <em>parent path</em>, or {@code null} if this path does not
|
||||
* have a parent.
|
||||
*
|
||||
* <p> The parent of this path object consists of this path's root
|
||||
* component, if any, and each element in the path except for the
|
||||
* <em>farthest</em> from the root in the directory hierarchy. This method
|
||||
* does not access the file system; the path or its parent may not exist.
|
||||
* Furthermore, this method does not eliminate special names such as "."
|
||||
* and ".." that may be used in some implementations. On UNIX for example,
|
||||
* the parent of "{@code /a/b/c}" is "{@code /a/b}", and the parent of
|
||||
* {@code "x/y/.}" is "{@code x/y}". This method may be used with the {@link
|
||||
* #normalize normalize} method, to eliminate redundant names, for cases where
|
||||
* <em>shell-like</em> navigation is required.
|
||||
*
|
||||
* <p> If this path has one or more elements, and no root component, then
|
||||
* this method is equivalent to evaluating the expression:
|
||||
* <blockquote><pre>
|
||||
* subpath(0, getNameCount()-1);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @return a path representing the path's parent
|
||||
*/
|
||||
Path getParent();
|
||||
|
||||
/**
|
||||
* Returns the number of name elements in the path.
|
||||
*
|
||||
* @return the number of elements in the path, or {@code 0} if this path
|
||||
* only represents a root component
|
||||
*/
|
||||
int getNameCount();
|
||||
|
||||
/**
|
||||
* Returns a name element of this path as a {@code Path} object.
|
||||
*
|
||||
* <p> The {@code index} parameter is the index of the name element to return.
|
||||
* The element that is <em>closest</em> to the root in the directory hierarchy
|
||||
* has index {@code 0}. The element that is <em>farthest</em> from the root
|
||||
* has index {@link #getNameCount count}{@code -1}.
|
||||
*
|
||||
* @param index
|
||||
* the index of the element
|
||||
*
|
||||
* @return the name element
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code index} is negative, {@code index} is greater than or
|
||||
* equal to the number of elements, or this path has zero name
|
||||
* elements
|
||||
*/
|
||||
Path getName(int index);
|
||||
|
||||
/**
|
||||
* Returns a relative {@code Path} that is a subsequence of the name
|
||||
* elements of this path.
|
||||
*
|
||||
* <p> The {@code beginIndex} and {@code endIndex} parameters specify the
|
||||
* subsequence of name elements. The name that is <em>closest</em> to the root
|
||||
* in the directory hierarchy has index {@code 0}. The name that is
|
||||
* <em>farthest</em> from the root has index {@link #getNameCount
|
||||
* count}{@code -1}. The returned {@code Path} object has the name elements
|
||||
* that begin at {@code beginIndex} and extend to the element at index {@code
|
||||
* endIndex-1}.
|
||||
*
|
||||
* @param beginIndex
|
||||
* the index of the first element, inclusive
|
||||
* @param endIndex
|
||||
* the index of the last element, exclusive
|
||||
*
|
||||
* @return a new {@code Path} object that is a subsequence of the name
|
||||
* elements in this {@code Path}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code beginIndex} is negative, or greater than or equal to
|
||||
* the number of elements. If {@code endIndex} is less than or
|
||||
* equal to {@code beginIndex}, or larger than the number of elements.
|
||||
*/
|
||||
Path subpath(int beginIndex, int endIndex);
|
||||
|
||||
/**
|
||||
* Tests if this path starts with the given path.
|
||||
*
|
||||
* <p> This path <em>starts</em> with the given path if this path's root
|
||||
* component <em>starts</em> with the root component of the given path,
|
||||
* and this path starts with the same name elements as the given path.
|
||||
* If the given path has more name elements than this path then {@code false}
|
||||
* is returned.
|
||||
*
|
||||
* <p> Whether or not the root component of this path starts with the root
|
||||
* component of the given path is file system specific. If this path does
|
||||
* not have a root component and the given path has a root component then
|
||||
* this path does not start with the given path.
|
||||
*
|
||||
* <p> If the given path is associated with a different {@code FileSystem}
|
||||
* to this path then {@code false} is returned.
|
||||
*
|
||||
* @param other
|
||||
* the given path
|
||||
*
|
||||
* @return {@code true} if this path starts with the given path; otherwise
|
||||
* {@code false}
|
||||
*/
|
||||
boolean startsWith(Path other);
|
||||
|
||||
/**
|
||||
* Tests if this path starts with a {@code Path}, constructed by converting
|
||||
* the given path string, in exactly the manner specified by the {@link
|
||||
* #startsWith(Path) startsWith(Path)} method. On UNIX for example, the path
|
||||
* "{@code foo/bar}" starts with "{@code foo}" and "{@code foo/bar}". It
|
||||
* does not start with "{@code f}" or "{@code fo}".
|
||||
*
|
||||
* @param other
|
||||
* the given path string
|
||||
*
|
||||
* @return {@code true} if this path starts with the given path; otherwise
|
||||
* {@code false}
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* If the path string cannot be converted to a Path.
|
||||
*/
|
||||
boolean startsWith(String other);
|
||||
|
||||
/**
|
||||
* Tests if this path ends with the given path.
|
||||
*
|
||||
* <p> If the given path has <em>N</em> elements, and no root component,
|
||||
* and this path has <em>N</em> or more elements, then this path ends with
|
||||
* the given path if the last <em>N</em> elements of each path, starting at
|
||||
* the element farthest from the root, are equal.
|
||||
*
|
||||
* <p> If the given path has a root component then this path ends with the
|
||||
* given path if the root component of this path <em>ends with</em> the root
|
||||
* component of the given path, and the corresponding elements of both paths
|
||||
* are equal. Whether or not the root component of this path ends with the
|
||||
* root component of the given path is file system specific. If this path
|
||||
* does not have a root component and the given path has a root component
|
||||
* then this path does not end with the given path.
|
||||
*
|
||||
* <p> If the given path is associated with a different {@code FileSystem}
|
||||
* to this path then {@code false} is returned.
|
||||
*
|
||||
* @param other
|
||||
* the given path
|
||||
*
|
||||
* @return {@code true} if this path ends with the given path; otherwise
|
||||
* {@code false}
|
||||
*/
|
||||
boolean endsWith(Path other);
|
||||
|
||||
/**
|
||||
* Tests if this path ends with a {@code Path}, constructed by converting
|
||||
* the given path string, in exactly the manner specified by the {@link
|
||||
* #endsWith(Path) endsWith(Path)} method. On UNIX for example, the path
|
||||
* "{@code foo/bar}" ends with "{@code foo/bar}" and "{@code bar}". It does
|
||||
* not end with "{@code r}" or "{@code /bar}". Note that trailing separators
|
||||
* are not taken into account, and so invoking this method on the {@code
|
||||
* Path}"{@code foo/bar}" with the {@code String} "{@code bar/}" returns
|
||||
* {@code true}.
|
||||
*
|
||||
* @param other
|
||||
* the given path string
|
||||
*
|
||||
* @return {@code true} if this path ends with the given path; otherwise
|
||||
* {@code false}
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* If the path string cannot be converted to a Path.
|
||||
*/
|
||||
boolean endsWith(String other);
|
||||
|
||||
/**
|
||||
* Returns a path that is this path with redundant name elements eliminated.
|
||||
*
|
||||
* <p> The precise definition of this method is implementation dependent but
|
||||
* in general it derives from this path, a path that does not contain
|
||||
* <em>redundant</em> name elements. In many file systems, the "{@code .}"
|
||||
* and "{@code ..}" are special names used to indicate the current directory
|
||||
* and parent directory. In such file systems all occurrences of "{@code .}"
|
||||
* are considered redundant. If a "{@code ..}" is preceded by a
|
||||
* non-"{@code ..}" name then both names are considered redundant (the
|
||||
* process to identify such names is repeated until it is no longer
|
||||
* applicable).
|
||||
*
|
||||
* <p> This method does not access the file system; the path may not locate
|
||||
* a file that exists. Eliminating "{@code ..}" and a preceding name from a
|
||||
* path may result in the path that locates a different file than the original
|
||||
* path. This can arise when the preceding name is a symbolic link.
|
||||
*
|
||||
* @return the resulting path or this path if it does not contain
|
||||
* redundant name elements; an empty path is returned if this path
|
||||
* does have a root component and all name elements are redundant
|
||||
*
|
||||
* @see #getParent
|
||||
* @see #toRealPath
|
||||
*/
|
||||
Path normalize();
|
||||
|
||||
// -- resolution and relativization --
|
||||
|
||||
/**
|
||||
* Resolve the given path against this path.
|
||||
*
|
||||
* <p> If the {@code other} parameter is an {@link #isAbsolute() absolute}
|
||||
* path then this method trivially returns {@code other}. If {@code other}
|
||||
* is an <i>empty path</i> then this method trivially returns this path.
|
||||
* Otherwise this method considers this path to be a directory and resolves
|
||||
* the given path against this path. In the simplest case, the given path
|
||||
* does not have a {@link #getRoot root} component, in which case this method
|
||||
* <em>joins</em> the given path to this path and returns a resulting path
|
||||
* that {@link #endsWith ends} with the given path. Where the given path has
|
||||
* a root component then resolution is highly implementation dependent and
|
||||
* therefore unspecified.
|
||||
*
|
||||
* @param other
|
||||
* the path to resolve against this path
|
||||
*
|
||||
* @return the resulting path
|
||||
*
|
||||
* @see #relativize
|
||||
*/
|
||||
Path resolve(Path other);
|
||||
|
||||
/**
|
||||
* Converts a given path string to a {@code Path} and resolves it against
|
||||
* this {@code Path} in exactly the manner specified by the {@link
|
||||
* #resolve(Path) resolve} method. For example, suppose that the name
|
||||
* separator is "{@code /}" and a path represents "{@code foo/bar}", then
|
||||
* invoking this method with the path string "{@code gus}" will result in
|
||||
* the {@code Path} "{@code foo/bar/gus}".
|
||||
*
|
||||
* @param other
|
||||
* the path string to resolve against this path
|
||||
*
|
||||
* @return the resulting path
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* if the path string cannot be converted to a Path.
|
||||
*
|
||||
* @see FileSystem#getPath
|
||||
*/
|
||||
Path resolve(String other);
|
||||
|
||||
/**
|
||||
* Resolves the given path against this path's {@link #getParent parent}
|
||||
* path. This is useful where a file name needs to be <i>replaced</i> with
|
||||
* another file name. For example, suppose that the name separator is
|
||||
* "{@code /}" and a path represents "{@code dir1/dir2/foo}", then invoking
|
||||
* this method with the {@code Path} "{@code bar}" will result in the {@code
|
||||
* Path} "{@code dir1/dir2/bar}". If this path does not have a parent path,
|
||||
* or {@code other} is {@link #isAbsolute() absolute}, then this method
|
||||
* returns {@code other}. If {@code other} is an empty path then this method
|
||||
* returns this path's parent, or where this path doesn't have a parent, the
|
||||
* empty path.
|
||||
*
|
||||
* @param other
|
||||
* the path to resolve against this path's parent
|
||||
*
|
||||
* @return the resulting path
|
||||
*
|
||||
* @see #resolve(Path)
|
||||
*/
|
||||
Path resolveSibling(Path other);
|
||||
|
||||
/**
|
||||
* Converts a given path string to a {@code Path} and resolves it against
|
||||
* this path's {@link #getParent parent} path in exactly the manner
|
||||
* specified by the {@link #resolveSibling(Path) resolveSibling} method.
|
||||
*
|
||||
* @param other
|
||||
* the path string to resolve against this path's parent
|
||||
*
|
||||
* @return the resulting path
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* if the path string cannot be converted to a Path.
|
||||
*
|
||||
* @see FileSystem#getPath
|
||||
*/
|
||||
Path resolveSibling(String other);
|
||||
|
||||
/**
|
||||
* Constructs a relative path between this path and a given path.
|
||||
*
|
||||
* <p> Relativization is the inverse of {@link #resolve(Path) resolution}.
|
||||
* This method attempts to construct a {@link #isAbsolute relative} path
|
||||
* that when {@link #resolve(Path) resolved} against this path, yields a
|
||||
* path that locates the same file as the given path. For example, on UNIX,
|
||||
* if this path is {@code "/a/b"} and the given path is {@code "/a/b/c/d"}
|
||||
* then the resulting relative path would be {@code "c/d"}. Where this
|
||||
* path and the given path do not have a {@link #getRoot root} component,
|
||||
* then a relative path can be constructed. A relative path cannot be
|
||||
* constructed if only one of the paths have a root component. Where both
|
||||
* paths have a root component then it is implementation dependent if a
|
||||
* relative path can be constructed. If this path and the given path are
|
||||
* {@link #equals equal} then an <i>empty path</i> is returned.
|
||||
*
|
||||
* <p> For any two {@link #normalize normalized} paths <i>p</i> and
|
||||
* <i>q</i>, where <i>q</i> does not have a root component,
|
||||
* <blockquote>
|
||||
* <i>p</i><tt>.relativize(</tt><i>p</i><tt>.resolve(</tt><i>q</i><tt>)).equals(</tt><i>q</i><tt>)</tt>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> When symbolic links are supported, then whether the resulting path,
|
||||
* when resolved against this path, yields a path that can be used to locate
|
||||
* the {@link Files#isSameFile same} file as {@code other} is implementation
|
||||
* dependent. For example, if this path is {@code "/a/b"} and the given
|
||||
* path is {@code "/a/x"} then the resulting relative path may be {@code
|
||||
* "../x"}. If {@code "b"} is a symbolic link then is implementation
|
||||
* dependent if {@code "a/b/../x"} would locate the same file as {@code "/a/x"}.
|
||||
*
|
||||
* @param other
|
||||
* the path to relativize against this path
|
||||
*
|
||||
* @return the resulting relative path, or an empty path if both paths are
|
||||
* equal
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if {@code other} is not a {@code Path} that can be relativized
|
||||
* against this path
|
||||
*/
|
||||
Path relativize(Path other);
|
||||
|
||||
/**
|
||||
* Returns a URI to represent this path.
|
||||
*
|
||||
* <p> This method constructs an absolute {@link URI} with a {@link
|
||||
* URI#getScheme() scheme} equal to the URI scheme that identifies the
|
||||
* provider. The exact form of the scheme specific part is highly provider
|
||||
* dependent.
|
||||
*
|
||||
* <p> In the case of the default provider, the URI is hierarchical with
|
||||
* a {@link URI#getPath() path} component that is absolute. The query and
|
||||
* fragment components are undefined. Whether the authority component is
|
||||
* defined or not is implementation dependent. There is no guarantee that
|
||||
* the {@code URI} may be used to construct a {@link java.io.File java.io.File}.
|
||||
* In particular, if this path represents a Universal Naming Convention (UNC)
|
||||
* path, then the UNC server name may be encoded in the authority component
|
||||
* of the resulting URI. In the case of the default provider, and the file
|
||||
* exists, and it can be determined that the file is a directory, then the
|
||||
* resulting {@code URI} will end with a slash.
|
||||
*
|
||||
* <p> The default provider provides a similar <em>round-trip</em> guarantee
|
||||
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
|
||||
* is guaranteed that
|
||||
* <blockquote><tt>
|
||||
* {@link Paths#get(URI) Paths.get}(</tt><i>p</i><tt>.toUri()).equals(</tt><i>p</i>
|
||||
* <tt>.{@link #toAbsolutePath() toAbsolutePath}())</tt>
|
||||
* </blockquote>
|
||||
* so long as the original {@code Path}, the {@code URI}, and the new {@code
|
||||
* Path} are all created in (possibly different invocations of) the same
|
||||
* Java virtual machine. Whether other providers make any guarantees is
|
||||
* provider specific and therefore unspecified.
|
||||
*
|
||||
* <p> When a file system is constructed to access the contents of a file
|
||||
* as a file system then it is highly implementation specific if the returned
|
||||
* URI represents the given path in the file system or it represents a
|
||||
* <em>compound</em> URI that encodes the URI of the enclosing file system.
|
||||
* A format for compound URIs is not defined in this release; such a scheme
|
||||
* may be added in a future release.
|
||||
*
|
||||
* @return the URI representing this path
|
||||
*
|
||||
* @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
|
||||
* obtained
|
||||
*
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, and a security manager
|
||||
* is installed, the {@link #toAbsolutePath toAbsolutePath} method
|
||||
* throws a security exception.
|
||||
*/
|
||||
URI toUri();
|
||||
|
||||
/**
|
||||
* Returns a {@code Path} object representing the absolute path of this
|
||||
* path.
|
||||
*
|
||||
* <p> If this path is already {@link Path#isAbsolute absolute} then this
|
||||
* method simply returns this path. Otherwise, this method resolves the path
|
||||
* in an implementation dependent manner, typically by resolving the path
|
||||
* against a file system default directory. Depending on the implementation,
|
||||
* this method may throw an I/O error if the file system is not accessible.
|
||||
*
|
||||
* @return a {@code Path} object representing the absolute path
|
||||
*
|
||||
* @throws java.io.IOError
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* 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}
|
||||
*/
|
||||
Path toAbsolutePath();
|
||||
|
||||
/**
|
||||
* Returns the <em>real</em> path of an existing file.
|
||||
*
|
||||
* <p> The precise definition of this method is implementation dependent but
|
||||
* in general it derives from this path, an {@link #isAbsolute absolute}
|
||||
* path that locates the {@link Files#isSameFile same} file as this path, but
|
||||
* with name elements that represent the actual name of the directories
|
||||
* and the file. For example, where filename comparisons on a file system
|
||||
* are case insensitive then the name elements represent the names in their
|
||||
* actual case. Additionally, the resulting path has redundant name
|
||||
* elements removed.
|
||||
*
|
||||
* <p> If this path is relative then its absolute path is first obtained,
|
||||
* as if by invoking the {@link #toAbsolutePath toAbsolutePath} method.
|
||||
*
|
||||
* <p> The {@code options} array may be used to indicate how symbolic links
|
||||
* are handled. By default, symbolic links are resolved to their final
|
||||
* target. If the option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is
|
||||
* present then this method does not resolve symbolic links.
|
||||
*
|
||||
* Some implementations allow special names such as "{@code ..}" to refer to
|
||||
* the parent directory. When deriving the <em>real path</em>, and a
|
||||
* "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then
|
||||
* an implementation will typically cause both names to be removed. When
|
||||
* not resolving symbolic links and the preceding name is a symbolic link
|
||||
* then the names are only removed if it guaranteed that the resulting path
|
||||
* will locate the same file as this path.
|
||||
*
|
||||
* @param options
|
||||
* options indicating how symbolic links are handled
|
||||
*
|
||||
* @return an absolute path represent the <em>real</em> path of the file
|
||||
* located by this object
|
||||
*
|
||||
* @throws IOException
|
||||
* if the file does not exist or 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 is invoked to check read access to the file, and where
|
||||
* this path is not absolute, its {@link SecurityManager#checkPropertyAccess(String)
|
||||
* checkPropertyAccess} method is invoked to check access to the
|
||||
* system property {@code user.dir}
|
||||
*/
|
||||
Path toRealPath(LinkOption... options) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a {@link File} object representing this path. Where this {@code
|
||||
* Path} is associated with the default provider, then this method is
|
||||
* equivalent to returning a {@code File} object constructed with the
|
||||
* {@code String} representation of this path.
|
||||
*
|
||||
* <p> If this path was created by invoking the {@code File} {@link
|
||||
* File#toPath toPath} method then there is no guarantee that the {@code
|
||||
* File} object returned by this method is {@link #equals equal} to the
|
||||
* original {@code File}.
|
||||
*
|
||||
* @return a {@code File} object representing this path
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if this {@code Path} is not associated with the default provider
|
||||
*/
|
||||
File toFile();
|
||||
|
||||
// -- watchable --
|
||||
|
||||
/**
|
||||
* Registers the file located by this path with a watch service.
|
||||
*
|
||||
* <p> In this release, this path locates a directory that exists. The
|
||||
* directory is registered with the watch service so that entries in the
|
||||
* directory can be watched. The {@code events} parameter is the events to
|
||||
* register and may contain the following events:
|
||||
* <ul>
|
||||
* <li>{@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE} -
|
||||
* entry created or moved into the directory</li>
|
||||
* <li>{@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE} -
|
||||
* entry deleted or moved out of the directory</li>
|
||||
* <li>{@link StandardWatchEventKinds#ENTRY_MODIFY ENTRY_MODIFY} -
|
||||
* entry in directory was modified</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> The {@link WatchEvent#context context} for these events is the
|
||||
* relative path between the directory located by this path, and the path
|
||||
* that locates the directory entry that is created, deleted, or modified.
|
||||
*
|
||||
* <p> The set of events may include additional implementation specific
|
||||
* event that are not defined by the enum {@link StandardWatchEventKinds}
|
||||
*
|
||||
* <p> The {@code modifiers} parameter specifies <em>modifiers</em> that
|
||||
* qualify how the directory is registered. This release does not define any
|
||||
* <em>standard</em> modifiers. It may contain implementation specific
|
||||
* modifiers.
|
||||
*
|
||||
* <p> Where a file is registered with a watch service by means of a symbolic
|
||||
* link then it is implementation specific if the watch continues to depend
|
||||
* on the existence of the symbolic link after it is registered.
|
||||
*
|
||||
* @param watcher
|
||||
* the watch service to which this object is to be registered
|
||||
* @param events
|
||||
* the events for which this object should be registered
|
||||
* @param modifiers
|
||||
* the modifiers, if any, that modify how the object is registered
|
||||
*
|
||||
* @return a key representing the registration of this object with the
|
||||
* given watch service
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if unsupported events or modifiers are specified
|
||||
* @throws IllegalArgumentException
|
||||
* if an invalid combination of events or modifiers is specified
|
||||
* @throws ClosedWatchServiceException
|
||||
* if the watch service is closed
|
||||
* @throws NotDirectoryException
|
||||
* if the file is registered to watch the entries in a directory
|
||||
* and the file is not a directory <i>(optional specific exception)</i>
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
WatchKey register(WatchService watcher,
|
||||
WatchEvent.Kind<?>[] events,
|
||||
WatchEvent.Modifier... modifiers)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Registers the file located by this path with a watch service.
|
||||
*
|
||||
* <p> An invocation of this method behaves in exactly the same way as the
|
||||
* invocation
|
||||
* <pre>
|
||||
* watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);
|
||||
* </pre>
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we wish to register a directory for entry create, delete, and modify
|
||||
* events:
|
||||
* <pre>
|
||||
* Path dir = ...
|
||||
* WatchService watcher = ...
|
||||
*
|
||||
* WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
|
||||
* </pre>
|
||||
* @param watcher
|
||||
* The watch service to which this object is to be registered
|
||||
* @param events
|
||||
* The events for which this object should be registered
|
||||
*
|
||||
* @return A key representing the registration of this object with the
|
||||
* given watch service
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If unsupported events are specified
|
||||
* @throws IllegalArgumentException
|
||||
* If an invalid combination of events is specified
|
||||
* @throws ClosedWatchServiceException
|
||||
* If the watch service is closed
|
||||
* @throws NotDirectoryException
|
||||
* If the file is registered to watch the entries in a directory
|
||||
* and the file is not a directory <i>(optional specific exception)</i>
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
WatchKey register(WatchService watcher,
|
||||
WatchEvent.Kind<?>... events)
|
||||
throws IOException;
|
||||
|
||||
// -- Iterable --
|
||||
|
||||
/**
|
||||
* Returns an iterator over the name elements of this path.
|
||||
*
|
||||
* <p> The first element returned by the iterator represents the name
|
||||
* element that is closest to the root in the directory hierarchy, the
|
||||
* second element is the next closest, and so on. The last element returned
|
||||
* is the name of the file or directory denoted by this path. The {@link
|
||||
* #getRoot root} component, if present, is not returned by the iterator.
|
||||
*
|
||||
* @return an iterator over the name elements of this path.
|
||||
*/
|
||||
@Override
|
||||
Iterator<Path> iterator();
|
||||
|
||||
// -- compareTo/equals/hashCode --
|
||||
|
||||
/**
|
||||
* Compares two abstract paths lexicographically. The ordering defined by
|
||||
* this method is provider specific, and in the case of the default
|
||||
* provider, platform specific. This method does not access the file system
|
||||
* and neither file is required to exist.
|
||||
*
|
||||
* <p> This method may not be used to compare paths that are associated
|
||||
* with different file system providers.
|
||||
*
|
||||
* @param other the path compared to this path.
|
||||
*
|
||||
* @return zero if the argument is {@link #equals equal} to this path, a
|
||||
* value less than zero if this path is lexicographically less than
|
||||
* the argument, or a value greater than zero if this path is
|
||||
* lexicographically greater than the argument
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* if the paths are associated with different providers
|
||||
*/
|
||||
@Override
|
||||
int compareTo(Path other);
|
||||
|
||||
/**
|
||||
* Tests this path for equality with the given object.
|
||||
*
|
||||
* <p> If the given object is not a Path, or is a Path associated with a
|
||||
* different {@code FileSystem}, then this method returns {@code false}.
|
||||
*
|
||||
* <p> Whether or not two path are equal depends on the file system
|
||||
* implementation. In some cases the paths are compared without regard
|
||||
* to case, and others are case sensitive. This method does not access the
|
||||
* file system and the file is not required to exist. Where required, the
|
||||
* {@link Files#isSameFile isSameFile} method may be used to check if two
|
||||
* paths locate the same file.
|
||||
*
|
||||
* <p> This method satisfies the general contract of the {@link
|
||||
* java.lang.Object#equals(Object) Object.equals} method. </p>
|
||||
*
|
||||
* @param other
|
||||
* the object to which this object is to be compared
|
||||
*
|
||||
* @return {@code true} if, and only if, the given object is a {@code Path}
|
||||
* that is identical to this {@code Path}
|
||||
*/
|
||||
boolean equals(Object other);
|
||||
|
||||
/**
|
||||
* Computes a hash code for this path.
|
||||
*
|
||||
* <p> The hash code is based upon the components of the path, and
|
||||
* satisfies the general contract of the {@link Object#hashCode
|
||||
* Object.hashCode} method.
|
||||
*
|
||||
* @return the hash-code value for this path
|
||||
*/
|
||||
int hashCode();
|
||||
|
||||
/**
|
||||
* Returns the string representation of this path.
|
||||
*
|
||||
* <p> If this path was created by converting a path string using the
|
||||
* {@link FileSystem#getPath getPath} method then the path string returned
|
||||
* by this method may differ from the original String used to create the path.
|
||||
*
|
||||
* <p> The returned path string uses the default name {@link
|
||||
* FileSystem#getSeparator separator} to separate names in the path.
|
||||
*
|
||||
* @return the string representation of this path
|
||||
*/
|
||||
String toString();
|
||||
}
|
49
jdkSrc/jdk8/java/nio/file/PathMatcher.java
Normal file
49
jdkSrc/jdk8/java/nio/file/PathMatcher.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* An interface that is implemented by objects that perform match operations on
|
||||
* paths.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see FileSystem#getPathMatcher
|
||||
* @see Files#newDirectoryStream(Path,String)
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PathMatcher {
|
||||
/**
|
||||
* Tells if given path matches this matcher's pattern.
|
||||
*
|
||||
* @param path
|
||||
* the path to match
|
||||
*
|
||||
* @return {@code true} if, and only if, the path matches this
|
||||
* matcher's pattern
|
||||
*/
|
||||
boolean matches(Path path);
|
||||
}
|
149
jdkSrc/jdk8/java/nio/file/Paths.java
Normal file
149
jdkSrc/jdk8/java/nio/file/Paths.java
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* This class consists exclusively of static methods that return a {@link Path}
|
||||
* by converting a path string or {@link URI}.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public final class Paths {
|
||||
private Paths() { }
|
||||
|
||||
/**
|
||||
* Converts a path string, or a sequence of strings that when joined form
|
||||
* a path string, to a {@code Path}. If {@code more} does not specify any
|
||||
* elements then the value of the {@code first} parameter is the path string
|
||||
* to convert. If {@code more} specifies one or more elements then each
|
||||
* non-empty string, including {@code first}, is considered to be a sequence
|
||||
* of name elements (see {@link Path}) and is joined to form a path string.
|
||||
* The details as to how the Strings are joined is provider specific but
|
||||
* typically they will be joined using the {@link FileSystem#getSeparator
|
||||
* name-separator} as the separator. For example, if the name separator is
|
||||
* "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the
|
||||
* path string {@code "/foo/bar/gus"} is converted to a {@code Path}.
|
||||
* A {@code Path} representing an empty path is returned if {@code first}
|
||||
* is the empty string and {@code more} does not contain any non-empty
|
||||
* strings.
|
||||
*
|
||||
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath
|
||||
* getPath} method of the {@link FileSystems#getDefault default} {@link
|
||||
* FileSystem}.
|
||||
*
|
||||
* <p> Note that while this method is very convenient, using it will imply
|
||||
* an assumed reference to the default {@code FileSystem} and limit the
|
||||
* utility of the calling code. Hence it should not be used in library code
|
||||
* intended for flexible reuse. A more flexible alternative is to use an
|
||||
* existing {@code Path} instance as an anchor, such as:
|
||||
* <pre>
|
||||
* Path dir = ...
|
||||
* Path path = dir.resolve("file");
|
||||
* </pre>
|
||||
*
|
||||
* @param first
|
||||
* the path string or initial part of the path string
|
||||
* @param more
|
||||
* additional strings to be joined to form the path string
|
||||
*
|
||||
* @return the resulting {@code Path}
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* if the path string cannot be converted to a {@code Path}
|
||||
*
|
||||
* @see FileSystem#getPath
|
||||
*/
|
||||
public static Path get(String first, String... more) {
|
||||
return FileSystems.getDefault().getPath(first, more);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given URI to a {@link Path} object.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers to locate the provider that is identified by the
|
||||
* URI {@link URI#getScheme scheme} of the given URI. URI schemes are
|
||||
* compared without regard to case. If the provider is found then its {@link
|
||||
* FileSystemProvider#getPath getPath} method is invoked to convert the
|
||||
* URI.
|
||||
*
|
||||
* <p> In the case of the default provider, identified by the URI scheme
|
||||
* "file", the given URI has a non-empty path component, and undefined query
|
||||
* and fragment components. Whether the authority component may be present
|
||||
* is platform specific. The returned {@code Path} is associated with the
|
||||
* {@link FileSystems#getDefault default} file system.
|
||||
*
|
||||
* <p> The default provider provides a similar <em>round-trip</em> guarantee
|
||||
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
|
||||
* is guaranteed that
|
||||
* <blockquote><tt>
|
||||
* Paths.get(</tt><i>p</i><tt>.{@link Path#toUri() toUri}()).equals(</tt>
|
||||
* <i>p</i><tt>.{@link Path#toAbsolutePath() toAbsolutePath}())</tt>
|
||||
* </blockquote>
|
||||
* so long as the original {@code Path}, the {@code URI}, and the new {@code
|
||||
* Path} are all created in (possibly different invocations of) the same
|
||||
* Java virtual machine. Whether other providers make any guarantees is
|
||||
* provider specific and therefore unspecified.
|
||||
*
|
||||
* @param uri
|
||||
* the URI to convert
|
||||
*
|
||||
* @return the resulting {@code Path}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if preconditions on the {@code uri} parameter do not hold. The
|
||||
* format of the URI is provider specific.
|
||||
* @throws FileSystemNotFoundException
|
||||
* 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
|
||||
*/
|
||||
public static Path get(URI uri) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null)
|
||||
throw new IllegalArgumentException("Missing scheme");
|
||||
|
||||
// check for default provider to avoid loading of installed providers
|
||||
if (scheme.equalsIgnoreCase("file"))
|
||||
return FileSystems.getDefault().provider().getPath(uri);
|
||||
|
||||
// try to find provider
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
if (provider.getScheme().equalsIgnoreCase(scheme)) {
|
||||
return provider.getPath(uri);
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
|
||||
}
|
||||
}
|
53
jdkSrc/jdk8/java/nio/file/ProviderMismatchException.java
Normal file
53
jdkSrc/jdk8/java/nio/file/ProviderMismatchException.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to invoke a method on an
|
||||
* object created by one file system provider with a parameter created by a
|
||||
* different file system provider.
|
||||
*/
|
||||
public class ProviderMismatchException
|
||||
extends java.lang.IllegalArgumentException
|
||||
{
|
||||
static final long serialVersionUID = 4990847485741612530L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ProviderMismatchException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public ProviderMismatchException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
52
jdkSrc/jdk8/java/nio/file/ProviderNotFoundException.java
Normal file
52
jdkSrc/jdk8/java/nio/file/ProviderNotFoundException.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Runtime exception thrown when a provider of the required type cannot be found.
|
||||
*/
|
||||
|
||||
public class ProviderNotFoundException
|
||||
extends RuntimeException
|
||||
{
|
||||
static final long serialVersionUID = -1880012509822920354L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ProviderNotFoundException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public ProviderNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
43
jdkSrc/jdk8/java/nio/file/ReadOnlyFileSystemException.java
Normal file
43
jdkSrc/jdk8/java/nio/file/ReadOnlyFileSystemException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to update an object
|
||||
* associated with a {@link FileSystem#isReadOnly() read-only} {@code FileSystem}.
|
||||
*/
|
||||
|
||||
public class ReadOnlyFileSystemException
|
||||
extends UnsupportedOperationException
|
||||
{
|
||||
static final long serialVersionUID = -6822409595617487197L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public ReadOnlyFileSystemException() {
|
||||
}
|
||||
}
|
312
jdkSrc/jdk8/java/nio/file/SecureDirectoryStream.java
Normal file
312
jdkSrc/jdk8/java/nio/file/SecureDirectoryStream.java
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.*;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.util.Set;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A {@code DirectoryStream} that defines operations on files that are located
|
||||
* relative to an open directory. A {@code 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 {@code SecureDirectoryStream}
|
||||
* may also be used as a virtual <em>working directory</em>.
|
||||
*
|
||||
* <p> A {@code SecureDirectoryStream} requires corresponding support from the
|
||||
* underlying operating system. Where an implementation supports this features
|
||||
* then the {@code DirectoryStream} returned by the {@link Files#newDirectoryStream
|
||||
* newDirectoryStream} method will be a {@code SecureDirectoryStream} and must
|
||||
* be cast to that type in order to invoke the methods defined by this interface.
|
||||
*
|
||||
* <p> In the case of the default {@link java.nio.file.spi.FileSystemProvider
|
||||
* 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 <i>original path</i> of the directory (irrespective of if the
|
||||
* directory is moved since it was opened).
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface SecureDirectoryStream<T>
|
||||
extends DirectoryStream<T>
|
||||
{
|
||||
/**
|
||||
* Opens the directory identified by the given path, returning a {@code
|
||||
* SecureDirectoryStream} to iterate over the entries in the directory.
|
||||
*
|
||||
* <p> This method works in exactly the manner specified by the {@link
|
||||
* Files#newDirectoryStream(Path) 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 {@link
|
||||
* LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to
|
||||
* ensure that this method fails if the file is a symbolic link.
|
||||
*
|
||||
* <p> 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.
|
||||
*
|
||||
* @param path
|
||||
* the path to the directory to open
|
||||
* @param options
|
||||
* options indicating how symbolic links are handled
|
||||
*
|
||||
* @return a new and open {@code SecureDirectoryStream} object
|
||||
*
|
||||
* @throws ClosedDirectoryStreamException
|
||||
* if the directory stream is closed
|
||||
* @throws NotDirectoryException
|
||||
* if the file could not otherwise be opened because it is not
|
||||
* a directory <i>(optional specific exception)</i>
|
||||
* @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 directory.
|
||||
*/
|
||||
SecureDirectoryStream<T> newDirectoryStream(T path, LinkOption... options)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Opens or creates a file in this directory, returning a seekable byte
|
||||
* channel to access the file.
|
||||
*
|
||||
* <p> This method works in exactly the manner specified by the {@link
|
||||
* Files#newByteChannel Files.newByteChannel} 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 file to open or
|
||||
* create is relative to this open directory. In addition to the options
|
||||
* defined by the {@code Files.newByteChannel} method, the {@link
|
||||
* LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to
|
||||
* ensure that this method fails if the file is a symbolic link.
|
||||
*
|
||||
* <p> 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.
|
||||
*
|
||||
* @param path
|
||||
* the path of the file to open open or create
|
||||
* @param options
|
||||
* options specifying how the file is opened
|
||||
* @param attrs
|
||||
* an optional list of attributes to set atomically when creating
|
||||
* the file
|
||||
*
|
||||
* @return the seekable byte channel
|
||||
*
|
||||
* @throws ClosedDirectoryStreamException
|
||||
* if the directory stream is closed
|
||||
* @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 FileAlreadyExistsException
|
||||
* if a file of that name already exists and the {@link
|
||||
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
|
||||
* <i>(optional specific exception)</i>
|
||||
* @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 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.
|
||||
*/
|
||||
SeekableByteChannel newByteChannel(T path,
|
||||
Set<? extends OpenOption> options,
|
||||
FileAttribute<?>... attrs)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Deletes a file.
|
||||
*
|
||||
* <p> Unlike the {@link Files#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
|
||||
* 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.
|
||||
*
|
||||
* @param path
|
||||
* the path of the file to delete
|
||||
*
|
||||
* @throws ClosedDirectoryStreamException
|
||||
* if the directory stream is closed
|
||||
* @throws NoSuchFileException
|
||||
* if the file does not exist <i>(optional specific exception)</i>
|
||||
* @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) checkDelete}
|
||||
* method is invoked to check delete access to the file
|
||||
*/
|
||||
void deleteFile(T path) throws IOException;
|
||||
|
||||
/**
|
||||
* Deletes a directory.
|
||||
*
|
||||
* <p> Unlike the {@link Files#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
|
||||
* directory to delete is relative to this open directory.
|
||||
*
|
||||
* @param path
|
||||
* the path of the directory to delete
|
||||
*
|
||||
* @throws ClosedDirectoryStreamException
|
||||
* if the directory stream is closed
|
||||
* @throws NoSuchFileException
|
||||
* if the directory does not exist <i>(optional specific exception)</i>
|
||||
* @throws DirectoryNotEmptyException
|
||||
* if the directory could not otherwise be deleted because it is
|
||||
* not empty <i>(optional specific exception)</i>
|
||||
* @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) checkDelete}
|
||||
* method is invoked to check delete access to the directory
|
||||
*/
|
||||
void deleteDirectory(T path) throws IOException;
|
||||
|
||||
/**
|
||||
* Move a file from this directory to another directory.
|
||||
*
|
||||
* <p> This method works in a similar manner to {@link Files#move move}
|
||||
* method when the {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} option
|
||||
* is specified. That is, this method moves a file as an atomic file system
|
||||
* operation. If the {@code srcpath} parameter is an {@link Path#isAbsolute
|
||||
* 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 {@code targetpath} parameter is absolute then it locates the target
|
||||
* file (the {@code targetdir} parameter is ignored). If the parameter is
|
||||
* a relative path it is located relative to the open directory identified
|
||||
* by the {@code targetdir} parameter. In all cases, if the target file
|
||||
* exists then it is implementation specific if it is replaced or this
|
||||
* method fails.
|
||||
*
|
||||
* @param srcpath
|
||||
* the name of the file to move
|
||||
* @param targetdir
|
||||
* the destination directory
|
||||
* @param targetpath
|
||||
* the name to give the file in the destination directory
|
||||
*
|
||||
* @throws ClosedDirectoryStreamException
|
||||
* if this or the target directory stream is closed
|
||||
* @throws FileAlreadyExistsException
|
||||
* if the file already exists in the target directory and cannot
|
||||
* be replaced <i>(optional specific exception)</i>
|
||||
* @throws AtomicMoveNotSupportedException
|
||||
* if 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.
|
||||
*/
|
||||
void move(T srcpath, SecureDirectoryStream<T> targetdir, T targetpath)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a new file attribute view to access the file attributes of this
|
||||
* directory.
|
||||
*
|
||||
* <p> The resulting file attribute view can be used to read or update the
|
||||
* attributes of this (open) directory. The {@code 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 {@link
|
||||
* BasicFileAttributeView} always returns an instance of that class that is
|
||||
* bound to this open directory.
|
||||
*
|
||||
* <p> The state of resulting file attribute view is intimately connected
|
||||
* to this directory stream. Once the directory stream is {@link #close closed},
|
||||
* then all methods to read or update attributes will throw {@link
|
||||
* ClosedDirectoryStreamException ClosedDirectoryStreamException}.
|
||||
*
|
||||
* @param <V>
|
||||
* The {@code FileAttributeView} type
|
||||
* @param type
|
||||
* the {@code Class} object corresponding to the file attribute view
|
||||
*
|
||||
* @return a new file attribute view of the specified type bound to
|
||||
* this directory stream, or {@code null} if the attribute view
|
||||
* type is not available
|
||||
*/
|
||||
<V extends FileAttributeView> V getFileAttributeView(Class<V> type);
|
||||
|
||||
/**
|
||||
* Returns a new file attribute view to access the file attributes of a file
|
||||
* in this directory.
|
||||
*
|
||||
* <p> The resulting file attribute view can be used to read or update the
|
||||
* attributes of file in this directory. The {@code 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 {@link
|
||||
* BasicFileAttributeView} always returns an instance of that class that is
|
||||
* bound to the file in the directory.
|
||||
*
|
||||
* <p> The state of resulting file attribute view is intimately connected
|
||||
* to this directory stream. Once the directory stream {@link #close closed},
|
||||
* then all methods to read or update attributes will throw {@link
|
||||
* ClosedDirectoryStreamException 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.
|
||||
*
|
||||
* @param <V>
|
||||
* The {@code FileAttributeView} type
|
||||
* @param path
|
||||
* the path of the file
|
||||
* @param type
|
||||
* the {@code Class} object corresponding to the file attribute view
|
||||
* @param options
|
||||
* options indicating how symbolic links are handled
|
||||
*
|
||||
* @return a new file attribute view of the specified type bound to a
|
||||
* this directory stream, or {@code null} if the attribute view
|
||||
* type is not available
|
||||
*
|
||||
*/
|
||||
<V extends FileAttributeView> V getFileAttributeView(T path,
|
||||
Class<V> type,
|
||||
LinkOption... options);
|
||||
}
|
112
jdkSrc/jdk8/java/nio/file/SimpleFileVisitor.java
Normal file
112
jdkSrc/jdk8/java/nio/file/SimpleFileVisitor.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A simple visitor of files with default behavior to visit all files and to
|
||||
* re-throw I/O errors.
|
||||
*
|
||||
* <p> Methods in this class may be overridden subject to their general contract.
|
||||
*
|
||||
* @param <T> The type of reference to the files
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class SimpleFileVisitor<T> implements FileVisitor<T> {
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected SimpleFileVisitor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked for a directory before entries in the directory are visited.
|
||||
*
|
||||
* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
|
||||
* CONTINUE}.
|
||||
*/
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
|
||||
throws IOException
|
||||
{
|
||||
Objects.requireNonNull(dir);
|
||||
Objects.requireNonNull(attrs);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked for a file in a directory.
|
||||
*
|
||||
* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
|
||||
* CONTINUE}.
|
||||
*/
|
||||
@Override
|
||||
public FileVisitResult visitFile(T file, BasicFileAttributes attrs)
|
||||
throws IOException
|
||||
{
|
||||
Objects.requireNonNull(file);
|
||||
Objects.requireNonNull(attrs);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked for a file that could not be visited.
|
||||
*
|
||||
* <p> Unless overridden, this method re-throws the I/O exception that prevented
|
||||
* the file from being visited.
|
||||
*/
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(T file, IOException exc)
|
||||
throws IOException
|
||||
{
|
||||
Objects.requireNonNull(file);
|
||||
throw exc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked for a directory after entries in the directory, and all of their
|
||||
* descendants, have been visited.
|
||||
*
|
||||
* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
|
||||
* CONTINUE} if the directory iteration completes without an I/O exception;
|
||||
* otherwise this method re-throws the I/O exception that caused the iteration
|
||||
* of the directory to terminate prematurely.
|
||||
*/
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(T dir, IOException exc)
|
||||
throws IOException
|
||||
{
|
||||
Objects.requireNonNull(dir);
|
||||
if (exc != null)
|
||||
throw exc;
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
47
jdkSrc/jdk8/java/nio/file/StandardCopyOption.java
Normal file
47
jdkSrc/jdk8/java/nio/file/StandardCopyOption.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines the standard copy options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum StandardCopyOption implements CopyOption {
|
||||
/**
|
||||
* Replace an existing file if it exists.
|
||||
*/
|
||||
REPLACE_EXISTING,
|
||||
/**
|
||||
* Copy attributes to the new file.
|
||||
*/
|
||||
COPY_ATTRIBUTES,
|
||||
/**
|
||||
* Move the file as an atomic file system operation.
|
||||
*/
|
||||
ATOMIC_MOVE;
|
||||
}
|
125
jdkSrc/jdk8/java/nio/file/StandardOpenOption.java
Normal file
125
jdkSrc/jdk8/java/nio/file/StandardOpenOption.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines the standard open options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum StandardOpenOption implements OpenOption {
|
||||
/**
|
||||
* Open for read access.
|
||||
*/
|
||||
READ,
|
||||
|
||||
/**
|
||||
* Open for write access.
|
||||
*/
|
||||
WRITE,
|
||||
|
||||
/**
|
||||
* If the file is opened for {@link #WRITE} access then bytes will be written
|
||||
* to the end of the file rather than the beginning.
|
||||
*
|
||||
* <p> If the file is opened for write access by other programs, then it
|
||||
* is file system specific if writing to the end of the file is atomic.
|
||||
*/
|
||||
APPEND,
|
||||
|
||||
/**
|
||||
* If the file already exists and it is opened for {@link #WRITE}
|
||||
* access, then its length is truncated to 0. This option is ignored
|
||||
* if the file is opened only for {@link #READ} access.
|
||||
*/
|
||||
TRUNCATE_EXISTING,
|
||||
|
||||
/**
|
||||
* Create a new file if it does not exist.
|
||||
* This option is ignored if the {@link #CREATE_NEW} option is also set.
|
||||
* The check for the existence of the file and the creation of the file
|
||||
* if it does not exist is atomic with respect to other file system
|
||||
* operations.
|
||||
*/
|
||||
CREATE,
|
||||
|
||||
/**
|
||||
* Create a new file, failing if the file already exists.
|
||||
* The check for the existence of the file and the creation of the file
|
||||
* if it does not exist is atomic with respect to other file system
|
||||
* operations.
|
||||
*/
|
||||
CREATE_NEW,
|
||||
|
||||
/**
|
||||
* Delete on close. When this option is present then the implementation
|
||||
* makes a <em>best effort</em> attempt to delete the file when closed
|
||||
* by the appropriate {@code close} method. If the {@code close} method is
|
||||
* not invoked then a <em>best effort</em> attempt is made to delete the
|
||||
* file when the Java virtual machine terminates (either normally, as
|
||||
* defined by the Java Language Specification, or where possible, abnormally).
|
||||
* This option is primarily intended for use with <em>work files</em> that
|
||||
* are used solely by a single instance of the Java virtual machine. This
|
||||
* option is not recommended for use when opening files that are open
|
||||
* concurrently by other entities. Many of the details as to when and how
|
||||
* the file is deleted are implementation specific and therefore not
|
||||
* specified. In particular, an implementation may be unable to guarantee
|
||||
* that it deletes the expected file when replaced by an attacker while the
|
||||
* file is open. Consequently, security sensitive applications should take
|
||||
* care when using this option.
|
||||
*
|
||||
* <p> For security reasons, this option may imply the {@link
|
||||
* LinkOption#NOFOLLOW_LINKS} option. In other words, if the option is present
|
||||
* when opening an existing file that is a symbolic link then it may fail
|
||||
* (by throwing {@link java.io.IOException}).
|
||||
*/
|
||||
DELETE_ON_CLOSE,
|
||||
|
||||
/**
|
||||
* Sparse file. When used with the {@link #CREATE_NEW} option then this
|
||||
* option provides a <em>hint</em> that the new file will be sparse. The
|
||||
* option is ignored when the file system does not support the creation of
|
||||
* sparse files.
|
||||
*/
|
||||
SPARSE,
|
||||
|
||||
/**
|
||||
* Requires that every update to the file's content or metadata be written
|
||||
* synchronously to the underlying storage device.
|
||||
*
|
||||
* @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a>
|
||||
*/
|
||||
SYNC,
|
||||
|
||||
/**
|
||||
* Requires that every update to the file's content be written
|
||||
* synchronously to the underlying storage device.
|
||||
*
|
||||
* @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a>
|
||||
*/
|
||||
DSYNC;
|
||||
}
|
94
jdkSrc/jdk8/java/nio/file/StandardWatchEventKinds.java
Normal file
94
jdkSrc/jdk8/java/nio/file/StandardWatchEventKinds.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* Defines the <em>standard</em> event kinds.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public final class StandardWatchEventKinds {
|
||||
private StandardWatchEventKinds() { }
|
||||
|
||||
/**
|
||||
* A special event to indicate that events may have been lost or
|
||||
* discarded.
|
||||
*
|
||||
* <p> The {@link WatchEvent#context context} for this event is
|
||||
* implementation specific and may be {@code null}. The event {@link
|
||||
* WatchEvent#count count} may be greater than {@code 1}.
|
||||
*
|
||||
* @see WatchService
|
||||
*/
|
||||
public static final WatchEvent.Kind<Object> OVERFLOW =
|
||||
new StdWatchEventKind<Object>("OVERFLOW", Object.class);
|
||||
|
||||
/**
|
||||
* Directory entry created.
|
||||
*
|
||||
* <p> When a directory is registered for this event then the {@link WatchKey}
|
||||
* is queued when it is observed that an entry is created in the directory
|
||||
* or renamed into the directory. The event {@link WatchEvent#count count}
|
||||
* for this event is always {@code 1}.
|
||||
*/
|
||||
public static final WatchEvent.Kind<Path> ENTRY_CREATE =
|
||||
new StdWatchEventKind<Path>("ENTRY_CREATE", Path.class);
|
||||
|
||||
/**
|
||||
* Directory entry deleted.
|
||||
*
|
||||
* <p> When a directory is registered for this event then the {@link WatchKey}
|
||||
* is queued when it is observed that an entry is deleted or renamed out of
|
||||
* the directory. The event {@link WatchEvent#count count} for this event
|
||||
* is always {@code 1}.
|
||||
*/
|
||||
public static final WatchEvent.Kind<Path> ENTRY_DELETE =
|
||||
new StdWatchEventKind<Path>("ENTRY_DELETE", Path.class);
|
||||
|
||||
/**
|
||||
* Directory entry modified.
|
||||
*
|
||||
* <p> When a directory is registered for this event then the {@link WatchKey}
|
||||
* is queued when it is observed that an entry in the directory has been
|
||||
* modified. The event {@link WatchEvent#count count} for this event is
|
||||
* {@code 1} or greater.
|
||||
*/
|
||||
public static final WatchEvent.Kind<Path> ENTRY_MODIFY =
|
||||
new StdWatchEventKind<Path>("ENTRY_MODIFY", Path.class);
|
||||
|
||||
private static class StdWatchEventKind<T> implements WatchEvent.Kind<T> {
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
StdWatchEventKind(String name, Class<T> type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
@Override public String name() { return name; }
|
||||
@Override public Class<T> type() { return type; }
|
||||
@Override public String toString() { return name; }
|
||||
}
|
||||
}
|
175
jdkSrc/jdk8/java/nio/file/TempFileHelper.java
Normal file
175
jdkSrc/jdk8/java/nio/file/TempFileHelper.java
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.security.SecureRandom;
|
||||
import static java.security.AccessController.*;
|
||||
import java.io.IOException;
|
||||
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 sun.security.action.GetPropertyAction;
|
||||
|
||||
|
||||
/**
|
||||
* Helper class to support creation of temporary files and directories with
|
||||
* initial attributes.
|
||||
*/
|
||||
|
||||
class TempFileHelper {
|
||||
private TempFileHelper() { }
|
||||
|
||||
// temporary directory location
|
||||
private static final Path tmpdir =
|
||||
Paths.get(doPrivileged(new GetPropertyAction("java.io.tmpdir")));
|
||||
|
||||
private static final boolean isPosix =
|
||||
FileSystems.getDefault().supportedFileAttributeViews().contains("posix");
|
||||
|
||||
// file name generation, same as java.io.File for now
|
||||
private static final SecureRandom random = new SecureRandom();
|
||||
private static Path generatePath(String prefix, String suffix, Path dir) {
|
||||
long n = random.nextLong();
|
||||
n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n);
|
||||
Path name = dir.getFileSystem().getPath(prefix + Long.toString(n) + suffix);
|
||||
// the generated name should be a simple file name
|
||||
if (name.getParent() != null)
|
||||
throw new IllegalArgumentException("Invalid prefix or suffix");
|
||||
return dir.resolve(name);
|
||||
}
|
||||
|
||||
// default file and directory permissions (lazily initialized)
|
||||
private static class PosixPermissions {
|
||||
static final FileAttribute<Set<PosixFilePermission>> filePermissions =
|
||||
PosixFilePermissions.asFileAttribute(EnumSet.of(OWNER_READ, OWNER_WRITE));
|
||||
static final FileAttribute<Set<PosixFilePermission>> dirPermissions =
|
||||
PosixFilePermissions.asFileAttribute(EnumSet
|
||||
.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file or directory in in the given given directory (or in the
|
||||
* temporary directory if dir is {@code null}).
|
||||
*/
|
||||
private static Path create(Path dir,
|
||||
String prefix,
|
||||
String suffix,
|
||||
boolean createDirectory,
|
||||
FileAttribute<?>[] attrs)
|
||||
throws IOException
|
||||
{
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
if (suffix == null)
|
||||
suffix = (createDirectory) ? "" : ".tmp";
|
||||
if (dir == null)
|
||||
dir = tmpdir;
|
||||
|
||||
// in POSIX environments use default file and directory permissions
|
||||
// if initial permissions not given by caller.
|
||||
if (isPosix && (dir.getFileSystem() == FileSystems.getDefault())) {
|
||||
if (attrs.length == 0) {
|
||||
// no attributes so use default permissions
|
||||
attrs = new FileAttribute<?>[1];
|
||||
attrs[0] = (createDirectory) ? PosixPermissions.dirPermissions :
|
||||
PosixPermissions.filePermissions;
|
||||
} else {
|
||||
// check if posix permissions given; if not use default
|
||||
boolean hasPermissions = false;
|
||||
for (int i=0; i<attrs.length; i++) {
|
||||
if (attrs[i].name().equals("posix:permissions")) {
|
||||
hasPermissions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasPermissions) {
|
||||
FileAttribute<?>[] copy = new FileAttribute<?>[attrs.length+1];
|
||||
System.arraycopy(attrs, 0, copy, 0, attrs.length);
|
||||
attrs = copy;
|
||||
attrs[attrs.length-1] = (createDirectory) ?
|
||||
PosixPermissions.dirPermissions :
|
||||
PosixPermissions.filePermissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loop generating random names until file or directory can be created
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
for (;;) {
|
||||
Path f;
|
||||
try {
|
||||
f = generatePath(prefix, suffix, dir);
|
||||
} catch (InvalidPathException e) {
|
||||
// don't reveal temporary directory location
|
||||
if (sm != null)
|
||||
throw new IllegalArgumentException("Invalid prefix or suffix");
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
if (createDirectory) {
|
||||
return Files.createDirectory(f, attrs);
|
||||
} else {
|
||||
return Files.createFile(f, attrs);
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// don't reveal temporary directory location
|
||||
if (dir == tmpdir && sm != null)
|
||||
throw new SecurityException("Unable to create temporary file or directory");
|
||||
throw e;
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary file in the given directory, or in in the
|
||||
* temporary directory if dir is {@code null}.
|
||||
*/
|
||||
static Path createTempFile(Path dir,
|
||||
String prefix,
|
||||
String suffix,
|
||||
FileAttribute<?>[] attrs)
|
||||
throws IOException
|
||||
{
|
||||
return create(dir, prefix, suffix, false, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary directory in the given directory, or in in the
|
||||
* temporary directory if dir is {@code null}.
|
||||
*/
|
||||
static Path createTempDirectory(Path dir,
|
||||
String prefix,
|
||||
FileAttribute<?>[] attrs)
|
||||
throws IOException
|
||||
{
|
||||
return create(dir, prefix, null, true, attrs);
|
||||
}
|
||||
}
|
118
jdkSrc/jdk8/java/nio/file/WatchEvent.java
Normal file
118
jdkSrc/jdk8/java/nio/file/WatchEvent.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
/**
|
||||
* An event or a repeated event for an object that is registered with a {@link
|
||||
* WatchService}.
|
||||
*
|
||||
* <p> An event is classified by its {@link #kind() kind} and has a {@link
|
||||
* #count() count} to indicate the number of times that the event has been
|
||||
* observed. This allows for efficient representation of repeated events. The
|
||||
* {@link #context() context} method returns any context associated with
|
||||
* the event. In the case of a repeated event then the context is the same for
|
||||
* all events.
|
||||
*
|
||||
* <p> Watch events are immutable and safe for use by multiple concurrent
|
||||
* threads.
|
||||
*
|
||||
* @param <T> The type of the context object associated with the event
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface WatchEvent<T> {
|
||||
|
||||
/**
|
||||
* An event kind, for the purposes of identification.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see StandardWatchEventKinds
|
||||
*/
|
||||
public static interface Kind<T> {
|
||||
/**
|
||||
* Returns the name of the event kind.
|
||||
*
|
||||
* @return the name of the event kind
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns the type of the {@link WatchEvent#context context} value.
|
||||
*
|
||||
*
|
||||
* @return the type of the context value
|
||||
*/
|
||||
Class<T> type();
|
||||
}
|
||||
|
||||
/**
|
||||
* An event modifier that qualifies how a {@link Watchable} is registered
|
||||
* with a {@link WatchService}.
|
||||
*
|
||||
* <p> This release does not define any <em>standard</em> modifiers.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see Watchable#register
|
||||
*/
|
||||
public static interface Modifier {
|
||||
/**
|
||||
* Returns the name of the modifier.
|
||||
*
|
||||
* @return the name of the modifier
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event kind.
|
||||
*
|
||||
* @return the event kind
|
||||
*/
|
||||
Kind<T> kind();
|
||||
|
||||
/**
|
||||
* Returns the event count. If the event count is greater than {@code 1}
|
||||
* then this is a repeated event.
|
||||
*
|
||||
* @return the event count
|
||||
*/
|
||||
int count();
|
||||
|
||||
/**
|
||||
* Returns the context for the event.
|
||||
*
|
||||
* <p> In the case of {@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE},
|
||||
* {@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE}, and {@link
|
||||
* StandardWatchEventKinds#ENTRY_MODIFY ENTRY_MODIFY} events the context is
|
||||
* a {@code Path} that is the {@link Path#relativize relative} path between
|
||||
* the directory registered with the watch service, and the entry that is
|
||||
* created, deleted, or modified.
|
||||
*
|
||||
* @return the event context; may be {@code null}
|
||||
*/
|
||||
T context();
|
||||
}
|
150
jdkSrc/jdk8/java/nio/file/WatchKey.java
Normal file
150
jdkSrc/jdk8/java/nio/file/WatchKey.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A token representing the registration of a {@link Watchable watchable} object
|
||||
* with a {@link WatchService}.
|
||||
*
|
||||
* <p> A watch key is created when a watchable object is registered with a watch
|
||||
* service. The key remains {@link #isValid valid} until:
|
||||
* <ol>
|
||||
* <li> It is cancelled, explicitly, by invoking its {@link #cancel cancel}
|
||||
* method, or</li>
|
||||
* <li> Cancelled implicitly, because the object is no longer accessible,
|
||||
* or </li>
|
||||
* <li> By {@link WatchService#close closing} the watch service. </li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> A watch key has a state. When initially created the key is said to be
|
||||
* <em>ready</em>. When an event is detected then the key is <em>signalled</em>
|
||||
* and queued so that it can be retrieved by invoking the watch service's {@link
|
||||
* WatchService#poll() poll} or {@link WatchService#take() take} methods. Once
|
||||
* signalled, a key remains in this state until its {@link #reset reset} method
|
||||
* is invoked to return the key to the ready state. Events detected while the
|
||||
* key is in the signalled state are queued but do not cause the key to be
|
||||
* re-queued for retrieval from the watch service. Events are retrieved by
|
||||
* invoking the key's {@link #pollEvents pollEvents} method. This method
|
||||
* retrieves and removes all events accumulated for the object. When initially
|
||||
* created, a watch key has no pending events. Typically events are retrieved
|
||||
* when the key is in the signalled state leading to the following idiom:
|
||||
*
|
||||
* <pre>
|
||||
* for (;;) {
|
||||
* // retrieve key
|
||||
* WatchKey key = watcher.take();
|
||||
*
|
||||
* // process events
|
||||
* for (WatchEvent<?> event: key.pollEvents()) {
|
||||
* :
|
||||
* }
|
||||
*
|
||||
* // reset the key
|
||||
* boolean valid = key.reset();
|
||||
* if (!valid) {
|
||||
* // object no longer registered
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p> Watch keys are safe for use by multiple concurrent threads. Where there
|
||||
* are several threads retrieving signalled keys from a watch service then care
|
||||
* should be taken to ensure that the {@code reset} method is only invoked after
|
||||
* the events for the object have been processed. This ensures that one thread
|
||||
* is processing the events for an object at any time.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface WatchKey {
|
||||
|
||||
/**
|
||||
* Tells whether or not this watch key is valid.
|
||||
*
|
||||
* <p> A watch key is valid upon creation and remains until it is cancelled,
|
||||
* or its watch service is closed.
|
||||
*
|
||||
* @return {@code true} if, and only if, this watch key is valid
|
||||
*/
|
||||
boolean isValid();
|
||||
|
||||
/**
|
||||
* Retrieves and removes all pending events for this watch key, returning
|
||||
* a {@code List} of the events that were retrieved.
|
||||
*
|
||||
* <p> Note that this method does not wait if there are no events pending.
|
||||
*
|
||||
* @return the list of the events retrieved; may be empty
|
||||
*/
|
||||
List<WatchEvent<?>> pollEvents();
|
||||
|
||||
/**
|
||||
* Resets this watch key.
|
||||
*
|
||||
* <p> If this watch key has been cancelled or this watch key is already in
|
||||
* the ready state then invoking this method has no effect. Otherwise
|
||||
* if there are pending events for the object then this watch key is
|
||||
* immediately re-queued to the watch service. If there are no pending
|
||||
* events then the watch key is put into the ready state and will remain in
|
||||
* that state until an event is detected or the watch key is cancelled.
|
||||
*
|
||||
* @return {@code true} if the watch key is valid and has been reset, and
|
||||
* {@code false} if the watch key could not be reset because it is
|
||||
* no longer {@link #isValid valid}
|
||||
*/
|
||||
boolean reset();
|
||||
|
||||
/**
|
||||
* Cancels the registration with the watch service. Upon return the watch key
|
||||
* will be invalid. If the watch key is enqueued, waiting to be retrieved
|
||||
* from the watch service, then it will remain in the queue until it is
|
||||
* removed. Pending events, if any, remain pending and may be retrieved by
|
||||
* invoking the {@link #pollEvents pollEvents} method after the key is
|
||||
* cancelled.
|
||||
*
|
||||
* <p> If this watch key has already been cancelled then invoking this
|
||||
* method has no effect. Once cancelled, a watch key remains forever invalid.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Returns the object for which this watch key was created. This method will
|
||||
* continue to return the object even after the key is cancelled.
|
||||
*
|
||||
* <p> As the {@code WatchService} is intended to map directly on to the
|
||||
* native file event notification facility (where available) then many of
|
||||
* details on how registered objects are watched is highly implementation
|
||||
* specific. When watching a directory for changes for example, and the
|
||||
* directory is moved or renamed in the file system, there is no guarantee
|
||||
* that the watch key will be cancelled and so the object returned by this
|
||||
* method may no longer be a valid path to the directory.
|
||||
*
|
||||
* @return the object for which this watch key was created
|
||||
*/
|
||||
Watchable watchable();
|
||||
}
|
174
jdkSrc/jdk8/java/nio/file/WatchService.java
Normal file
174
jdkSrc/jdk8/java/nio/file/WatchService.java
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A watch service that <em>watches</em> registered objects for changes and
|
||||
* events. For example a file manager may use a watch service to monitor a
|
||||
* directory for changes so that it can update its display of the list of files
|
||||
* when files are created or deleted.
|
||||
*
|
||||
* <p> A {@link Watchable} object is registered with a watch service by invoking
|
||||
* its {@link Watchable#register register} method, returning a {@link WatchKey}
|
||||
* to represent the registration. When an event for an object is detected the
|
||||
* key is <em>signalled</em>, and if not currently signalled, it is queued to
|
||||
* the watch service so that it can be retrieved by consumers that invoke the
|
||||
* {@link #poll() poll} or {@link #take() take} methods to retrieve keys
|
||||
* and process events. Once the events have been processed the consumer
|
||||
* invokes the key's {@link WatchKey#reset reset} method to reset the key which
|
||||
* allows the key to be signalled and re-queued with further events.
|
||||
*
|
||||
* <p> Registration with a watch service is cancelled by invoking the key's
|
||||
* {@link WatchKey#cancel cancel} method. A key that is queued at the time that
|
||||
* it is cancelled remains in the queue until it is retrieved. Depending on the
|
||||
* object, a key may be cancelled automatically. For example, suppose a
|
||||
* directory is watched and the watch service detects that it has been deleted
|
||||
* or its file system is no longer accessible. When a key is cancelled in this
|
||||
* manner it is signalled and queued, if not currently signalled. To ensure
|
||||
* that the consumer is notified the return value from the {@code reset}
|
||||
* method indicates if the key is valid.
|
||||
*
|
||||
* <p> A watch service is safe for use by multiple concurrent consumers. To
|
||||
* ensure that only one consumer processes the events for a particular object at
|
||||
* any time then care should be taken to ensure that the key's {@code reset}
|
||||
* method is only invoked after its events have been processed. The {@link
|
||||
* #close close} method may be invoked at any time to close the service causing
|
||||
* any threads waiting to retrieve keys, to throw {@code
|
||||
* ClosedWatchServiceException}.
|
||||
*
|
||||
* <p> File systems may report events faster than they can be retrieved or
|
||||
* processed and an implementation may impose an unspecified limit on the number
|
||||
* of events that it may accumulate. Where an implementation <em>knowingly</em>
|
||||
* discards events then it arranges for the key's {@link WatchKey#pollEvents
|
||||
* pollEvents} method to return an element with an event type of {@link
|
||||
* StandardWatchEventKinds#OVERFLOW OVERFLOW}. This event can be used by the
|
||||
* consumer as a trigger to re-examine the state of the object.
|
||||
*
|
||||
* <p> When an event is reported to indicate that a file in a watched directory
|
||||
* has been modified then there is no guarantee that the program (or programs)
|
||||
* that have modified the file have completed. Care should be taken to coordinate
|
||||
* access with other programs that may be updating the file.
|
||||
* The {@link java.nio.channels.FileChannel FileChannel} class defines methods
|
||||
* to lock regions of a file against access by other programs.
|
||||
*
|
||||
* <h2>Platform dependencies</h2>
|
||||
*
|
||||
* <p> The implementation that observes events from the file system is intended
|
||||
* to map directly on to the native file event notification facility where
|
||||
* available, or to use a primitive mechanism, such as polling, when a native
|
||||
* facility is not available. Consequently, many of the details on how events
|
||||
* are detected, their timeliness, and whether their ordering is preserved are
|
||||
* highly implementation specific. For example, when a file in a watched
|
||||
* directory is modified then it may result in a single {@link
|
||||
* StandardWatchEventKinds#ENTRY_MODIFY ENTRY_MODIFY} event in some
|
||||
* implementations but several events in other implementations. Short-lived
|
||||
* files (meaning files that are deleted very quickly after they are created)
|
||||
* may not be detected by primitive implementations that periodically poll the
|
||||
* file system to detect changes.
|
||||
*
|
||||
* <p> If a watched file is not located on a local storage device then it is
|
||||
* implementation specific if changes to the file can be detected. In particular,
|
||||
* it is not required that changes to files carried out on remote systems be
|
||||
* detected.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see FileSystem#newWatchService
|
||||
*/
|
||||
|
||||
public interface WatchService
|
||||
extends Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
* Closes this watch service.
|
||||
*
|
||||
* <p> If a thread is currently blocked in the {@link #take take} or {@link
|
||||
* #poll(long,TimeUnit) poll} methods waiting for a key to be queued then
|
||||
* it immediately receives a {@link ClosedWatchServiceException}. Any
|
||||
* valid keys associated with this watch service are {@link WatchKey#isValid
|
||||
* invalidated}.
|
||||
*
|
||||
* <p> After a watch service is closed, any further attempt to invoke
|
||||
* operations upon it will throw {@link ClosedWatchServiceException}.
|
||||
* If this watch service is already closed then invoking this method
|
||||
* has no effect.
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
@Override
|
||||
void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves and removes the next watch key, or {@code null} if none are
|
||||
* present.
|
||||
*
|
||||
* @return the next watch key, or {@code null}
|
||||
*
|
||||
* @throws ClosedWatchServiceException
|
||||
* if this watch service is closed
|
||||
*/
|
||||
WatchKey poll();
|
||||
|
||||
/**
|
||||
* Retrieves and removes the next watch key, waiting if necessary up to the
|
||||
* specified wait time if none are yet present.
|
||||
*
|
||||
* @param timeout
|
||||
* how to wait before giving up, in units of unit
|
||||
* @param unit
|
||||
* a {@code TimeUnit} determining how to interpret the timeout
|
||||
* parameter
|
||||
*
|
||||
* @return the next watch key, or {@code null}
|
||||
*
|
||||
* @throws ClosedWatchServiceException
|
||||
* if this watch service is closed, or it is closed while waiting
|
||||
* for the next key
|
||||
* @throws InterruptedException
|
||||
* if interrupted while waiting
|
||||
*/
|
||||
WatchKey poll(long timeout, TimeUnit unit)
|
||||
throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Retrieves and removes next watch key, waiting if none are yet present.
|
||||
*
|
||||
* @return the next watch key
|
||||
*
|
||||
* @throws ClosedWatchServiceException
|
||||
* if this watch service is closed, or it is closed while waiting
|
||||
* for the next key
|
||||
* @throws InterruptedException
|
||||
* if interrupted while waiting
|
||||
*/
|
||||
WatchKey take() throws InterruptedException;
|
||||
}
|
127
jdkSrc/jdk8/java/nio/file/Watchable.java
Normal file
127
jdkSrc/jdk8/java/nio/file/Watchable.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An object that may be registered with a watch service so that it can be
|
||||
* <em>watched</em> for changes and events.
|
||||
*
|
||||
* <p> This interface defines the {@link #register register} method to register
|
||||
* the object with a {@link WatchService} returning a {@link WatchKey} to
|
||||
* represent the registration. An object may be registered with more than one
|
||||
* watch service. Registration with a watch service is cancelled by invoking the
|
||||
* key's {@link WatchKey#cancel cancel} method.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see Path#register
|
||||
*/
|
||||
|
||||
public interface Watchable {
|
||||
|
||||
/**
|
||||
* Registers an object with a watch service.
|
||||
*
|
||||
* <p> If the file system object identified by this object is currently
|
||||
* registered with the watch service then the watch key, representing that
|
||||
* registration, is returned after changing the event set or modifiers to
|
||||
* those specified by the {@code events} and {@code modifiers} parameters.
|
||||
* Changing the event set does not cause pending events for the object to be
|
||||
* discarded. Objects are automatically registered for the {@link
|
||||
* StandardWatchEventKinds#OVERFLOW OVERFLOW} event. This event is not
|
||||
* required to be present in the array of events.
|
||||
*
|
||||
* <p> Otherwise the file system object has not yet been registered with the
|
||||
* given watch service, so it is registered and the resulting new key is
|
||||
* returned.
|
||||
*
|
||||
* <p> Implementations of this interface should specify the events they
|
||||
* support.
|
||||
*
|
||||
* @param watcher
|
||||
* the watch service to which this object is to be registered
|
||||
* @param events
|
||||
* the events for which this object should be registered
|
||||
* @param modifiers
|
||||
* the modifiers, if any, that modify how the object is registered
|
||||
*
|
||||
* @return a key representing the registration of this object with the
|
||||
* given watch service
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if unsupported events or modifiers are specified
|
||||
* @throws IllegalArgumentException
|
||||
* if an invalid of combination of events are modifiers are specified
|
||||
* @throws ClosedWatchServiceException
|
||||
* if the watch service is closed
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission required to monitor this object. Implementations of
|
||||
* this interface should specify the permission checks.
|
||||
*/
|
||||
WatchKey register(WatchService watcher,
|
||||
WatchEvent.Kind<?>[] events,
|
||||
WatchEvent.Modifier... modifiers)
|
||||
throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Registers an object with a watch service.
|
||||
*
|
||||
* <p> An invocation of this method behaves in exactly the same way as the
|
||||
* invocation
|
||||
* <pre>
|
||||
* watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);
|
||||
* </pre>
|
||||
*
|
||||
* @param watcher
|
||||
* the watch service to which this object is to be registered
|
||||
* @param events
|
||||
* the events for which this object should be registered
|
||||
*
|
||||
* @return a key representing the registration of this object with the
|
||||
* given watch service
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if unsupported events are specified
|
||||
* @throws IllegalArgumentException
|
||||
* if an invalid of combination of events are specified
|
||||
* @throws ClosedWatchServiceException
|
||||
* if the watch service is closed
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission required to monitor this object. Implementations of
|
||||
* this interface should specify the permission checks.
|
||||
*/
|
||||
WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events)
|
||||
throws IOException;
|
||||
}
|
417
jdkSrc/jdk8/java/nio/file/attribute/AclEntry.java
Normal file
417
jdkSrc/jdk8/java/nio/file/attribute/AclEntry.java
Normal file
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An entry in an access control list (ACL).
|
||||
*
|
||||
* <p> The ACL entry represented by this class is based on the ACL model
|
||||
* specified in <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530:
|
||||
* Network File System (NFS) version 4 Protocol</i></a>. Each entry has four
|
||||
* components as follows:
|
||||
*
|
||||
* <ol>
|
||||
* <li><p> The {@link #type() type} component determines if the entry
|
||||
* grants or denies access. </p></li>
|
||||
*
|
||||
* <li><p> The {@link #principal() principal} component, sometimes called the
|
||||
* "who" component, is a {@link UserPrincipal} corresponding to the identity
|
||||
* that the entry grants or denies access
|
||||
* </p></li>
|
||||
*
|
||||
* <li><p> The {@link #permissions permissions} component is a set of
|
||||
* {@link AclEntryPermission permissions}
|
||||
* </p></li>
|
||||
*
|
||||
* <li><p> The {@link #flags flags} component is a set of {@link AclEntryFlag
|
||||
* flags} to indicate how entries are inherited and propagated </p></li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> ACL entries are created using an associated {@link Builder} object by
|
||||
* invoking its {@link Builder#build build} method.
|
||||
*
|
||||
* <p> ACL entries are immutable and are safe for use by multiple concurrent
|
||||
* threads.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public final class AclEntry {
|
||||
|
||||
private final AclEntryType type;
|
||||
private final UserPrincipal who;
|
||||
private final Set<AclEntryPermission> perms;
|
||||
private final Set<AclEntryFlag> flags;
|
||||
|
||||
// cached hash code
|
||||
private volatile int hash;
|
||||
|
||||
// private constructor
|
||||
private AclEntry(AclEntryType type,
|
||||
UserPrincipal who,
|
||||
Set<AclEntryPermission> perms,
|
||||
Set<AclEntryFlag> flags)
|
||||
{
|
||||
this.type = type;
|
||||
this.who = who;
|
||||
this.perms = perms;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder of {@link AclEntry} objects.
|
||||
*
|
||||
* <p> A {@code Builder} object is obtained by invoking one of the {@link
|
||||
* AclEntry#newBuilder newBuilder} methods defined by the {@code AclEntry}
|
||||
* class.
|
||||
*
|
||||
* <p> Builder objects are mutable and are not safe for use by multiple
|
||||
* concurrent threads without appropriate synchronization.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static final class Builder {
|
||||
private AclEntryType type;
|
||||
private UserPrincipal who;
|
||||
private Set<AclEntryPermission> perms;
|
||||
private Set<AclEntryFlag> flags;
|
||||
|
||||
private Builder(AclEntryType type,
|
||||
UserPrincipal who,
|
||||
Set<AclEntryPermission> perms,
|
||||
Set<AclEntryFlag> flags)
|
||||
{
|
||||
assert perms != null && flags != null;
|
||||
this.type = type;
|
||||
this.who = who;
|
||||
this.perms = perms;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an {@link AclEntry} from the components of this builder.
|
||||
* The type and who components are required to have been set in order
|
||||
* to construct an {@code AclEntry}.
|
||||
*
|
||||
* @return a new ACL entry
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if the type or who component have not been set
|
||||
*/
|
||||
public AclEntry build() {
|
||||
if (type == null)
|
||||
throw new IllegalStateException("Missing type component");
|
||||
if (who == null)
|
||||
throw new IllegalStateException("Missing who component");
|
||||
return new AclEntry(type, who, perms, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type component of this builder.
|
||||
*
|
||||
* @param type the component type
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setType(AclEntryType type) {
|
||||
if (type == null)
|
||||
throw new NullPointerException();
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the principal component of this builder.
|
||||
*
|
||||
* @param who the principal component
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setPrincipal(UserPrincipal who) {
|
||||
if (who == null)
|
||||
throw new NullPointerException();
|
||||
this.who = who;
|
||||
return this;
|
||||
}
|
||||
|
||||
// check set only contains elements of the given type
|
||||
private static void checkSet(Set<?> set, Class<?> type) {
|
||||
for (Object e: set) {
|
||||
if (e == null)
|
||||
throw new NullPointerException();
|
||||
type.cast(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the permissions component of this builder. On return, the
|
||||
* permissions component of this builder is a copy of the given set.
|
||||
*
|
||||
* @param perms the permissions component
|
||||
* @return this builder
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* if the set contains elements that are not of type {@code
|
||||
* AclEntryPermission}
|
||||
*/
|
||||
public Builder setPermissions(Set<AclEntryPermission> perms) {
|
||||
if (perms.isEmpty()) {
|
||||
// EnumSet.copyOf does not allow empty set
|
||||
perms = Collections.emptySet();
|
||||
} else {
|
||||
// copy and check for erroneous elements
|
||||
perms = EnumSet.copyOf(perms);
|
||||
checkSet(perms, AclEntryPermission.class);
|
||||
}
|
||||
|
||||
this.perms = perms;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the permissions component of this builder. On return, the
|
||||
* permissions component of this builder is a copy of the permissions in
|
||||
* the given array.
|
||||
*
|
||||
* @param perms the permissions component
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setPermissions(AclEntryPermission... perms) {
|
||||
Set<AclEntryPermission> set = EnumSet.noneOf(AclEntryPermission.class);
|
||||
// copy and check for null elements
|
||||
for (AclEntryPermission p: perms) {
|
||||
if (p == null)
|
||||
throw new NullPointerException();
|
||||
set.add(p);
|
||||
}
|
||||
this.perms = set;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flags component of this builder. On return, the flags
|
||||
* component of this builder is a copy of the given set.
|
||||
*
|
||||
* @param flags the flags component
|
||||
* @return this builder
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* if the set contains elements that are not of type {@code
|
||||
* AclEntryFlag}
|
||||
*/
|
||||
public Builder setFlags(Set<AclEntryFlag> flags) {
|
||||
if (flags.isEmpty()) {
|
||||
// EnumSet.copyOf does not allow empty set
|
||||
flags = Collections.emptySet();
|
||||
} else {
|
||||
// copy and check for erroneous elements
|
||||
flags = EnumSet.copyOf(flags);
|
||||
checkSet(flags, AclEntryFlag.class);
|
||||
}
|
||||
|
||||
this.flags = flags;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flags component of this builder. On return, the flags
|
||||
* component of this builder is a copy of the flags in the given
|
||||
* array.
|
||||
*
|
||||
* @param flags the flags component
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setFlags(AclEntryFlag... flags) {
|
||||
Set<AclEntryFlag> set = EnumSet.noneOf(AclEntryFlag.class);
|
||||
// copy and check for null elements
|
||||
for (AclEntryFlag f: flags) {
|
||||
if (f == null)
|
||||
throw new NullPointerException();
|
||||
set.add(f);
|
||||
}
|
||||
this.flags = set;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new builder. The initial value of the type and who
|
||||
* components is {@code null}. The initial value of the permissions and
|
||||
* flags components is the empty set.
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
public static Builder newBuilder() {
|
||||
Set<AclEntryPermission> perms = Collections.emptySet();
|
||||
Set<AclEntryFlag> flags = Collections.emptySet();
|
||||
return new Builder(null, null, perms, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new builder with the components of an existing ACL entry.
|
||||
*
|
||||
* @param entry an ACL entry
|
||||
* @return a new builder
|
||||
*/
|
||||
public static Builder newBuilder(AclEntry entry) {
|
||||
return new Builder(entry.type, entry.who, entry.perms, entry.flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ACL entry type.
|
||||
*
|
||||
* @return the ACL entry type
|
||||
*/
|
||||
public AclEntryType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the principal component.
|
||||
*
|
||||
* @return the principal component
|
||||
*/
|
||||
public UserPrincipal principal() {
|
||||
return who;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the permissions component.
|
||||
*
|
||||
* <p> The returned set is a modifiable copy of the permissions.
|
||||
*
|
||||
* @return the permissions component
|
||||
*/
|
||||
public Set<AclEntryPermission> permissions() {
|
||||
return new HashSet<AclEntryPermission>(perms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the flags component.
|
||||
*
|
||||
* <p> The returned set is a modifiable copy of the flags.
|
||||
*
|
||||
* @return the flags component
|
||||
*/
|
||||
public Set<AclEntryFlag> flags() {
|
||||
return new HashSet<AclEntryFlag>(flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the specified object with this ACL entry for equality.
|
||||
*
|
||||
* <p> If the given object is not an {@code AclEntry} then this method
|
||||
* immediately returns {@code false}.
|
||||
*
|
||||
* <p> For two ACL entries to be considered equals requires that they are
|
||||
* both the same type, their who components are equal, their permissions
|
||||
* components are equal, and their flags components are equal.
|
||||
*
|
||||
* <p> This method satisfies the general contract of the {@link
|
||||
* java.lang.Object#equals(Object) Object.equals} method. </p>
|
||||
*
|
||||
* @param ob the object to which this object is to be compared
|
||||
*
|
||||
* @return {@code true} if, and only if, the given object is an AclEntry that
|
||||
* is identical to this AclEntry
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object ob) {
|
||||
if (ob == this)
|
||||
return true;
|
||||
if (ob == null || !(ob instanceof AclEntry))
|
||||
return false;
|
||||
AclEntry other = (AclEntry)ob;
|
||||
if (this.type != other.type)
|
||||
return false;
|
||||
if (!this.who.equals(other.who))
|
||||
return false;
|
||||
if (!this.perms.equals(other.perms))
|
||||
return false;
|
||||
if (!this.flags.equals(other.flags))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int hash(int h, Object o) {
|
||||
return h * 127 + o.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash-code value for this ACL entry.
|
||||
*
|
||||
* <p> This method satisfies the general contract of the {@link
|
||||
* Object#hashCode} method.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// return cached hash if available
|
||||
if (hash != 0)
|
||||
return hash;
|
||||
int h = type.hashCode();
|
||||
h = hash(h, who);
|
||||
h = hash(h, perms);
|
||||
h = hash(h, flags);
|
||||
hash = h;
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of this ACL entry.
|
||||
*
|
||||
* @return the string representation of this entry
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// who
|
||||
sb.append(who.getName());
|
||||
sb.append(':');
|
||||
|
||||
// permissions
|
||||
for (AclEntryPermission perm: perms) {
|
||||
sb.append(perm.name());
|
||||
sb.append('/');
|
||||
}
|
||||
sb.setLength(sb.length()-1); // drop final slash
|
||||
sb.append(':');
|
||||
|
||||
// flags
|
||||
if (!flags.isEmpty()) {
|
||||
for (AclEntryFlag flag: flags) {
|
||||
sb.append(flag.name());
|
||||
sb.append('/');
|
||||
}
|
||||
sb.setLength(sb.length()-1); // drop final slash
|
||||
sb.append(':');
|
||||
}
|
||||
|
||||
// type
|
||||
sb.append(type.name());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
65
jdkSrc/jdk8/java/nio/file/attribute/AclEntryFlag.java
Normal file
65
jdkSrc/jdk8/java/nio/file/attribute/AclEntryFlag.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* Defines the flags for used by the flags component of an ACL {@link AclEntry
|
||||
* entry}.
|
||||
*
|
||||
* <p> In this release, this class does not define flags related to {@link
|
||||
* AclEntryType#AUDIT} and {@link AclEntryType#ALARM} entry types.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum AclEntryFlag {
|
||||
|
||||
/**
|
||||
* Can be placed on a directory and indicates that the ACL entry should be
|
||||
* added to each new non-directory file created.
|
||||
*/
|
||||
FILE_INHERIT,
|
||||
|
||||
/**
|
||||
* Can be placed on a directory and indicates that the ACL entry should be
|
||||
* added to each new directory created.
|
||||
*/
|
||||
DIRECTORY_INHERIT,
|
||||
|
||||
/**
|
||||
* Can be placed on a directory to indicate that the ACL entry should not
|
||||
* be placed on the newly created directory which is inheritable by
|
||||
* subdirectories of the created directory.
|
||||
*/
|
||||
NO_PROPAGATE_INHERIT,
|
||||
|
||||
/**
|
||||
* Can be placed on a directory but does not apply to the directory,
|
||||
* only to newly created files/directories as specified by the
|
||||
* {@link #FILE_INHERIT} and {@link #DIRECTORY_INHERIT} flags.
|
||||
*/
|
||||
INHERIT_ONLY;
|
||||
}
|
130
jdkSrc/jdk8/java/nio/file/attribute/AclEntryPermission.java
Normal file
130
jdkSrc/jdk8/java/nio/file/attribute/AclEntryPermission.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* Defines the permissions for use with the permissions component of an ACL
|
||||
* {@link AclEntry entry}.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum AclEntryPermission {
|
||||
|
||||
/**
|
||||
* Permission to read the data of the file.
|
||||
*/
|
||||
READ_DATA,
|
||||
|
||||
/**
|
||||
* Permission to modify the file's data.
|
||||
*/
|
||||
WRITE_DATA,
|
||||
|
||||
/**
|
||||
* Permission to append data to a file.
|
||||
*/
|
||||
APPEND_DATA,
|
||||
|
||||
/**
|
||||
* Permission to read the named attributes of a file.
|
||||
*
|
||||
* <p> <a href="http://www.ietf.org/rfc/rfc3530.txt">RFC 3530: Network
|
||||
* File System (NFS) version 4 Protocol</a> defines <em>named attributes</em>
|
||||
* as opaque files associated with a file in the file system.
|
||||
*/
|
||||
READ_NAMED_ATTRS,
|
||||
|
||||
/**
|
||||
* Permission to write the named attributes of a file.
|
||||
*
|
||||
* <p> <a href="http://www.ietf.org/rfc/rfc3530.txt">RFC 3530: Network
|
||||
* File System (NFS) version 4 Protocol</a> defines <em>named attributes</em>
|
||||
* as opaque files associated with a file in the file system.
|
||||
*/
|
||||
WRITE_NAMED_ATTRS,
|
||||
|
||||
/**
|
||||
* Permission to execute a file.
|
||||
*/
|
||||
EXECUTE,
|
||||
|
||||
/**
|
||||
* Permission to delete a file or directory within a directory.
|
||||
*/
|
||||
DELETE_CHILD,
|
||||
|
||||
/**
|
||||
* The ability to read (non-acl) file attributes.
|
||||
*/
|
||||
READ_ATTRIBUTES,
|
||||
|
||||
/**
|
||||
* The ability to write (non-acl) file attributes.
|
||||
*/
|
||||
WRITE_ATTRIBUTES,
|
||||
|
||||
/**
|
||||
* Permission to delete the file.
|
||||
*/
|
||||
DELETE,
|
||||
|
||||
/**
|
||||
* Permission to read the ACL attribute.
|
||||
*/
|
||||
READ_ACL,
|
||||
|
||||
/**
|
||||
* Permission to write the ACL attribute.
|
||||
*/
|
||||
WRITE_ACL,
|
||||
|
||||
/**
|
||||
* Permission to change the owner.
|
||||
*/
|
||||
WRITE_OWNER,
|
||||
|
||||
/**
|
||||
* Permission to access file locally at the server with synchronous reads
|
||||
* and writes.
|
||||
*/
|
||||
SYNCHRONIZE;
|
||||
|
||||
/**
|
||||
* Permission to list the entries of a directory (equal to {@link #READ_DATA})
|
||||
*/
|
||||
public static final AclEntryPermission LIST_DIRECTORY = READ_DATA;
|
||||
|
||||
/**
|
||||
* Permission to add a new file to a directory (equal to {@link #WRITE_DATA})
|
||||
*/
|
||||
public static final AclEntryPermission ADD_FILE = WRITE_DATA;
|
||||
|
||||
/**
|
||||
* Permission to create a subdirectory to a directory (equal to {@link #APPEND_DATA})
|
||||
*/
|
||||
public static final AclEntryPermission ADD_SUBDIRECTORY = APPEND_DATA;
|
||||
}
|
56
jdkSrc/jdk8/java/nio/file/attribute/AclEntryType.java
Normal file
56
jdkSrc/jdk8/java/nio/file/attribute/AclEntryType.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* A typesafe enumeration of the access control entry types.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum AclEntryType {
|
||||
/**
|
||||
* Explicitly grants access to a file or directory.
|
||||
*/
|
||||
ALLOW,
|
||||
|
||||
/**
|
||||
* Explicitly denies access to a file or directory.
|
||||
*/
|
||||
DENY,
|
||||
|
||||
/**
|
||||
* Log, in a system dependent way, the access specified in the
|
||||
* permissions component of the ACL entry.
|
||||
*/
|
||||
AUDIT,
|
||||
|
||||
/**
|
||||
* Generate an alarm, in a system dependent way, the access specified in the
|
||||
* permissions component of the ACL entry.
|
||||
*/
|
||||
ALARM
|
||||
}
|
209
jdkSrc/jdk8/java/nio/file/attribute/AclFileAttributeView.java
Normal file
209
jdkSrc/jdk8/java/nio/file/attribute/AclFileAttributeView.java
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that supports reading or updating a file's Access
|
||||
* Control Lists (ACL) or file owner attributes.
|
||||
*
|
||||
* <p> ACLs are used to specify access rights to file system objects. An ACL is
|
||||
* an ordered list of {@link AclEntry access-control-entries}, each specifying a
|
||||
* {@link UserPrincipal} and the level of access for that user principal. This
|
||||
* file attribute view defines the {@link #getAcl() getAcl}, and {@link
|
||||
* #setAcl(List) setAcl} methods to read and write ACLs based on the ACL
|
||||
* model specified in <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530:
|
||||
* Network File System (NFS) version 4 Protocol</i></a>. This file attribute view
|
||||
* is intended for file system implementations that support the NFSv4 ACL model
|
||||
* or have a <em>well-defined</em> mapping between the NFSv4 ACL model and the ACL
|
||||
* model used by the file system. The details of such mapping are implementation
|
||||
* dependent and are therefore unspecified.
|
||||
*
|
||||
* <p> This class also extends {@code FileOwnerAttributeView} so as to define
|
||||
* methods to get and set the file owner.
|
||||
*
|
||||
* <p> When a file system provides access to a set of {@link FileStore
|
||||
* file-systems} that are not homogeneous then only some of the file systems may
|
||||
* support ACLs. The {@link FileStore#supportsFileAttributeView
|
||||
* supportsFileAttributeView} method can be used to test if a file system
|
||||
* supports ACLs.
|
||||
*
|
||||
* <h2>Interoperability</h2>
|
||||
*
|
||||
* RFC 3530 allows for special user identities to be used on platforms that
|
||||
* support the POSIX defined access permissions. The special user identities
|
||||
* are "{@code OWNER@}", "{@code GROUP@}", and "{@code EVERYONE@}". When both
|
||||
* the {@code AclFileAttributeView} and the {@link PosixFileAttributeView}
|
||||
* are supported then these special user identities may be included in ACL {@link
|
||||
* AclEntry entries} that are read or written. The file system's {@link
|
||||
* UserPrincipalLookupService} may be used to obtain a {@link UserPrincipal}
|
||||
* to represent these special identities by invoking the {@link
|
||||
* UserPrincipalLookupService#lookupPrincipalByName lookupPrincipalByName}
|
||||
* method.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we wish to add an entry to an existing ACL to grant "joe" access:
|
||||
* <pre>
|
||||
* // lookup "joe"
|
||||
* UserPrincipal joe = file.getFileSystem().getUserPrincipalLookupService()
|
||||
* .lookupPrincipalByName("joe");
|
||||
*
|
||||
* // get view
|
||||
* AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
|
||||
*
|
||||
* // create ACE to give "joe" read access
|
||||
* AclEntry entry = AclEntry.newBuilder()
|
||||
* .setType(AclEntryType.ALLOW)
|
||||
* .setPrincipal(joe)
|
||||
* .setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES)
|
||||
* .build();
|
||||
*
|
||||
* // read ACL, insert ACE, re-write ACL
|
||||
* List<AclEntry> acl = view.getAcl();
|
||||
* acl.add(0, entry); // insert before any DENY entries
|
||||
* view.setAcl(acl);
|
||||
* </pre>
|
||||
*
|
||||
* <h2> Dynamic Access </h2>
|
||||
* <p> Where dynamic access to file attributes is required, the attributes
|
||||
* supported by this attribute view are as follows:
|
||||
* <blockquote>
|
||||
* <table border="1" cellpadding="8" summary="Supported attributes">
|
||||
* <tr>
|
||||
* <th> Name </th>
|
||||
* <th> Type </th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "acl" </td>
|
||||
* <td> {@link List}<{@link AclEntry}> </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "owner" </td>
|
||||
* <td> {@link UserPrincipal} </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> The {@link Files#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.
|
||||
*
|
||||
* <p> The {@link Files#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.
|
||||
*
|
||||
* <h2> Setting the ACL when creating a file </h2>
|
||||
*
|
||||
* <p> Implementations supporting this attribute view may also support setting
|
||||
* the initial ACL when creating a file or directory. The initial ACL
|
||||
* may be provided to methods such as {@link Files#createFile createFile} or {@link
|
||||
* Files#createDirectory createDirectory} as an {@link FileAttribute} with {@link
|
||||
* FileAttribute#name name} {@code "acl:acl"} and a {@link FileAttribute#value
|
||||
* value} that is the list of {@code AclEntry} objects.
|
||||
*
|
||||
* <p> Where an implementation supports an ACL model that differs from the NFSv4
|
||||
* defined ACL model then setting the initial ACL when creating the file must
|
||||
* translate the ACL to the model supported by the file system. Methods that
|
||||
* create a file should reject (by throwing {@link IOException IOException})
|
||||
* any attempt to create a file that would be less secure as a result of the
|
||||
* translation.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface AclFileAttributeView
|
||||
extends FileOwnerAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of the attribute view. Attribute views of this type
|
||||
* have the name {@code "acl"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Reads the access control list.
|
||||
*
|
||||
* <p> When the file system uses an ACL model that differs from the NFSv4
|
||||
* defined ACL model, then this method returns an ACL that is the translation
|
||||
* of the ACL to the NFSv4 ACL model.
|
||||
*
|
||||
* <p> The returned list is modifiable so as to facilitate changes to the
|
||||
* existing ACL. The {@link #setAcl setAcl} method is used to update
|
||||
* the file's ACL attribute.
|
||||
*
|
||||
* @return an ordered list of {@link AclEntry entries} representing the
|
||||
* ACL
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
|
||||
* or its {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*/
|
||||
List<AclEntry> getAcl() throws IOException;
|
||||
|
||||
/**
|
||||
* Updates (replace) the access control list.
|
||||
*
|
||||
* <p> Where the file system supports Access Control Lists, and it uses an
|
||||
* ACL model that differs from the NFSv4 defined ACL model, then this method
|
||||
* must translate the ACL to the model supported by the file system. This
|
||||
* method should reject (by throwing {@link IOException IOException}) any
|
||||
* attempt to write an ACL that would appear to make the file more secure
|
||||
* than would be the case if the ACL were updated. Where an implementation
|
||||
* does not support a mapping of {@link AclEntryType#AUDIT} or {@link
|
||||
* AclEntryType#ALARM} entries, then this method ignores these entries when
|
||||
* writing the ACL.
|
||||
*
|
||||
* <p> If an ACL entry contains a {@link AclEntry#principal user-principal}
|
||||
* that is not associated with the same provider as this attribute view then
|
||||
* {@link ProviderMismatchException} is thrown. Additional validation, if
|
||||
* any, is implementation dependent.
|
||||
*
|
||||
* <p> If the file system supports other security related file attributes
|
||||
* (such as a file {@link PosixFileAttributes#permissions
|
||||
* access-permissions} for example), the updating the access control list
|
||||
* may also cause these security related attributes to be updated.
|
||||
*
|
||||
* @param acl
|
||||
* the new access control list
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs or the ACL is invalid
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
|
||||
* or its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method denies write access to the file.
|
||||
*/
|
||||
void setAcl(List<AclEntry> acl) throws IOException;
|
||||
}
|
45
jdkSrc/jdk8/java/nio/file/attribute/AttributeView.java
Normal file
45
jdkSrc/jdk8/java/nio/file/attribute/AttributeView.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* An object that provides a read-only or updatable <em>view</em> 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.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface AttributeView {
|
||||
/**
|
||||
* Returns the name of the attribute view.
|
||||
*
|
||||
* @return the name of the attribute view
|
||||
*/
|
||||
String name();
|
||||
}
|
177
jdkSrc/jdk8/java/nio/file/attribute/BasicFileAttributeView.java
Normal file
177
jdkSrc/jdk8/java/nio/file/attribute/BasicFileAttributeView.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that provides a view of a <em>basic set</em> of file
|
||||
* attributes common to many file systems. The basic set of file attributes
|
||||
* consist of <em>mandatory</em> and <em>optional</em> file attributes as
|
||||
* defined by the {@link BasicFileAttributes} interface.
|
||||
|
||||
* <p> The file attributes are retrieved from the file system as a <em>bulk
|
||||
* operation</em> by invoking the {@link #readAttributes() readAttributes} method.
|
||||
* This class also defines the {@link #setTimes setTimes} method to update the
|
||||
* file's time attributes.
|
||||
*
|
||||
* <p> Where dynamic access to file attributes is required, the attributes
|
||||
* supported by this attribute view have the following names and types:
|
||||
* <blockquote>
|
||||
* <table border="1" cellpadding="8" summary="Supported attributes">
|
||||
* <tr>
|
||||
* <th> Name </th>
|
||||
* <th> Type </th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "lastModifiedTime" </td>
|
||||
* <td> {@link FileTime} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "lastAccessTime" </td>
|
||||
* <td> {@link FileTime} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "creationTime" </td>
|
||||
* <td> {@link FileTime} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "size" </td>
|
||||
* <td> {@link Long} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "isRegularFile" </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "isDirectory" </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "isSymbolicLink" </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "isOther" </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "fileKey" </td>
|
||||
* <td> {@link Object} </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> The {@link java.nio.file.Files#getAttribute getAttribute} method may be
|
||||
* used to read any of these attributes as if by invoking the {@link
|
||||
* #readAttributes() readAttributes()} method.
|
||||
*
|
||||
* <p> The {@link java.nio.file.Files#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
|
||||
*/
|
||||
|
||||
public interface BasicFileAttributeView
|
||||
extends FileAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of the attribute view. Attribute views of this type
|
||||
* have the name {@code "basic"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Reads the basic file attributes as a bulk operation.
|
||||
*
|
||||
* <p> It is implementation specific if all file attributes are read as an
|
||||
* atomic operation with respect to other file system operations.
|
||||
*
|
||||
* @return the file attributes
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, its {@link SecurityManager#checkRead(String) checkRead}
|
||||
* method is invoked to check read access to the file
|
||||
*/
|
||||
BasicFileAttributes readAttributes() throws IOException;
|
||||
|
||||
/**
|
||||
* Updates any or all of the file's last modified time, last access time,
|
||||
* and create time attributes.
|
||||
*
|
||||
* <p> This method updates the file's timestamp attributes. The values are
|
||||
* 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 that is
|
||||
* not supported or 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}.
|
||||
*
|
||||
* <p> If any of the {@code lastModifiedTime}, {@code lastAccessTime},
|
||||
* or {@code createTime} parameters has the value {@code null} then the
|
||||
* corresponding timestamp is not changed. An implementation may require to
|
||||
* 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. 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.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to change a file's last access time.
|
||||
* <pre>
|
||||
* Path path = ...
|
||||
* FileTime time = ...
|
||||
* Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes(null, time, null);
|
||||
* </pre>
|
||||
*
|
||||
* @param lastModifiedTime
|
||||
* the new last modified time, or {@code null} to not change the
|
||||
* value
|
||||
* @param lastAccessTime
|
||||
* the last access time, or {@code null} to not change the value
|
||||
* @param createTime
|
||||
* the file's create time, or {@code null} to not change the value
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method is invoked to check write access to the file
|
||||
*
|
||||
* @see java.nio.file.Files#setLastModifiedTime
|
||||
*/
|
||||
void setTimes(FileTime lastModifiedTime,
|
||||
FileTime lastAccessTime,
|
||||
FileTime createTime) throws IOException;
|
||||
}
|
155
jdkSrc/jdk8/java/nio/file/attribute/BasicFileAttributes.java
Normal file
155
jdkSrc/jdk8/java/nio/file/attribute/BasicFileAttributes.java
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* Basic attributes associated with a file in a file system.
|
||||
*
|
||||
* <p> Basic file attributes are attributes that are common to many file systems
|
||||
* and consist of mandatory and optional file attributes as defined by this
|
||||
* interface.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* <pre>
|
||||
* Path file = ...
|
||||
* BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see BasicFileAttributeView
|
||||
*/
|
||||
|
||||
public interface BasicFileAttributes {
|
||||
|
||||
/**
|
||||
* Returns the time of last modification.
|
||||
*
|
||||
* <p> If the file system implementation does not support a time stamp
|
||||
* to indicate the time of last modification then this method returns an
|
||||
* implementation specific default value, typically a {@code FileTime}
|
||||
* representing the epoch (1970-01-01T00:00:00Z).
|
||||
*
|
||||
* @return a {@code FileTime} representing the time the file was last
|
||||
* modified
|
||||
*/
|
||||
FileTime lastModifiedTime();
|
||||
|
||||
/**
|
||||
* Returns the time of last access.
|
||||
*
|
||||
* <p> If the file system implementation does not support a time stamp
|
||||
* to indicate the time of last access then this method returns
|
||||
* an implementation specific default value, typically the {@link
|
||||
* #lastModifiedTime() last-modified-time} or a {@code FileTime}
|
||||
* representing the epoch (1970-01-01T00:00:00Z).
|
||||
*
|
||||
* @return a {@code FileTime} representing the time of last access
|
||||
*/
|
||||
FileTime lastAccessTime();
|
||||
|
||||
/**
|
||||
* Returns the creation time. The creation time is the time that the file
|
||||
* was created.
|
||||
*
|
||||
* <p> If the file system implementation does not support a time stamp
|
||||
* to indicate the time when the file was created then this method returns
|
||||
* an implementation specific default value, typically the {@link
|
||||
* #lastModifiedTime() last-modified-time} or a {@code FileTime}
|
||||
* representing the epoch (1970-01-01T00:00:00Z).
|
||||
*
|
||||
* @return a {@code FileTime} representing the time the file was created
|
||||
*/
|
||||
FileTime creationTime();
|
||||
|
||||
/**
|
||||
* Tells whether the file is a regular file with opaque content.
|
||||
*
|
||||
* @return {@code true} if the file is a regular file with opaque content
|
||||
*/
|
||||
boolean isRegularFile();
|
||||
|
||||
/**
|
||||
* Tells whether the file is a directory.
|
||||
*
|
||||
* @return {@code true} if the file is a directory
|
||||
*/
|
||||
boolean isDirectory();
|
||||
|
||||
/**
|
||||
* Tells whether the file is a symbolic link.
|
||||
*
|
||||
* @return {@code true} if the file is a symbolic link
|
||||
*/
|
||||
boolean isSymbolicLink();
|
||||
|
||||
/**
|
||||
* Tells whether the file is something other than a regular file, directory,
|
||||
* or symbolic link.
|
||||
*
|
||||
* @return {@code true} if the file something other than a regular file,
|
||||
* directory or symbolic link
|
||||
*/
|
||||
boolean isOther();
|
||||
|
||||
/**
|
||||
* Returns the size of the file (in bytes). The size may differ from the
|
||||
* actual size on the file system due to compression, support for sparse
|
||||
* files, or other reasons. The size of files that are not {@link
|
||||
* #isRegularFile regular} files is implementation specific and
|
||||
* therefore unspecified.
|
||||
*
|
||||
* @return the file size, in bytes
|
||||
*/
|
||||
long size();
|
||||
|
||||
/**
|
||||
* 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
|
||||
* it is possible to use an identifier, or a combination of identifiers to
|
||||
* uniquely identify a file. Such identifiers are important for operations
|
||||
* such as file tree traversal in file systems that support <a
|
||||
* href="../package-summary.html#links">symbolic links</a> or file systems
|
||||
* that allow a file to be an entry in more than one directory. On UNIX file
|
||||
* systems, for example, the <em>device ID</em> and <em>inode</em> are
|
||||
* commonly used for such purposes.
|
||||
*
|
||||
* <p> The file key returned by this method can only be guaranteed to be
|
||||
* unique if the file system and files remain static. Whether a file system
|
||||
* re-uses identifiers after a file is deleted is implementation dependent and
|
||||
* therefore unspecified.
|
||||
*
|
||||
* <p> 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.Files#isSameFile same} with
|
||||
* non-{@code null} file keys, then their file keys are equal.
|
||||
*
|
||||
* @return an object that uniquely identifies the given file, or {@code null}
|
||||
*
|
||||
* @see java.nio.file.Files#walkFileTree
|
||||
*/
|
||||
Object fileKey();
|
||||
}
|
179
jdkSrc/jdk8/java/nio/file/attribute/DosFileAttributeView.java
Normal file
179
jdkSrc/jdk8/java/nio/file/attribute/DosFileAttributeView.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that provides a view of the legacy "DOS" file attributes.
|
||||
* These attributes are supported by file systems such as the File Allocation
|
||||
* Table (FAT) format commonly used in <em>consumer devices</em>.
|
||||
*
|
||||
* <p> A {@code DosFileAttributeView} is a {@link BasicFileAttributeView} that
|
||||
* additionally supports access to the set of DOS attribute flags that are used
|
||||
* to indicate if the file is read-only, hidden, a system file, or archived.
|
||||
*
|
||||
* <p> Where dynamic access to file attributes is required, the attributes
|
||||
* supported by this attribute view are as defined by {@code
|
||||
* BasicFileAttributeView}, and in addition, the following attributes are
|
||||
* supported:
|
||||
* <blockquote>
|
||||
* <table border="1" cellpadding="8" summary="Supported attributes">
|
||||
* <tr>
|
||||
* <th> Name </th>
|
||||
* <th> Type </th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> readonly </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> hidden </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> system </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> archive </td>
|
||||
* <td> {@link Boolean} </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> The {@link java.nio.file.Files#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.
|
||||
*
|
||||
* <p> The {@link java.nio.file.Files#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
|
||||
*/
|
||||
|
||||
public interface DosFileAttributeView
|
||||
extends BasicFileAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of the attribute view. Attribute views of this type
|
||||
* have the name {@code "dos"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @throws SecurityException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
DosFileAttributes readAttributes() throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the value of the read-only attribute.
|
||||
*
|
||||
* <p> It is implementation specific if the attribute can be updated as an
|
||||
* atomic operation with respect to other file system operations. An
|
||||
* implementation may, for example, require to read the existing value of
|
||||
* the DOS attribute in order to update this attribute.
|
||||
*
|
||||
* @param value
|
||||
* the new value of the attribute
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default, and a security manager is installed,
|
||||
* its {@link SecurityManager#checkWrite(String) checkWrite} method
|
||||
* is invoked to check write access to the file
|
||||
*/
|
||||
void setReadOnly(boolean value) throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the value of the hidden attribute.
|
||||
*
|
||||
* <p> It is implementation specific if the attribute can be updated as an
|
||||
* atomic operation with respect to other file system operations. An
|
||||
* implementation may, for example, require to read the existing value of
|
||||
* the DOS attribute in order to update this attribute.
|
||||
*
|
||||
* @param value
|
||||
* the new value of the attribute
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default, and a security manager is installed,
|
||||
* its {@link SecurityManager#checkWrite(String) checkWrite} method
|
||||
* is invoked to check write access to the file
|
||||
*/
|
||||
void setHidden(boolean value) throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the value of the system attribute.
|
||||
*
|
||||
* <p> It is implementation specific if the attribute can be updated as an
|
||||
* atomic operation with respect to other file system operations. An
|
||||
* implementation may, for example, require to read the existing value of
|
||||
* the DOS attribute in order to update this attribute.
|
||||
*
|
||||
* @param value
|
||||
* the new value of the attribute
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default, and a security manager is installed,
|
||||
* its {@link SecurityManager#checkWrite(String) checkWrite} method
|
||||
* is invoked to check write access to the file
|
||||
*/
|
||||
void setSystem(boolean value) throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the value of the archive attribute.
|
||||
*
|
||||
* <p> It is implementation specific if the attribute can be updated as an
|
||||
* atomic operation with respect to other file system operations. An
|
||||
* implementation may, for example, require to read the existing value of
|
||||
* the DOS attribute in order to update this attribute.
|
||||
*
|
||||
* @param value
|
||||
* the new value of the attribute
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default, and a security manager is installed,
|
||||
* its {@link SecurityManager#checkWrite(String) checkWrite} method
|
||||
* is invoked to check write access to the file
|
||||
*/
|
||||
void setArchive(boolean value) throws IOException;
|
||||
}
|
84
jdkSrc/jdk8/java/nio/file/attribute/DosFileAttributes.java
Normal file
84
jdkSrc/jdk8/java/nio/file/attribute/DosFileAttributes.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* File attributes associated with a file in a file system that supports
|
||||
* legacy "DOS" attributes.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* <pre>
|
||||
* Path file = ...
|
||||
* DosFileAttributes attrs = Files.readAttributes(file, DosFileAttributes.class);
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface DosFileAttributes
|
||||
extends BasicFileAttributes
|
||||
{
|
||||
/**
|
||||
* Returns the value of the read-only attribute.
|
||||
*
|
||||
* <p> This attribute is often used as a simple access control mechanism
|
||||
* to prevent files from being deleted or updated. Whether the file system
|
||||
* or platform does any enforcement to prevent <em>read-only</em> files
|
||||
* from being updated is implementation specific.
|
||||
*
|
||||
* @return the value of the read-only attribute
|
||||
*/
|
||||
boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Returns the value of the hidden attribute.
|
||||
*
|
||||
* <p> This attribute is often used to indicate if the file is visible to
|
||||
* users.
|
||||
*
|
||||
* @return the value of the hidden attribute
|
||||
*/
|
||||
boolean isHidden();
|
||||
|
||||
/**
|
||||
* Returns the value of the archive attribute.
|
||||
*
|
||||
* <p> This attribute is typically used by backup programs.
|
||||
*
|
||||
* @return the value of the archive attribute
|
||||
*/
|
||||
boolean isArchive();
|
||||
|
||||
/**
|
||||
* Returns the value of the system attribute.
|
||||
*
|
||||
* <p> This attribute is often used to indicate that the file is a component
|
||||
* of the operating system.
|
||||
*
|
||||
* @return the value of the system attribute
|
||||
*/
|
||||
boolean isSystem();
|
||||
}
|
54
jdkSrc/jdk8/java/nio/file/attribute/FileAttribute.java
Normal file
54
jdkSrc/jdk8/java/nio/file/attribute/FileAttribute.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* An object that encapsulates the value of a file attribute that can be set
|
||||
* atomically when creating a new file or directory by invoking the {@link
|
||||
* java.nio.file.Files#createFile createFile} or {@link
|
||||
* java.nio.file.Files#createDirectory createDirectory} methods.
|
||||
*
|
||||
* @param <T> The type of the file attribute value
|
||||
*
|
||||
* @since 1.7
|
||||
* @see PosixFilePermissions#asFileAttribute
|
||||
*/
|
||||
|
||||
public interface FileAttribute<T> {
|
||||
/**
|
||||
* Returns the attribute name.
|
||||
*
|
||||
* @return The attribute name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns the attribute value.
|
||||
*
|
||||
* @return The attribute value
|
||||
*/
|
||||
T value();
|
||||
}
|
42
jdkSrc/jdk8/java/nio/file/attribute/FileAttributeView.java
Normal file
42
jdkSrc/jdk8/java/nio/file/attribute/FileAttributeView.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* An attribute view that is a read-only or updatable view of non-opaque
|
||||
* values associated with a file in a filesystem. This interface is extended or
|
||||
* implemented by specific file attribute views that define methods to read
|
||||
* and/or update the attributes of a file.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see java.nio.file.Files#getFileAttributeView(Path,Class,java.nio.file.LinkOption[])
|
||||
*/
|
||||
|
||||
public interface FileAttributeView
|
||||
extends AttributeView
|
||||
{
|
||||
}
|
101
jdkSrc/jdk8/java/nio/file/attribute/FileOwnerAttributeView.java
Normal file
101
jdkSrc/jdk8/java/nio/file/attribute/FileOwnerAttributeView.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that supports reading or updating the owner of a file.
|
||||
* This file attribute view is intended for file system implementations that
|
||||
* support a file attribute that represents an identity that is the owner of
|
||||
* the file. Often the owner of a file is the identity of the entity that
|
||||
* created the file.
|
||||
*
|
||||
* <p> The {@link #getOwner getOwner} or {@link #setOwner setOwner} methods may
|
||||
* be used to read or update the owner of the file.
|
||||
*
|
||||
* <p> The {@link java.nio.file.Files#getAttribute getAttribute} and
|
||||
* {@link java.nio.file.Files#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
|
||||
*/
|
||||
|
||||
public interface FileOwnerAttributeView
|
||||
extends FileAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of the attribute view. Attribute views of this type
|
||||
* have the name {@code "owner"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Read the file owner.
|
||||
*
|
||||
* <p> It it implementation specific if the file owner can be a {@link
|
||||
* GroupPrincipal group}.
|
||||
*
|
||||
* @return the file owner
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserInformation")</tt> or its
|
||||
* {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*/
|
||||
UserPrincipal getOwner() throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the file owner.
|
||||
*
|
||||
* <p> It it implementation specific if the file owner can be a {@link
|
||||
* GroupPrincipal group}. To ensure consistent and correct behavior
|
||||
* across platforms it is recommended that this method should only be used
|
||||
* to set the file owner to a user principal that is not a group.
|
||||
*
|
||||
* @param owner
|
||||
* the new file owner
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs, or the {@code owner} parameter is a
|
||||
* group and this implementation does not support setting the owner
|
||||
* to a group
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserInformation")</tt> or its
|
||||
* {@link SecurityManager#checkWrite(String) checkWrite} method
|
||||
* denies write access to the file.
|
||||
*/
|
||||
void setOwner(UserPrincipal owner) throws IOException;
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* An attribute view that is a read-only or updatable view of the attributes of
|
||||
* a {@link java.nio.file.FileStore}.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface FileStoreAttributeView
|
||||
extends AttributeView
|
||||
{
|
||||
}
|
475
jdkSrc/jdk8/java/nio/file/attribute/FileTime.java
Normal file
475
jdkSrc/jdk8/java/nio/file/attribute/FileTime.java
Normal file
@@ -0,0 +1,475 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Objects;
|
||||
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
|
||||
* {@link BasicFileAttributes#lastModifiedTime() modified},
|
||||
* {@link BasicFileAttributes#lastAccessTime() accessed},
|
||||
* or {@link BasicFileAttributes#creationTime() created}.
|
||||
*
|
||||
* <p> Instances of this class are immutable.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see java.nio.file.Files#setLastModifiedTime
|
||||
* @see java.nio.file.Files#getLastModifiedTime
|
||||
*/
|
||||
|
||||
public final class FileTime
|
||||
implements Comparable<FileTime>
|
||||
{
|
||||
/**
|
||||
* The unit of granularity to interpret the value. Null if
|
||||
* this {@code FileTime} is converted from an {@code Instant},
|
||||
* the {@code value} and {@code unit} pair will not be used
|
||||
* in this scenario.
|
||||
*/
|
||||
private final TimeUnit unit;
|
||||
|
||||
/**
|
||||
* The value since the epoch; can be negative.
|
||||
*/
|
||||
private final long value;
|
||||
|
||||
/**
|
||||
* The value as Instant (created lazily, if not from an instant)
|
||||
*/
|
||||
private Instant instant;
|
||||
|
||||
/**
|
||||
* The value return by toString (created lazily)
|
||||
*/
|
||||
private String valueAsString;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
private FileTime(long value, TimeUnit unit, Instant instant) {
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
this.instant = instant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code FileTime} representing a value at the given unit of
|
||||
* granularity.
|
||||
*
|
||||
* @param value
|
||||
* the value since the epoch (1970-01-01T00:00:00Z); can be
|
||||
* negative
|
||||
* @param unit
|
||||
* the unit of granularity to interpret the value
|
||||
*
|
||||
* @return a {@code FileTime} representing the given value
|
||||
*/
|
||||
public static FileTime from(long value, TimeUnit unit) {
|
||||
Objects.requireNonNull(unit, "unit");
|
||||
return new FileTime(value, unit, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code FileTime} representing the given value in milliseconds.
|
||||
*
|
||||
* @param value
|
||||
* the value, in milliseconds, since the epoch
|
||||
* (1970-01-01T00:00:00Z); can be negative
|
||||
*
|
||||
* @return a {@code FileTime} representing the given value
|
||||
*/
|
||||
public static FileTime fromMillis(long value) {
|
||||
return new FileTime(value, TimeUnit.MILLISECONDS, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code FileTime} representing the same point of time value
|
||||
* on the time-line as the provided {@code Instant} object.
|
||||
*
|
||||
* @param instant
|
||||
* the instant to convert
|
||||
* @return a {@code FileTime} representing the same point on the time-line
|
||||
* as the provided instant
|
||||
* @since 1.8
|
||||
*/
|
||||
public static FileTime from(Instant instant) {
|
||||
Objects.requireNonNull(instant, "instant");
|
||||
return new FileTime(0, null, instant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value at the given unit of granularity.
|
||||
*
|
||||
* <p> 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) {
|
||||
Objects.requireNonNull(unit, "unit");
|
||||
if (this.unit != null) {
|
||||
return unit.convert(this.value, this.unit);
|
||||
} else {
|
||||
long secs = unit.convert(instant.getEpochSecond(), TimeUnit.SECONDS);
|
||||
if (secs == Long.MIN_VALUE || secs == Long.MAX_VALUE) {
|
||||
return secs;
|
||||
}
|
||||
long nanos = unit.convert(instant.getNano(), TimeUnit.NANOSECONDS);
|
||||
long r = secs + nanos;
|
||||
// Math.addExact() variant
|
||||
if (((secs ^ r) & (nanos ^ r)) < 0) {
|
||||
return (secs < 0) ? Long.MIN_VALUE : Long.MAX_VALUE;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value in milliseconds.
|
||||
*
|
||||
* <p> 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() {
|
||||
if (unit != null) {
|
||||
return unit.toMillis(value);
|
||||
} else {
|
||||
long secs = instant.getEpochSecond();
|
||||
int nanos = instant.getNano();
|
||||
// Math.multiplyExact() variant
|
||||
long r = secs * 1000;
|
||||
long ax = Math.abs(secs);
|
||||
if (((ax | 1000) >>> 31 != 0)) {
|
||||
if ((r / 1000) != secs) {
|
||||
return (secs < 0) ? Long.MIN_VALUE : Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
return r + nanos / 1000_000;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Time unit constants for conversion.
|
||||
*/
|
||||
private static final long HOURS_PER_DAY = 24L;
|
||||
private static final long MINUTES_PER_HOUR = 60L;
|
||||
private static final long SECONDS_PER_MINUTE = 60L;
|
||||
private static final long SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
||||
private static final long SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
private static final long MILLIS_PER_SECOND = 1000L;
|
||||
private static final long MICROS_PER_SECOND = 1000_000L;
|
||||
private static final long NANOS_PER_SECOND = 1000_000_000L;
|
||||
private static final int NANOS_PER_MILLI = 1000_000;
|
||||
private static final int NANOS_PER_MICRO = 1000;
|
||||
// The epoch second of Instant.MIN.
|
||||
private static final long MIN_SECOND = -31557014167219200L;
|
||||
// The epoch second of Instant.MAX.
|
||||
private static final long MAX_SECOND = 31556889864403199L;
|
||||
|
||||
/*
|
||||
* Scale d by m, checking for overflow.
|
||||
*/
|
||||
private static long scale(long d, long m, long over) {
|
||||
if (d > over) return Long.MAX_VALUE;
|
||||
if (d < -over) return Long.MIN_VALUE;
|
||||
return d * m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this {@code FileTime} object to an {@code Instant}.
|
||||
*
|
||||
* <p> The conversion creates an {@code Instant} that represents the
|
||||
* same point on the time-line as this {@code FileTime}.
|
||||
*
|
||||
* <p> {@code FileTime} can store points on the time-line further in the
|
||||
* future and further in the past than {@code Instant}. Conversion
|
||||
* from such further time points saturates to {@link Instant#MIN} if
|
||||
* earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
|
||||
* than {@code Instant.MAX}.
|
||||
*
|
||||
* @return an instant representing the same point on the time-line as
|
||||
* this {@code FileTime} object
|
||||
* @since 1.8
|
||||
*/
|
||||
public Instant toInstant() {
|
||||
if (instant == null) {
|
||||
long secs = 0L;
|
||||
int nanos = 0;
|
||||
switch (unit) {
|
||||
case DAYS:
|
||||
secs = scale(value, SECONDS_PER_DAY,
|
||||
Long.MAX_VALUE/SECONDS_PER_DAY);
|
||||
break;
|
||||
case HOURS:
|
||||
secs = scale(value, SECONDS_PER_HOUR,
|
||||
Long.MAX_VALUE/SECONDS_PER_HOUR);
|
||||
break;
|
||||
case MINUTES:
|
||||
secs = scale(value, SECONDS_PER_MINUTE,
|
||||
Long.MAX_VALUE/SECONDS_PER_MINUTE);
|
||||
break;
|
||||
case SECONDS:
|
||||
secs = value;
|
||||
break;
|
||||
case MILLISECONDS:
|
||||
secs = Math.floorDiv(value, MILLIS_PER_SECOND);
|
||||
nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
|
||||
* NANOS_PER_MILLI;
|
||||
break;
|
||||
case MICROSECONDS:
|
||||
secs = Math.floorDiv(value, MICROS_PER_SECOND);
|
||||
nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
|
||||
* NANOS_PER_MICRO;
|
||||
break;
|
||||
case NANOSECONDS:
|
||||
secs = Math.floorDiv(value, NANOS_PER_SECOND);
|
||||
nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
|
||||
break;
|
||||
default : throw new AssertionError("Unit not handled");
|
||||
}
|
||||
if (secs <= MIN_SECOND)
|
||||
instant = Instant.MIN;
|
||||
else if (secs >= MAX_SECOND)
|
||||
instant = Instant.MAX;
|
||||
else
|
||||
instant = Instant.ofEpochSecond(secs, nanos);
|
||||
}
|
||||
return instant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests this {@code FileTime} for equality with the given object.
|
||||
*
|
||||
* <p> 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.
|
||||
*
|
||||
* <p> 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() {
|
||||
// hashcode of instant representation to satisfy contract with equals
|
||||
return toInstant().hashCode();
|
||||
}
|
||||
|
||||
private long toDays() {
|
||||
if (unit != null) {
|
||||
return unit.toDays(value);
|
||||
} else {
|
||||
return TimeUnit.SECONDS.toDays(toInstant().getEpochSecond());
|
||||
}
|
||||
}
|
||||
|
||||
private long toExcessNanos(long days) {
|
||||
if (unit != null) {
|
||||
return unit.toNanos(value - unit.convert(days, TimeUnit.DAYS));
|
||||
} else {
|
||||
return TimeUnit.SECONDS.toNanos(toInstant().getEpochSecond()
|
||||
- TimeUnit.DAYS.toSeconds(days));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 != null && unit == other.unit) {
|
||||
return Long.compare(value, other.value);
|
||||
} else {
|
||||
// compare using instant representation when unit differs
|
||||
long secs = toInstant().getEpochSecond();
|
||||
long secsOther = other.toInstant().getEpochSecond();
|
||||
int cmp = Long.compare(secs, secsOther);
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
cmp = Long.compare(toInstant().getNano(), other.toInstant().getNano());
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
if (secs != MAX_SECOND && secs != MIN_SECOND) {
|
||||
return 0;
|
||||
}
|
||||
// if both this and other's Instant reps are MIN/MAX,
|
||||
// use daysSinceEpoch and nanosOfDays, which will not
|
||||
// saturate during calculation.
|
||||
long days = toDays();
|
||||
long daysOther = other.toDays();
|
||||
if (days == daysOther) {
|
||||
return Long.compare(toExcessNanos(days), other.toExcessNanos(daysOther));
|
||||
}
|
||||
return Long.compare(days, daysOther);
|
||||
}
|
||||
}
|
||||
|
||||
// days in a 400 year cycle = 146097
|
||||
// days in a 10,000 year cycle = 146097 * 25
|
||||
// seconds per day = 86400
|
||||
private static final long DAYS_PER_10000_YEARS = 146097L * 25L;
|
||||
private static final long SECONDS_PER_10000_YEARS = 146097L * 25L * 86400L;
|
||||
private static final long SECONDS_0000_TO_1970 = ((146097L * 5L) - (30L * 365L + 7L)) * 86400L;
|
||||
|
||||
// append year/month/day/hour/minute/second/nano with width and 0 padding
|
||||
private StringBuilder append(StringBuilder sb, int w, int d) {
|
||||
while (w > 0) {
|
||||
sb.append((char)(d/w + '0'));
|
||||
d = d % w;
|
||||
w /= 10;
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of this {@code FileTime}. The string
|
||||
* is returned in the <a
|
||||
* href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a> format:
|
||||
* <pre>
|
||||
* YYYY-MM-DDThh:mm:ss[.s+]Z
|
||||
* </pre>
|
||||
* 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"}.
|
||||
*
|
||||
* <p> A {@code FileTime} is primarily intended to represent the value of a
|
||||
* file's time stamp. Where used to represent <i>extreme values</i>, where
|
||||
* the year is less than "{@code 0001}" or greater than "{@code 9999}" then
|
||||
* this method deviates from ISO 8601 in the same manner as the
|
||||
* <a href="http://www.w3.org/TR/xmlschema-2/#deviantformats">XML Schema
|
||||
* language</a>. That is, 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() {
|
||||
if (valueAsString == null) {
|
||||
long secs = 0L;
|
||||
int nanos = 0;
|
||||
if (instant == null && unit.compareTo(TimeUnit.SECONDS) >= 0) {
|
||||
secs = unit.toSeconds(value);
|
||||
} else {
|
||||
secs = toInstant().getEpochSecond();
|
||||
nanos = toInstant().getNano();
|
||||
}
|
||||
LocalDateTime ldt;
|
||||
int year = 0;
|
||||
if (secs >= -SECONDS_0000_TO_1970) {
|
||||
// current era
|
||||
long zeroSecs = secs - SECONDS_PER_10000_YEARS + SECONDS_0000_TO_1970;
|
||||
long hi = Math.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1;
|
||||
long lo = Math.floorMod(zeroSecs, SECONDS_PER_10000_YEARS);
|
||||
ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, nanos, ZoneOffset.UTC);
|
||||
year = ldt.getYear() + (int)hi * 10000;
|
||||
} else {
|
||||
// before current era
|
||||
long zeroSecs = secs + SECONDS_0000_TO_1970;
|
||||
long hi = zeroSecs / SECONDS_PER_10000_YEARS;
|
||||
long lo = zeroSecs % SECONDS_PER_10000_YEARS;
|
||||
ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, nanos, ZoneOffset.UTC);
|
||||
year = ldt.getYear() + (int)hi * 10000;
|
||||
}
|
||||
if (year <= 0) {
|
||||
year = year - 1;
|
||||
}
|
||||
int fraction = ldt.getNano();
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
sb.append(year < 0 ? "-" : "");
|
||||
year = Math.abs(year);
|
||||
if (year < 10000) {
|
||||
append(sb, 1000, Math.abs(year));
|
||||
} else {
|
||||
sb.append(String.valueOf(year));
|
||||
}
|
||||
sb.append('-');
|
||||
append(sb, 10, ldt.getMonthValue());
|
||||
sb.append('-');
|
||||
append(sb, 10, ldt.getDayOfMonth());
|
||||
sb.append('T');
|
||||
append(sb, 10, ldt.getHour());
|
||||
sb.append(':');
|
||||
append(sb, 10, ldt.getMinute());
|
||||
sb.append(':');
|
||||
append(sb, 10, ldt.getSecond());
|
||||
if (fraction != 0) {
|
||||
sb.append('.');
|
||||
// adding leading zeros and stripping any trailing zeros
|
||||
int w = 100_000_000;
|
||||
while (fraction % 10 == 0) {
|
||||
fraction /= 10;
|
||||
w /= 10;
|
||||
}
|
||||
append(sb, w, fraction);
|
||||
}
|
||||
sb.append('Z');
|
||||
valueAsString = sb.toString();
|
||||
}
|
||||
return valueAsString;
|
||||
}
|
||||
}
|
42
jdkSrc/jdk8/java/nio/file/attribute/GroupPrincipal.java
Normal file
42
jdkSrc/jdk8/java/nio/file/attribute/GroupPrincipal.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* A {@code UserPrincipal} representing a <em>group identity</em>, used to
|
||||
* determine access rights to objects in a file system. The exact definition of
|
||||
* a group is implementation specific, but typically, it represents an identity
|
||||
* created for administrative purposes so as to determine the access rights for
|
||||
* the members of the group. Whether an entity can be a member of multiple
|
||||
* groups, and whether groups can be nested, are implementation specified and
|
||||
* therefore not specified.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see UserPrincipalLookupService#lookupPrincipalByGroupName
|
||||
*/
|
||||
|
||||
public interface GroupPrincipal extends UserPrincipal { }
|
193
jdkSrc/jdk8/java/nio/file/attribute/PosixFileAttributeView.java
Normal file
193
jdkSrc/jdk8/java/nio/file/attribute/PosixFileAttributeView.java
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.Set;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that provides a view of the file attributes commonly
|
||||
* associated with files on file systems used by operating systems that implement
|
||||
* the Portable Operating System Interface (POSIX) family of standards.
|
||||
*
|
||||
* <p> Operating systems that implement the <a href="http://www.opengroup.org">
|
||||
* POSIX</a> family of standards commonly use file systems that have a
|
||||
* file <em>owner</em>, <em>group-owner</em>, and related <em>access
|
||||
* permissions</em>. This file attribute view provides read and write access
|
||||
* to these attributes.
|
||||
*
|
||||
* <p> The {@link #readAttributes() readAttributes} method is used to read the
|
||||
* file's attributes. The file {@link PosixFileAttributes#owner() owner} is
|
||||
* represented by a {@link UserPrincipal} that is the identity of the file owner
|
||||
* for the purposes of access control. The {@link PosixFileAttributes#group()
|
||||
* group-owner}, represented by a {@link GroupPrincipal}, is the identity of the
|
||||
* group owner, where a group is an identity created for administrative purposes
|
||||
* so as to determine the access rights for the members of the group.
|
||||
*
|
||||
* <p> The {@link PosixFileAttributes#permissions() permissions} attribute is a
|
||||
* set of access permissions. This file attribute view provides access to the nine
|
||||
* permission defined by the {@link PosixFilePermission} class.
|
||||
* These nine permission bits determine the <em>read</em>, <em>write</em>, and
|
||||
* <em>execute</em> access for the file owner, group, and others (others
|
||||
* meaning identities other than the owner and members of the group). Some
|
||||
* operating systems and file systems may provide additional permission bits
|
||||
* but access to these other bits is not defined by this class in this release.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we need to print out the owner and access permissions of a file:
|
||||
* <pre>
|
||||
* Path file = ...
|
||||
* PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class)
|
||||
* .readAttributes();
|
||||
* System.out.format("%s %s%n",
|
||||
* attrs.owner().getName(),
|
||||
* PosixFilePermissions.toString(attrs.permissions()));
|
||||
* </pre>
|
||||
*
|
||||
* <h2> Dynamic Access </h2>
|
||||
* <p> Where dynamic access to file attributes is required, the attributes
|
||||
* supported by this attribute view are as defined by {@link
|
||||
* BasicFileAttributeView} and {@link FileOwnerAttributeView}, and in addition,
|
||||
* the following attributes are supported:
|
||||
* <blockquote>
|
||||
* <table border="1" cellpadding="8" summary="Supported attributes">
|
||||
* <tr>
|
||||
* <th> Name </th>
|
||||
* <th> Type </th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "permissions" </td>
|
||||
* <td> {@link Set}<{@link PosixFilePermission}> </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> "group" </td>
|
||||
* <td> {@link GroupPrincipal} </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> The {@link Files#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.
|
||||
*
|
||||
* <p> The {@link Files#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
|
||||
* #setGroup setGroup} methods respectively.
|
||||
*
|
||||
* <h2> Setting Initial Permissions </h2>
|
||||
* <p> Implementations supporting this attribute view may also support setting
|
||||
* the initial permissions when creating a file or directory. The
|
||||
* initial permissions are provided to the {@link Files#createFile createFile}
|
||||
* or {@link Files#createDirectory createDirectory} methods as a {@link
|
||||
* FileAttribute} with {@link FileAttribute#name name} {@code "posix:permissions"}
|
||||
* and a {@link FileAttribute#value value} that is the set of permissions. The
|
||||
* following example uses the {@link PosixFilePermissions#asFileAttribute
|
||||
* asFileAttribute} method to construct a {@code FileAttribute} when creating a
|
||||
* file:
|
||||
*
|
||||
* <pre>
|
||||
* Path path = ...
|
||||
* Set<PosixFilePermission> perms =
|
||||
* EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ);
|
||||
* Files.createFile(path, PosixFilePermissions.asFileAttribute(perms));
|
||||
* </pre>
|
||||
*
|
||||
* <p> When the access permissions are set at file creation time then the actual
|
||||
* value of the permissions may differ that the value of the attribute object.
|
||||
* The reasons for this are implementation specific. On UNIX systems, for
|
||||
* example, a process has a <em>umask</em> that impacts the permission bits
|
||||
* of newly created files. Where an implementation supports the setting of
|
||||
* the access permissions, and the underlying file system supports access
|
||||
* permissions, then it is required that the value of the actual access
|
||||
* permissions will be equal or less than the value of the attribute
|
||||
* provided to the {@link Files#createFile createFile} or {@link
|
||||
* Files#createDirectory createDirectory} methods. In other words, the file may
|
||||
* be more secure than requested.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface PosixFileAttributeView
|
||||
extends BasicFileAttributeView, FileOwnerAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of the attribute view. Attribute views of this type
|
||||
* have the name {@code "posix"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
|
||||
* or its {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*/
|
||||
@Override
|
||||
PosixFileAttributes readAttributes() throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the file permissions.
|
||||
*
|
||||
* @param perms
|
||||
* the new set of permissions
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* if the sets contains elements that are not of type {@code
|
||||
* PosixFilePermission}
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
|
||||
* or its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method denies write access to the file.
|
||||
*/
|
||||
void setPermissions(Set<PosixFilePermission> perms) throws IOException;
|
||||
|
||||
/**
|
||||
* Updates the file group-owner.
|
||||
*
|
||||
* @param group
|
||||
* the new file group-owner
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, and a security manager is
|
||||
* installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
|
||||
* or its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method denies write access to the file.
|
||||
*/
|
||||
void setGroup(GroupPrincipal group) throws IOException;
|
||||
}
|
75
jdkSrc/jdk8/java/nio/file/attribute/PosixFileAttributes.java
Normal file
75
jdkSrc/jdk8/java/nio/file/attribute/PosixFileAttributes.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* File attributes associated with files on file systems used by operating systems
|
||||
* that implement the Portable Operating System Interface (POSIX) family of
|
||||
* standards.
|
||||
*
|
||||
* <p> The POSIX attributes of a file are retrieved using a {@link
|
||||
* PosixFileAttributeView} by invoking its {@link
|
||||
* PosixFileAttributeView#readAttributes readAttributes} method.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface PosixFileAttributes
|
||||
extends BasicFileAttributes
|
||||
{
|
||||
/**
|
||||
* Returns the owner of the file.
|
||||
*
|
||||
* @return the file owner
|
||||
*
|
||||
* @see PosixFileAttributeView#setOwner
|
||||
*/
|
||||
UserPrincipal owner();
|
||||
|
||||
/**
|
||||
* Returns the group owner of the file.
|
||||
*
|
||||
* @return the file group owner
|
||||
*
|
||||
* @see PosixFileAttributeView#setGroup
|
||||
*/
|
||||
GroupPrincipal group();
|
||||
|
||||
/**
|
||||
* Returns the permissions of the file. The file permissions are returned
|
||||
* as a set of {@link PosixFilePermission} elements. The returned set is a
|
||||
* copy of the file permissions and is modifiable. This allows the result
|
||||
* to be modified and passed to the {@link PosixFileAttributeView#setPermissions
|
||||
* setPermissions} method to update the file's permissions.
|
||||
*
|
||||
* @return the file permissions
|
||||
*
|
||||
* @see PosixFileAttributeView#setPermissions
|
||||
*/
|
||||
Set<PosixFilePermission> permissions();
|
||||
}
|
84
jdkSrc/jdk8/java/nio/file/attribute/PosixFilePermission.java
Normal file
84
jdkSrc/jdk8/java/nio/file/attribute/PosixFilePermission.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
/**
|
||||
* Defines the bits for use with the {@link PosixFileAttributes#permissions()
|
||||
* permissions} attribute.
|
||||
*
|
||||
* <p> The {@link PosixFilePermissions} class defines methods for manipulating
|
||||
* set of permissions.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public enum PosixFilePermission {
|
||||
|
||||
/**
|
||||
* Read permission, owner.
|
||||
*/
|
||||
OWNER_READ,
|
||||
|
||||
/**
|
||||
* Write permission, owner.
|
||||
*/
|
||||
OWNER_WRITE,
|
||||
|
||||
/**
|
||||
* Execute/search permission, owner.
|
||||
*/
|
||||
OWNER_EXECUTE,
|
||||
|
||||
/**
|
||||
* Read permission, group.
|
||||
*/
|
||||
GROUP_READ,
|
||||
|
||||
/**
|
||||
* Write permission, group.
|
||||
*/
|
||||
GROUP_WRITE,
|
||||
|
||||
/**
|
||||
* Execute/search permission, group.
|
||||
*/
|
||||
GROUP_EXECUTE,
|
||||
|
||||
/**
|
||||
* Read permission, others.
|
||||
*/
|
||||
OTHERS_READ,
|
||||
|
||||
/**
|
||||
* Write permission, others.
|
||||
*/
|
||||
OTHERS_WRITE,
|
||||
|
||||
/**
|
||||
* Execute/search permission, others.
|
||||
*/
|
||||
OTHERS_EXECUTE;
|
||||
}
|
180
jdkSrc/jdk8/java/nio/file/attribute/PosixFilePermissions.java
Normal file
180
jdkSrc/jdk8/java/nio/file/attribute/PosixFilePermissions.java
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import static java.nio.file.attribute.PosixFilePermission.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class consists exclusively of static methods that operate on sets of
|
||||
* {@link PosixFilePermission} objects.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public final class PosixFilePermissions {
|
||||
private PosixFilePermissions() { }
|
||||
|
||||
// Write string representation of permission bits to {@code sb}.
|
||||
private static void writeBits(StringBuilder sb, boolean r, boolean w, boolean x) {
|
||||
if (r) {
|
||||
sb.append('r');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
if (w) {
|
||||
sb.append('w');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
if (x) {
|
||||
sb.append('x');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* <p> If the set contains {@code null} or elements that are not of type
|
||||
* {@code PosixFilePermission} then these elements are ignored.
|
||||
*
|
||||
* @param perms
|
||||
* the set of permissions
|
||||
*
|
||||
* @return the string representation of the permission set
|
||||
*/
|
||||
public static String toString(Set<PosixFilePermission> perms) {
|
||||
StringBuilder sb = new StringBuilder(9);
|
||||
writeBits(sb, perms.contains(OWNER_READ), perms.contains(OWNER_WRITE),
|
||||
perms.contains(OWNER_EXECUTE));
|
||||
writeBits(sb, perms.contains(GROUP_READ), perms.contains(GROUP_WRITE),
|
||||
perms.contains(GROUP_EXECUTE));
|
||||
writeBits(sb, perms.contains(OTHERS_READ), perms.contains(OTHERS_WRITE),
|
||||
perms.contains(OTHERS_EXECUTE));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static boolean isSet(char c, char setValue) {
|
||||
if (c == setValue)
|
||||
return true;
|
||||
if (c == '-')
|
||||
return false;
|
||||
throw new IllegalArgumentException("Invalid mode");
|
||||
}
|
||||
private static boolean isR(char c) { return isSet(c, 'r'); }
|
||||
private static boolean isW(char c) { return isSet(c, 'w'); }
|
||||
private static boolean isX(char c) { return isSet(c, 'x'); }
|
||||
|
||||
/**
|
||||
* Returns the set of permissions corresponding to a given {@code String}
|
||||
* representation.
|
||||
*
|
||||
* <p> The {@code perms} parameter is a {@code String} representing the
|
||||
* permissions. It has 9 characters that are interpreted as three sets of
|
||||
* three. The first set refers to the owner's permissions; the next to the
|
||||
* group permissions and the last to others. Within each set, the first
|
||||
* character is {@code 'r'} to indicate permission to read, the second
|
||||
* character is {@code 'w'} to indicate permission to write, and the third
|
||||
* character is {@code 'x'} for execute permission. Where a permission is
|
||||
* not set then the corresponding character is set to {@code '-'}.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we require the set of permissions that indicate the owner has read,
|
||||
* write, and execute permissions, the group has read and execute permissions
|
||||
* and others have none.
|
||||
* <pre>
|
||||
* Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-x---");
|
||||
* </pre>
|
||||
*
|
||||
* @param perms
|
||||
* string representing a set of permissions
|
||||
*
|
||||
* @return the resulting set of permissions
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the string cannot be converted to a set of permissions
|
||||
*
|
||||
* @see #toString(Set)
|
||||
*/
|
||||
public static Set<PosixFilePermission> fromString(String perms) {
|
||||
if (perms.length() != 9)
|
||||
throw new IllegalArgumentException("Invalid mode");
|
||||
Set<PosixFilePermission> result = EnumSet.noneOf(PosixFilePermission.class);
|
||||
if (isR(perms.charAt(0))) result.add(OWNER_READ);
|
||||
if (isW(perms.charAt(1))) result.add(OWNER_WRITE);
|
||||
if (isX(perms.charAt(2))) result.add(OWNER_EXECUTE);
|
||||
if (isR(perms.charAt(3))) result.add(GROUP_READ);
|
||||
if (isW(perms.charAt(4))) result.add(GROUP_WRITE);
|
||||
if (isX(perms.charAt(5))) result.add(GROUP_EXECUTE);
|
||||
if (isR(perms.charAt(6))) result.add(OTHERS_READ);
|
||||
if (isW(perms.charAt(7))) result.add(OTHERS_WRITE);
|
||||
if (isX(perms.charAt(8))) result.add(OTHERS_EXECUTE);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link FileAttribute}, encapsulating a copy of the given file
|
||||
* permissions, suitable for passing to the {@link java.nio.file.Files#createFile
|
||||
* createFile} or {@link java.nio.file.Files#createDirectory createDirectory}
|
||||
* methods.
|
||||
*
|
||||
* @param perms
|
||||
* the set of permissions
|
||||
*
|
||||
* @return an attribute encapsulating the given file permissions with
|
||||
* {@link FileAttribute#name name} {@code "posix:permissions"}
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* if the set contains elements that are not of type {@code
|
||||
* PosixFilePermission}
|
||||
*/
|
||||
public static FileAttribute<Set<PosixFilePermission>>
|
||||
asFileAttribute(Set<PosixFilePermission> perms)
|
||||
{
|
||||
// copy set and check for nulls (CCE will be thrown if an element is not
|
||||
// a PosixFilePermission)
|
||||
perms = new HashSet<PosixFilePermission>(perms);
|
||||
for (PosixFilePermission p: perms) {
|
||||
if (p == null)
|
||||
throw new NullPointerException();
|
||||
}
|
||||
final Set<PosixFilePermission> value = perms;
|
||||
return new FileAttribute<Set<PosixFilePermission>>() {
|
||||
@Override
|
||||
public String name() {
|
||||
return "posix:permissions";
|
||||
}
|
||||
@Override
|
||||
public Set<PosixFilePermission> value() {
|
||||
return Collections.unmodifiableSet(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file attribute view that provides a view of a file's user-defined
|
||||
* attributes, sometimes known as <em>extended attributes</em>. User-defined
|
||||
* file attributes are used to store metadata with a file that is not meaningful
|
||||
* to the file system. It is primarily intended for file system implementations
|
||||
* that support such a capability directly but may be emulated. The details of
|
||||
* such emulation are highly implementation specific and therefore not specified.
|
||||
*
|
||||
* <p> This {@code FileAttributeView} provides a view of a file's user-defined
|
||||
* attributes as a set of name/value pairs, where the attribute name is
|
||||
* represented by a {@code String}. An implementation may require to encode and
|
||||
* decode from the platform or file system representation when accessing the
|
||||
* attribute. The value has opaque content. This attribute view defines the
|
||||
* {@link #read read} and {@link #write write} methods to read the value into
|
||||
* or write from a {@link ByteBuffer}. This {@code FileAttributeView} is not
|
||||
* intended for use where the size of an attribute value is larger than {@link
|
||||
* Integer#MAX_VALUE}.
|
||||
*
|
||||
* <p> User-defined attributes may be used in some implementations to store
|
||||
* security related attributes so consequently, in the case of the default
|
||||
* provider at least, all methods that access user-defined attributes require the
|
||||
* {@code RuntimePermission("accessUserDefinedAttributes")} permission when a
|
||||
* security manager is installed.
|
||||
*
|
||||
* <p> The {@link java.nio.file.FileStore#supportsFileAttributeView
|
||||
* supportsFileAttributeView} method may be used to test if a specific {@link
|
||||
* java.nio.file.FileStore FileStore} supports the storage of user-defined
|
||||
* attributes.
|
||||
*
|
||||
* <p> Where dynamic access to file attributes is required, the {@link
|
||||
* java.nio.file.Files#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.Files#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
|
||||
*/
|
||||
|
||||
public interface UserDefinedFileAttributeView
|
||||
extends FileAttributeView
|
||||
{
|
||||
/**
|
||||
* Returns the name of this attribute view. Attribute views of this type
|
||||
* have the name {@code "user"}.
|
||||
*/
|
||||
@Override
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns a list containing the names of the user-defined attributes.
|
||||
*
|
||||
* @return An unmodifiable list containing the names of the file's
|
||||
* user-defined
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserDefinedAttributes")</tt>
|
||||
* or its {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*/
|
||||
List<String> list() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the size of the value of a user-defined attribute.
|
||||
*
|
||||
* @param name
|
||||
* The attribute name
|
||||
*
|
||||
* @return The size of the attribute value, in bytes.
|
||||
*
|
||||
* @throws ArithmeticException
|
||||
* If the size of the attribute is larger than {@link Integer#MAX_VALUE}
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserDefinedAttributes")</tt>
|
||||
* or its {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*/
|
||||
int size(String name) throws IOException;
|
||||
|
||||
/**
|
||||
* Read the value of a user-defined attribute into a buffer.
|
||||
*
|
||||
* <p> This method reads the value of the attribute into the given buffer
|
||||
* as a sequence of bytes, failing if the number of bytes remaining in
|
||||
* the buffer is insufficient to read the complete attribute value. The
|
||||
* number of bytes transferred into the buffer is {@code n}, where {@code n}
|
||||
* is the size of the attribute value. The first byte in the sequence is at
|
||||
* index {@code p} and the last byte is at index {@code p + n - 1}, where
|
||||
* {@code p} is the buffer's position. Upon return the buffer's position
|
||||
* will be equal to {@code p + n}; its limit will not have changed.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to read a file's MIME type that is stored as a user-defined
|
||||
* attribute with the name "{@code user.mimetype}".
|
||||
* <pre>
|
||||
* UserDefinedFileAttributeView view =
|
||||
* Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
|
||||
* String name = "user.mimetype";
|
||||
* ByteBuffer buf = ByteBuffer.allocate(view.size(name));
|
||||
* view.read(name, buf);
|
||||
* buf.flip();
|
||||
* String value = Charset.defaultCharset().decode(buf).toString();
|
||||
* </pre>
|
||||
*
|
||||
* @param name
|
||||
* The attribute name
|
||||
* @param dst
|
||||
* The destination buffer
|
||||
*
|
||||
* @return The number of bytes read, possibly zero
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the destination buffer is read-only
|
||||
* @throws IOException
|
||||
* If an I/O error occurs or there is insufficient space in the
|
||||
* destination buffer for the attribute value
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserDefinedAttributes")</tt>
|
||||
* or its {@link SecurityManager#checkRead(String) checkRead} method
|
||||
* denies read access to the file.
|
||||
*
|
||||
* @see #size
|
||||
*/
|
||||
int read(String name, ByteBuffer dst) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes the value of a user-defined attribute from a buffer.
|
||||
*
|
||||
* <p> This method writes the value of the attribute from a given buffer as
|
||||
* a sequence of bytes. The size of the value to transfer is {@code r},
|
||||
* where {@code r} is the number of bytes remaining in the buffer, that is
|
||||
* {@code src.remaining()}. The sequence of bytes is transferred from the
|
||||
* buffer starting at index {@code p}, where {@code p} is the buffer's
|
||||
* position. Upon return, the buffer's position will be equal to {@code
|
||||
* p + n}, where {@code n} is the number of bytes transferred; its limit
|
||||
* will not have changed.
|
||||
*
|
||||
* <p> If an attribute of the given name already exists then its value is
|
||||
* replaced. If the attribute does not exist then it is created. If it
|
||||
* implementation specific if a test to check for the existence of the
|
||||
* attribute and the creation of attribute are atomic with respect to other
|
||||
* file system activities.
|
||||
*
|
||||
* <p> Where there is insufficient space to store the attribute, or the
|
||||
* attribute name or value exceed an implementation specific maximum size
|
||||
* then an {@code IOException} is thrown.
|
||||
*
|
||||
* <p> <b>Usage Example:</b>
|
||||
* Suppose we want to write a file's MIME type as a user-defined attribute:
|
||||
* <pre>
|
||||
* UserDefinedFileAttributeView view =
|
||||
* FIles.getFileAttributeView(path, UserDefinedFileAttributeView.class);
|
||||
* view.write("user.mimetype", Charset.defaultCharset().encode("text/html"));
|
||||
* </pre>
|
||||
*
|
||||
* @param name
|
||||
* The attribute name
|
||||
* @param src
|
||||
* The buffer containing the attribute value
|
||||
*
|
||||
* @return The number of bytes written, possibly zero
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserDefinedAttributes")</tt>
|
||||
* or its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method denies write access to the file.
|
||||
*/
|
||||
int write(String name, ByteBuffer src) throws IOException;
|
||||
|
||||
/**
|
||||
* Deletes a user-defined attribute.
|
||||
*
|
||||
* @param name
|
||||
* The attribute name
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs or the attribute does not exist
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, a security manager is
|
||||
* installed, and it denies {@link
|
||||
* RuntimePermission}<tt>("accessUserDefinedAttributes")</tt>
|
||||
* or its {@link SecurityManager#checkWrite(String) checkWrite}
|
||||
* method denies write access to the file.
|
||||
*/
|
||||
void delete(String name) throws IOException;
|
||||
}
|
54
jdkSrc/jdk8/java/nio/file/attribute/UserPrincipal.java
Normal file
54
jdkSrc/jdk8/java/nio/file/attribute/UserPrincipal.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
/**
|
||||
* A {@code Principal} representing an identity used to determine access rights
|
||||
* to objects in a file system.
|
||||
*
|
||||
* <p> On many platforms and file systems an entity requires appropriate access
|
||||
* rights or permissions in order to access objects in a file system. The
|
||||
* access rights are generally performed by checking the identity of the entity.
|
||||
* For example, on implementations that use Access Control Lists (ACLs) to
|
||||
* enforce privilege separation then a file in the file system may have an
|
||||
* associated ACL that determines the access rights of identities specified in
|
||||
* the ACL.
|
||||
*
|
||||
* <p> A {@code UserPrincipal} object is an abstract representation of an
|
||||
* identity. It has a {@link #getName() name} that is typically the username or
|
||||
* account name that it represents. User principal objects may be obtained using
|
||||
* a {@link UserPrincipalLookupService}, or returned by {@link
|
||||
* FileAttributeView} implementations that provide access to identity related
|
||||
* attributes. For example, the {@link AclFileAttributeView} and {@link
|
||||
* PosixFileAttributeView} provide access to a file's {@link
|
||||
* PosixFileAttributes#owner owner}.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public interface UserPrincipal extends Principal { }
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An object to lookup user and group principals by name. A {@link UserPrincipal}
|
||||
* represents an identity that may be used to determine access rights to objects
|
||||
* in a file system. A {@link GroupPrincipal} represents a <em>group identity</em>.
|
||||
* A {@code UserPrincipalLookupService} defines methods to lookup identities by
|
||||
* name or group name (which are typically user or account names). Whether names
|
||||
* and group names are case sensitive or not depends on the implementation.
|
||||
* The exact definition of a group is implementation specific but typically a
|
||||
* group represents an identity created for administrative purposes so as to
|
||||
* determine the access rights for the members of the group. In particular it is
|
||||
* implementation specific if the <em>namespace</em> for names and groups is the
|
||||
* same or is distinct. To ensure consistent and correct behavior across
|
||||
* platforms it is recommended that this API be used as if the namespaces are
|
||||
* distinct. In other words, the {@link #lookupPrincipalByName
|
||||
* lookupPrincipalByName} should be used to lookup users, and {@link
|
||||
* #lookupPrincipalByGroupName lookupPrincipalByGroupName} should be used to
|
||||
* lookup groups.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see java.nio.file.FileSystem#getUserPrincipalLookupService
|
||||
*/
|
||||
|
||||
public abstract class UserPrincipalLookupService {
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected UserPrincipalLookupService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a user principal by name.
|
||||
*
|
||||
* @param name
|
||||
* the string representation of the user principal to lookup
|
||||
*
|
||||
* @return a user principal
|
||||
*
|
||||
* @throws UserPrincipalNotFoundException
|
||||
* the principal does not exist
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, and a security manager is
|
||||
* installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt>
|
||||
*/
|
||||
public abstract UserPrincipal lookupPrincipalByName(String name)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Lookup a group principal by group name.
|
||||
*
|
||||
* <p> Where an implementation does not support any notion of group then
|
||||
* this method always throws {@link UserPrincipalNotFoundException}. Where
|
||||
* the namespace for user accounts and groups is the same, then this method
|
||||
* is identical to invoking {@link #lookupPrincipalByName
|
||||
* lookupPrincipalByName}.
|
||||
*
|
||||
* @param group
|
||||
* the string representation of the group to lookup
|
||||
*
|
||||
* @return a group principal
|
||||
*
|
||||
* @throws UserPrincipalNotFoundException
|
||||
* the principal does not exist or is not a group
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* In the case of the default provider, and a security manager is
|
||||
* installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt>
|
||||
*/
|
||||
public abstract GroupPrincipal lookupPrincipalByGroupName(String group)
|
||||
throws IOException;
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Checked exception thrown when a lookup of {@link UserPrincipal} fails because
|
||||
* the principal does not exist.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public class UserPrincipalNotFoundException
|
||||
extends IOException
|
||||
{
|
||||
static final long serialVersionUID = -5369283889045833024L;
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*
|
||||
* @param name
|
||||
* the principal name; may be {@code null}
|
||||
*/
|
||||
public UserPrincipalNotFoundException(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user principal name if this exception was created with the
|
||||
* user principal name that was not found, otherwise <tt>null</tt>.
|
||||
*
|
||||
* @return the user principal name or {@code null}
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
110
jdkSrc/jdk8/java/nio/file/attribute/package-info.java
Normal file
110
jdkSrc/jdk8/java/nio/file/attribute/package-info.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interfaces and classes providing access to file and file system attributes.
|
||||
*
|
||||
* <blockquote><table cellspacing=1 cellpadding=0 summary="Attribute views">
|
||||
* <tr><th align="left">Attribute views</th><th align="left">Description</th></tr>
|
||||
* <tr><td valign=top><tt><i>{@link java.nio.file.attribute.AttributeView}</i></tt></td>
|
||||
* <td>Can read or update non-opaque values associated with objects in a file system</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.FileAttributeView}</i></tt></td>
|
||||
* <td>Can read or update file attributes</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.BasicFileAttributeView} </i></tt></td>
|
||||
* <td>Can read or update a basic set of file attributes</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.PosixFileAttributeView} </i></tt></td>
|
||||
* <td>Can read or update POSIX defined file attributes</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.DosFileAttributeView} </i></tt></td>
|
||||
* <td>Can read or update FAT file attributes</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.FileOwnerAttributeView} </i></tt></td>
|
||||
* <td>Can read or update the owner of a file</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.AclFileAttributeView} </i></tt></td>
|
||||
* <td>Can read or update Access Control Lists</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.UserDefinedFileAttributeView} </i></tt></td>
|
||||
* <td>Can read or update user-defined file attributes</td></tr>
|
||||
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.FileStoreAttributeView}</i></tt></td>
|
||||
* <td>Can read or update file system attributes</td></tr>
|
||||
* </table></blockquote>
|
||||
*
|
||||
* <p> An attribute view provides a read-only or updatable view of the non-opaque
|
||||
* values, or <em>metadata</em>, associated with objects in a file system.
|
||||
* The {@link java.nio.file.attribute.FileAttributeView} interface is
|
||||
* extended by several other interfaces that that views to specific sets of file
|
||||
* attributes. {@code FileAttributeViews} are selected by invoking the {@link
|
||||
* java.nio.file.Files#getFileAttributeView} method with a
|
||||
* <em>type-token</em> to identify the required view. Views can also be identified
|
||||
* by name. The {@link java.nio.file.attribute.FileStoreAttributeView} interface
|
||||
* provides access to file store attributes. A {@code FileStoreAttributeView} of
|
||||
* a given type is obtained by invoking the {@link
|
||||
* java.nio.file.FileStore#getFileStoreAttributeView} method.
|
||||
*
|
||||
* <p> The {@link java.nio.file.attribute.BasicFileAttributeView}
|
||||
* class defines methods to read and update a <em>basic</em> set of file
|
||||
* attributes that are common to many file systems.
|
||||
*
|
||||
* <p> The {@link java.nio.file.attribute.PosixFileAttributeView}
|
||||
* interface extends {@code BasicFileAttributeView} by defining methods
|
||||
* to access the file attributes commonly used by file systems and operating systems
|
||||
* that implement the Portable Operating System Interface (POSIX) family of
|
||||
* standards.
|
||||
*
|
||||
* <p> The {@link java.nio.file.attribute.DosFileAttributeView}
|
||||
* class extends {@code BasicFileAttributeView} by defining methods to
|
||||
* access the legacy "DOS" file attributes supported on file systems such as File
|
||||
* Allocation Tabl (FAT), commonly used in consumer devices.
|
||||
*
|
||||
* <p> The {@link java.nio.file.attribute.AclFileAttributeView}
|
||||
* class defines methods to read and write the Access Control List (ACL)
|
||||
* file attribute. The ACL model used by this file attribute view is based
|
||||
* on the model defined by <a href="http://www.ietf.org/rfc/rfc3530.txt">
|
||||
* <i>RFC 3530: Network File System (NFS) version 4 Protocol</i></a>.
|
||||
*
|
||||
* <p> In addition to attribute views, this package also defines classes and
|
||||
* interfaces that are used when accessing attributes:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li> The {@link java.nio.file.attribute.UserPrincipal} and
|
||||
* {@link java.nio.file.attribute.GroupPrincipal} interfaces represent an
|
||||
* identity or group identity. </li>
|
||||
*
|
||||
* <li> The {@link java.nio.file.attribute.UserPrincipalLookupService}
|
||||
* interface defines methods to lookup user or group principals. </li>
|
||||
*
|
||||
* <li> The {@link java.nio.file.attribute.FileAttribute} interface
|
||||
* represents the value of an attribute for cases where the attribute value is
|
||||
* required to be set atomically when creating an object in the file system. </li>
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
|
||||
* or method in any class or interface in this package will cause a {@link
|
||||
* java.lang.NullPointerException NullPointerException} to be thrown.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
package java.nio.file.attribute;
|
117
jdkSrc/jdk8/java/nio/file/package-info.java
Normal file
117
jdkSrc/jdk8/java/nio/file/package-info.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines interfaces and classes for the Java virtual machine to access files,
|
||||
* file attributes, and file systems.
|
||||
*
|
||||
* <p> The java.nio.file package defines classes to access files and file
|
||||
* systems. The API to access file and file system attributes is defined in the
|
||||
* {@link java.nio.file.attribute} package. The {@link java.nio.file.spi}
|
||||
* package is used by service provider implementors wishing to extend the
|
||||
* platform default provider, or to construct other provider implementations. </p>
|
||||
*
|
||||
* <h3><a name="links">Symbolic Links</a></h3>
|
||||
* <p> Many operating systems and file systems support for <em>symbolic links</em>.
|
||||
* A symbolic link is a special file that serves as a reference to another file.
|
||||
* For the most part, symbolic links are transparent to applications and
|
||||
* operations on symbolic links are automatically redirected to the <em>target</em>
|
||||
* of the link. Exceptions to this are when a symbolic link is deleted or
|
||||
* renamed/moved in which case the link is deleted or removed rather than the
|
||||
* target of the link. This package includes support for symbolic links where
|
||||
* implementations provide these semantics. File systems may support other types
|
||||
* that are semantically close but support for these other types of links is
|
||||
* not included in this package. </p>
|
||||
*
|
||||
* <h3><a name="interop">Interoperability</a></h3>
|
||||
* <p> The {@link java.io.File} class defines the {@link java.io.File#toPath
|
||||
* toPath} method to construct a {@link java.nio.file.Path} by converting
|
||||
* the abstract path represented by the {@code java.io.File} object. The resulting
|
||||
* {@code Path} can be used to operate on the same file as the {@code File}
|
||||
* object. The {@code Path} specification provides further information
|
||||
* on the <a href="Path.html#interop">interoperability</a> between {@code Path}
|
||||
* and {@code java.io.File} objects. </p>
|
||||
*
|
||||
* <h3>Visibility</h3>
|
||||
* <p> The view of the files and file system provided by classes in this package are
|
||||
* guaranteed to be consistent with other views provided by other instances in the
|
||||
* same Java virtual machine. The view may or may not, however, be consistent with
|
||||
* the view of the file system as seen by other concurrently running programs due
|
||||
* to caching performed by the underlying operating system and delays induced by
|
||||
* network-filesystem protocols. This is true regardless of the language in which
|
||||
* these other programs are written, and whether they are running on the same machine
|
||||
* or on some other machine. The exact nature of any such inconsistencies are
|
||||
* system-dependent and are therefore unspecified. </p>
|
||||
*
|
||||
* <h3><a name="integrity">Synchronized I/O File Integrity</a></h3>
|
||||
* <p> The {@link java.nio.file.StandardOpenOption#SYNC SYNC} and {@link
|
||||
* java.nio.file.StandardOpenOption#DSYNC DSYNC} options are used when opening a file
|
||||
* to require that updates to the file are written synchronously to the underlying
|
||||
* storage device. In the case of the default provider, and the file resides on
|
||||
* a local storage device, and the {@link java.nio.channels.SeekableByteChannel
|
||||
* seekable} channel is connected to a file that was opened with one of these
|
||||
* options, then an invocation of the {@link
|
||||
* java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer) write}
|
||||
* method is only guaranteed to return when all changes made to the file
|
||||
* by that invocation have been written to the device. These options are useful
|
||||
* for ensuring that critical information is not lost in the event of a system
|
||||
* crash. If the file does not reside on a local device then no such guarantee
|
||||
* is made. Whether this guarantee is possible with other {@link
|
||||
* java.nio.file.spi.FileSystemProvider provider} implementations is provider
|
||||
* specific. </p>
|
||||
*
|
||||
* <h3>General Exceptions</h3>
|
||||
* <p> Unless otherwise noted, passing a {@code null} argument to a constructor
|
||||
* or method of any class or interface in this package will cause a {@link
|
||||
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally,
|
||||
* invoking a method with a collection containing a {@code null} element will
|
||||
* cause a {@code NullPointerException}, unless otherwise specified. </p>
|
||||
*
|
||||
* <p> Unless otherwise noted, methods that attempt to access the file system
|
||||
* will throw {@link java.nio.file.ClosedFileSystemException} when invoked on
|
||||
* objects associated with a {@link java.nio.file.FileSystem} that has been
|
||||
* {@link java.nio.file.FileSystem#close closed}. Additionally, any methods
|
||||
* that attempt write access to a file system will throw {@link
|
||||
* java.nio.file.ReadOnlyFileSystemException} when invoked on an object associated
|
||||
* with a {@link java.nio.file.FileSystem} that only provides read-only
|
||||
* access. </p>
|
||||
*
|
||||
* <p> Unless otherwise noted, invoking a method of any class or interface in
|
||||
* this package created by one {@link java.nio.file.spi.FileSystemProvider
|
||||
* provider} with a parameter that is an object created by another provider,
|
||||
* will throw {@link java.nio.file.ProviderMismatchException}. </p>
|
||||
*
|
||||
* <h3>Optional Specific Exceptions</h3>
|
||||
* Most of the methods defined by classes in this package that access the
|
||||
* file system specify that {@link java.io.IOException} be thrown when an I/O
|
||||
* error occurs. In some cases, these methods define specific I/O exceptions
|
||||
* for common cases. These exceptions, noted as <i>optional specific exceptions</i>,
|
||||
* are thrown by the implementation where it can detect the specific error.
|
||||
* Where the specific error cannot be detected then the more general {@code
|
||||
* IOException} is thrown.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
package java.nio.file;
|
1103
jdkSrc/jdk8/java/nio/file/spi/FileSystemProvider.java
Normal file
1103
jdkSrc/jdk8/java/nio/file/spi/FileSystemProvider.java
Normal file
File diff suppressed because it is too large
Load Diff
106
jdkSrc/jdk8/java/nio/file/spi/FileTypeDetector.java
Normal file
106
jdkSrc/jdk8/java/nio/file/spi/FileTypeDetector.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.nio.file.spi;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A file type detector for probing a file to guess its file type.
|
||||
*
|
||||
* <p> A file type detector is a concrete implementation of this class, has a
|
||||
* zero-argument constructor, and implements the abstract methods specified
|
||||
* below.
|
||||
*
|
||||
* <p> The means by which a file type detector determines the file type is
|
||||
* highly implementation specific. A simple implementation might examine the
|
||||
* <em>file extension</em> (a convention used in some platforms) and map it to
|
||||
* a file type. In other cases, the file type may be stored as a file <a
|
||||
* href="../attribute/package-summary.html"> attribute</a> or the bytes in a
|
||||
* file may be examined to guess its file type.
|
||||
*
|
||||
* @see java.nio.file.Files#probeContentType(Path)
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
public abstract class FileTypeDetector {
|
||||
|
||||
private static Void checkPermission() {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkPermission(new RuntimePermission("fileTypeDetector"));
|
||||
return null;
|
||||
}
|
||||
private FileTypeDetector(Void ignore) { }
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and it denies
|
||||
* {@link RuntimePermission}<tt>("fileTypeDetector")</tt>
|
||||
*/
|
||||
protected FileTypeDetector() {
|
||||
this(checkPermission());
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes the given file to guess its content type.
|
||||
*
|
||||
* <p> The means by which this method determines the file type is highly
|
||||
* implementation specific. It may simply examine the file name, it may use
|
||||
* a file <a href="../attribute/package-summary.html">attribute</a>,
|
||||
* or it may examines bytes in the file.
|
||||
*
|
||||
* <p> The probe result is the string form of the value of a
|
||||
* Multipurpose Internet Mail Extension (MIME) content type as
|
||||
* defined by <a href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045:
|
||||
* Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet
|
||||
* Message Bodies</i></a>. The string must be parsable according to the
|
||||
* grammar in the RFC 2045.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file to probe
|
||||
*
|
||||
* @return The content type or {@code null} if the file type is not
|
||||
* recognized
|
||||
*
|
||||
* @throws IOException
|
||||
* An I/O error occurs
|
||||
* @throws SecurityException
|
||||
* If the implementation requires to access the file, and a
|
||||
* security manager is installed, and it denies an unspecified
|
||||
* permission required by a file system provider implementation.
|
||||
* If the file reference is associated with the default file system
|
||||
* provider then the {@link SecurityManager#checkRead(String)} method
|
||||
* is invoked to check read access to the file.
|
||||
*
|
||||
* @see java.nio.file.Files#probeContentType
|
||||
*/
|
||||
public abstract String probeContentType(Path path)
|
||||
throws IOException;
|
||||
}
|
39
jdkSrc/jdk8/java/nio/file/spi/package-info.java
Normal file
39
jdkSrc/jdk8/java/nio/file/spi/package-info.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Service-provider classes for the <tt>{@link java.nio.file}</tt> package.
|
||||
*
|
||||
* <p> Only developers who are defining new file system providers or file type
|
||||
* detectors should need to make direct use of this package. </p>
|
||||
*
|
||||
* <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
|
||||
* or method in any class or interface in this package will cause a {@link
|
||||
* java.lang.NullPointerException NullPointerException} to be thrown.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
package java.nio.file.spi;
|
Reference in New Issue
Block a user