author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8808 | fc799c458da8 |
child 11286 | a49be3718db9 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8808
diff
changeset
|
2 |
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
package java.nio.file.spi; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
import java.nio.file.*; |
8158 | 29 |
import java.nio.file.attribute.*; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
import java.nio.channels.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import java.net.URI; |
8158 | 32 |
import java.io.InputStream; |
33 |
import java.io.OutputStream; |
|
34 |
import java.io.IOException; |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import java.util.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
import java.util.concurrent.ExecutorService; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
import java.security.AccessController; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
import java.security.PrivilegedAction; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
/** |
8158 | 41 |
* Service-provider class for file systems. The methods defined by the {@link |
42 |
* java.nio.file.Files} class will typically delegate to an instance of this |
|
43 |
* class. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
* <p> A file system provider is a concrete implementation of this class that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
* implements the abstract methods defined by this class. A provider is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
* identified by a {@code URI} {@link #getScheme() scheme}. The default provider |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
* is identified by the URI scheme "file". It creates the {@link FileSystem} that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
* provides access to the file systems accessible to the Java virtual machine. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
* The {@link FileSystems} class defines how file system providers are located |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
* and loaded. The default provider is typically a system-default provider but |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
* may be overridden if the system property {@code |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
* java.nio.file.spi.DefaultFileSystemProvider} is set. In that case, the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
54 |
* provider has a one argument constructor whose formal parameter type is {@code |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
* FileSystemProvider}. All other providers have a zero argument constructor |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
* that initializes the provider. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
* <p> A provider is a factory for one or more {@link FileSystem} instances. Each |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
* file system is identified by a {@code URI} where the URI's scheme matches |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
* the provider's {@link #getScheme scheme}. The default file system, for example, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
* is identified by the URI {@code "file:///"}. A memory-based file system, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
* for example, may be identified by a URI such as {@code "memory:///?name=logfs"}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
* The {@link #newFileSystem newFileSystem} method may be used to create a file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
* system, and the {@link #getFileSystem getFileSystem} method may be used to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
* obtain a reference to an existing file system created by the provider. Where |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
* a provider is the factory for a single file system then it is provider dependent |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
* if the file system is created when the provider is initialized, or later when |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
* the {@code newFileSystem} method is invoked. In the case of the default |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
* provider, the {@code FileSystem} is created when the provider is initialized. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
* <p> All of the methods in this class are safe for use by multiple concurrent |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
* threads. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
* @since 1.7 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
76 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
public abstract class FileSystemProvider { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
// lock using when loading providers |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
private static final Object lock = new Object(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
// installed providers |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
82 |
private static volatile List<FileSystemProvider> installedProviders; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
// used to avoid recursive loading of instaled providers |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
private static boolean loadingProviders = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
private static Void checkPermission() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
SecurityManager sm = System.getSecurityManager(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
if (sm != null) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
sm.checkPermission(new RuntimePermission("fileSystemProvider")); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
return null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
private FileSystemProvider(Void ignore) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
* Initializes a new instance of this class. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
* <p> During construction a provider may safely access files associated |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
* with the default provider but care needs to be taken to avoid circular |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
* loading of other installed providers. If circular loading of installed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
* providers is detected then an unspecified error is thrown. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
102 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
* If a security manager has been installed and it denies |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
* {@link RuntimePermission}<tt>("fileSystemProvider")</tt> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
protected FileSystemProvider() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
108 |
this(checkPermission()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
// loads all installed providers |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
private static List<FileSystemProvider> loadInstalledProviders() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
List<FileSystemProvider> list = new ArrayList<FileSystemProvider>(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
ServiceLoader<FileSystemProvider> sl = ServiceLoader |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
.load(FileSystemProvider.class, ClassLoader.getSystemClassLoader()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
// ServiceConfigurationError may be throw here |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
for (FileSystemProvider provider: sl) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
String scheme = provider.getScheme(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
// add to list if the provider is not "file" and isn't a duplicate |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
if (!scheme.equalsIgnoreCase("file")) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
boolean found = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
for (FileSystemProvider p: list) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
if (p.getScheme().equalsIgnoreCase(scheme)) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
found = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
break; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
if (!found) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
list.add(provider); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
return list; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
* Returns a list of the installed file system providers. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
141 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
* <p> The first invocation of this method causes the default provider to be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
* initialized (if not already initialized) and loads any other installed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
* providers as described by the {@link FileSystems} class. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
* @return An unmodifiable list of the installed file system providers. The |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
* list contains at least one element, that is the default file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
* system provider |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
* @throws ServiceConfigurationError |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
* When an error occurs while loading a service provider |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
153 |
public static List<FileSystemProvider> installedProviders() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
if (installedProviders == null) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
// ensure default provider is initialized |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
FileSystemProvider defaultProvider = FileSystems.getDefault().provider(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
synchronized (lock) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
if (installedProviders == null) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
if (loadingProviders) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
throw new Error("Circular loading of installed providers detected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
loadingProviders = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
List<FileSystemProvider> list = AccessController |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
.doPrivileged(new PrivilegedAction<List<FileSystemProvider>>() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
168 |
public List<FileSystemProvider> run() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
return loadInstalledProviders(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
}}); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
171 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
// insert the default provider at the start of the list |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
173 |
list.add(0, defaultProvider); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
174 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
175 |
installedProviders = Collections.unmodifiableList(list); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
176 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
177 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
178 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
179 |
return installedProviders; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
180 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
181 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
182 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
183 |
* Returns the URI scheme that identifies this provider. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
* @return The URI scheme |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
public abstract String getScheme(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
* Constructs a new {@code FileSystem} object identified by a URI. This |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
* method is invoked by the {@link FileSystems#newFileSystem(URI,Map)} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
* method to open a new file system identified by a URI. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
193 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
194 |
* <p> The {@code uri} parameter is an absolute, hierarchical URI, with a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
195 |
* scheme equal (without regard to case) to the scheme supported by this |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
196 |
* provider. The exact form of the URI is highly provider dependent. The |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
197 |
* {@code env} parameter is a map of provider specific properties to configure |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
* the file system. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
199 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
200 |
* <p> This method throws {@link FileSystemAlreadyExistsException} if the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
201 |
* file system already exists because it was previously created by an |
8158 | 202 |
* invocation of this method. Once a file system is {@link |
203 |
* java.nio.file.FileSystem#close closed} it is provider-dependent if the |
|
204 |
* provider allows a new file system to be created with the same URI as a |
|
205 |
* file system it previously created. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
206 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
207 |
* @param uri |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
208 |
* URI reference |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
209 |
* @param env |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
210 |
* A map of provider specific properties to configure the file system; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
* may be empty |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
213 |
* @return A new file system |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
214 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
215 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
* If the pre-conditions for the {@code uri} parameter aren't met, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
217 |
* or the {@code env} parameter does not contain properties required |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
218 |
* by the provider, or a property value is invalid |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
219 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
220 |
* An I/O error occurs creating the file system |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
221 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
222 |
* If a security manager is installed and it denies an unspecified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
223 |
* permission required by the file system provider implementation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
224 |
* @throws FileSystemAlreadyExistsException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
* If the file system has already been created |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
226 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
227 |
public abstract FileSystem newFileSystem(URI uri, Map<String,?> env) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
228 |
throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
229 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
230 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
231 |
* Returns an existing {@code FileSystem} created by this provider. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
233 |
* <p> This method returns a reference to a {@code FileSystem} that was |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
234 |
* created by invoking the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)} |
8158 | 235 |
* method. File systems created the {@link #newFileSystem(Path,Map) |
236 |
* newFileSystem(Path,Map)} method are not returned by this method. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
237 |
* The file system is identified by its {@code URI}. Its exact form |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
238 |
* is highly provider dependent. In the case of the default provider the URI's |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
* path component is {@code "/"} and the authority, query and fragment components |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
240 |
* are undefined (Undefined components are represented by {@code null}). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
241 |
* |
8158 | 242 |
* <p> Once a file system created by this provider is {@link |
243 |
* java.nio.file.FileSystem#close closed} it is provider-dependent if this |
|
244 |
* method returns a reference to the closed file system or throws {@link |
|
245 |
* FileSystemNotFoundException}. If the provider allows a new file system to |
|
246 |
* be created with the same URI as a file system it previously created then |
|
247 |
* this method throws the exception if invoked after the file system is |
|
248 |
* closed (and before a new instance is created by the {@link #newFileSystem |
|
249 |
* newFileSystem} method). |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
250 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
251 |
* <p> If a security manager is installed then a provider implementation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
252 |
* may require to check a permission before returning a reference to an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
253 |
* existing file system. In the case of the {@link FileSystems#getDefault |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
254 |
* default} file system, no permission check is required. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
255 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
256 |
* @param uri |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
257 |
* URI reference |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
258 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
259 |
* @return The file system |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
260 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
261 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
262 |
* If the pre-conditions for the {@code uri} parameter aren't met |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
263 |
* @throws FileSystemNotFoundException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
264 |
* If the file system does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
265 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
266 |
* If a security manager is installed and it denies an unspecified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
267 |
* permission. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
268 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
269 |
public abstract FileSystem getFileSystem(URI uri); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
270 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
271 |
/** |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
272 |
* Return a {@code Path} object by converting the given {@link URI}. The |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
273 |
* resulting {@code Path} is associated with a {@link FileSystem} that |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
274 |
* already exists or is constructed automatically. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
275 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
276 |
* <p> The exact form of the URI is file system provider dependent. In the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
277 |
* case of the default provider, the URI scheme is {@code "file"} and the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
278 |
* given URI has a non-empty path component, and undefined query, and |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
279 |
* fragment components. The resulting {@code Path} is associated with the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
280 |
* default {@link FileSystems#getDefault default} {@code FileSystem}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
281 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
282 |
* <p> If a security manager is installed then a provider implementation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
283 |
* may require to check a permission. In the case of the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
284 |
* FileSystems#getDefault default} file system, no permission check is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
285 |
* required. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
286 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
287 |
* @param uri |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
288 |
* The URI to convert |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
289 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
290 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
291 |
* If the URI scheme does not identify this provider or other |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
292 |
* preconditions on the uri parameter do not hold |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
293 |
* @throws FileSystemNotFoundException |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
294 |
* The file system, identified by the URI, does not exist and |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
295 |
* cannot be created automatically |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
296 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
297 |
* If a security manager is installed and it denies an unspecified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
298 |
* permission. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
299 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
300 |
public abstract Path getPath(URI uri); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
301 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
302 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
303 |
* Constructs a new {@code FileSystem} to access the contents of a file as a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
304 |
* file system. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
305 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
306 |
* <p> This method is intended for specialized providers of pseudo file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
307 |
* systems where the contents of one or more files is treated as a file |
8158 | 308 |
* system. The {@code env} parameter is a map of provider specific properties |
309 |
* to configure the file system. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
310 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
311 |
* <p> If this provider does not support the creation of such file systems |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
312 |
* or if the provider does not recognize the file type of the given file then |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
313 |
* it throws {@code UnsupportedOperationException}. The default implementation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
314 |
* of this method throws {@code UnsupportedOperationException}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
315 |
* |
8158 | 316 |
* @param path |
317 |
* The path to the file |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
318 |
* @param env |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
319 |
* A map of provider specific properties to configure the file system; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
320 |
* may be empty |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
321 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
322 |
* @return A new file system |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
323 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
324 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
325 |
* If this provider does not support access to the contents as a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
326 |
* file system or it does not recognize the file type of the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
327 |
* given file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
328 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
329 |
* If the {@code env} parameter does not contain properties required |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
330 |
* by the provider, or a property value is invalid |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
331 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
332 |
* If an I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
333 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
334 |
* If a security manager is installed and it denies an unspecified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
335 |
* permission. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
336 |
*/ |
8158 | 337 |
public FileSystem newFileSystem(Path path, Map<String,?> env) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
338 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
339 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
340 |
throw new UnsupportedOperationException(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
341 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
342 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
343 |
/** |
8158 | 344 |
* Opens a file, returning an input stream to read from the file. This |
345 |
* method works in exactly the manner specified by the {@link |
|
346 |
* Files#newInputStream} method. |
|
347 |
* |
|
348 |
* <p> The default implementation of this method opens a channel to the file |
|
349 |
* as if by invoking the {@link #newByteChannel} method and constructs a |
|
350 |
* stream that reads bytes from the channel. This method should be overridden |
|
351 |
* where appropriate. |
|
352 |
* |
|
353 |
* @param path |
|
354 |
* the path to the file to open |
|
355 |
* @param options |
|
356 |
* options specifying how the file is opened |
|
357 |
* |
|
358 |
* @return a new input stream |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
359 |
* |
8158 | 360 |
* @throws IllegalArgumentException |
361 |
* if an invalid combination of options is specified |
|
362 |
* @throws UnsupportedOperationException |
|
363 |
* if an unsupported option is specified |
|
364 |
* @throws IOException |
|
365 |
* if an I/O error occurs |
|
366 |
* @throws SecurityException |
|
367 |
* In the case of the default provider, and a security manager is |
|
368 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
369 |
* method is invoked to check read access to the file. |
|
370 |
*/ |
|
371 |
public InputStream newInputStream(Path path, OpenOption... options) |
|
372 |
throws IOException |
|
373 |
{ |
|
374 |
if (options.length > 0) { |
|
375 |
for (OpenOption opt: options) { |
|
376 |
if (opt != StandardOpenOption.READ) |
|
377 |
throw new UnsupportedOperationException("'" + opt + "' not allowed"); |
|
378 |
} |
|
379 |
} |
|
380 |
return Channels.newInputStream(Files.newByteChannel(path)); |
|
381 |
} |
|
382 |
||
383 |
/** |
|
384 |
* Opens or creates a file, returning an output stream that may be used to |
|
385 |
* write bytes to the file. This method works in exactly the manner |
|
386 |
* specified by the {@link Files#newOutputStream} method. |
|
387 |
* |
|
388 |
* <p> The default implementation of this method opens a channel to the file |
|
389 |
* as if by invoking the {@link #newByteChannel} method and constructs a |
|
390 |
* stream that writes bytes to the channel. This method should be overridden |
|
391 |
* where appropriate. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
392 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
393 |
* @param path |
8158 | 394 |
* the path to the file to open or create |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
395 |
* @param options |
8158 | 396 |
* options specifying how the file is opened |
397 |
* |
|
398 |
* @return a new output stream |
|
399 |
* |
|
400 |
* @throws IllegalArgumentException |
|
401 |
* if {@code options} contains an invalid combination of options |
|
402 |
* @throws UnsupportedOperationException |
|
403 |
* if an unsupported option is specified |
|
404 |
* @throws IOException |
|
405 |
* if an I/O error occurs |
|
406 |
* @throws SecurityException |
|
407 |
* In the case of the default provider, and a security manager is |
|
408 |
* installed, the {@link SecurityManager#checkWrite(String) checkWrite} |
|
409 |
* method is invoked to check write access to the file. The {@link |
|
410 |
* SecurityManager#checkDelete(String) checkDelete} method is |
|
411 |
* invoked to check delete access if the file is opened with the |
|
412 |
* {@code DELETE_ON_CLOSE} option. |
|
413 |
*/ |
|
414 |
public OutputStream newOutputStream(Path path, OpenOption... options) |
|
415 |
throws IOException |
|
416 |
{ |
|
417 |
int len = options.length; |
|
418 |
Set<OpenOption> opts = new HashSet<OpenOption>(len + 3); |
|
419 |
if (len == 0) { |
|
420 |
opts.add(StandardOpenOption.CREATE); |
|
421 |
opts.add(StandardOpenOption.TRUNCATE_EXISTING); |
|
422 |
} else { |
|
423 |
for (OpenOption opt: options) { |
|
424 |
if (opt == StandardOpenOption.READ) |
|
425 |
throw new IllegalArgumentException("READ not allowed"); |
|
426 |
opts.add(opt); |
|
427 |
} |
|
428 |
} |
|
429 |
opts.add(StandardOpenOption.WRITE); |
|
430 |
return Channels.newOutputStream(newByteChannel(path, opts)); |
|
431 |
} |
|
432 |
||
433 |
/** |
|
434 |
* Opens or creates a file for reading and/or writing, returning a file |
|
435 |
* channel to access the file. This method works in exactly the manner |
|
436 |
* specified by the {@link FileChannel#open(Path,Set,FileAttribute[]) |
|
437 |
* FileChannel.open} method. A provider that does not support all the |
|
438 |
* features required to construct a file channel throws {@code |
|
439 |
* UnsupportedOperationException}. The default provider is required to |
|
440 |
* support the creation of file channels. When not overridden, the default |
|
441 |
* implementation throws {@code UnsupportedOperationException}. |
|
442 |
* |
|
443 |
* @param path |
|
444 |
* the path of the file to open or create |
|
445 |
* @param options |
|
446 |
* options specifying how the file is opened |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
447 |
* @param attrs |
8158 | 448 |
* an optional list of file attributes to set atomically when |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
449 |
* creating the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
450 |
* |
8158 | 451 |
* @return a new file channel |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
452 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
453 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
454 |
* If the set contains an invalid combination of options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
455 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
456 |
* If this provider that does not support creating file channels, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
457 |
* or an unsupported open option or file attribute is specified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
458 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
459 |
* If an I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
460 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
461 |
* In the case of the default file system, the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
462 |
* SecurityManager#checkRead(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
463 |
* read access if the file is opened for reading. The {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
464 |
* SecurityManager#checkWrite(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
465 |
* write access if the file is opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
466 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
467 |
public FileChannel newFileChannel(Path path, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
468 |
Set<? extends OpenOption> options, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
469 |
FileAttribute<?>... attrs) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
470 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
471 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
472 |
throw new UnsupportedOperationException(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
473 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
474 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
475 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
476 |
* Opens or creates a file for reading and/or writing, returning an |
8158 | 477 |
* asynchronous file channel to access the file. This method works in |
478 |
* exactly the manner specified by the {@link |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
479 |
* AsynchronousFileChannel#open(Path,Set,ExecutorService,FileAttribute[]) |
8158 | 480 |
* AsynchronousFileChannel.open} method. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
481 |
* A provider that does not support all the features required to construct |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
482 |
* an asynchronous file channel throws {@code UnsupportedOperationException}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
483 |
* The default provider is required to support the creation of asynchronous |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
484 |
* file channels. When not overridden, the default implementation of this |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
485 |
* method throws {@code UnsupportedOperationException}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
486 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
487 |
* @param path |
8158 | 488 |
* the path of the file to open or create |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
489 |
* @param options |
8158 | 490 |
* options specifying how the file is opened |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
491 |
* @param executor |
8158 | 492 |
* the thread pool or {@code null} to associate the channel with |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
493 |
* the default thread pool |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
494 |
* @param attrs |
8158 | 495 |
* an optional list of file attributes to set atomically when |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
496 |
* creating the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
497 |
* |
8158 | 498 |
* @return a new asynchronous file channel |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
499 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
500 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
501 |
* If the set contains an invalid combination of options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
502 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
503 |
* If this provider that does not support creating asynchronous file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
504 |
* channels, or an unsupported open option or file attribute is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
505 |
* specified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
506 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
507 |
* If an I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
508 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
509 |
* In the case of the default file system, the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
510 |
* SecurityManager#checkRead(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
511 |
* read access if the file is opened for reading. The {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
512 |
* SecurityManager#checkWrite(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
513 |
* write access if the file is opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
514 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
515 |
public AsynchronousFileChannel newAsynchronousFileChannel(Path path, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
516 |
Set<? extends OpenOption> options, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
517 |
ExecutorService executor, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
518 |
FileAttribute<?>... attrs) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
519 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
520 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
521 |
throw new UnsupportedOperationException(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
522 |
} |
8158 | 523 |
|
524 |
/** |
|
525 |
* Opens or creates a file, returning a seekable byte channel to access the |
|
526 |
* file. This method works in exactly the manner specified by the {@link |
|
527 |
* Files#newByteChannel(Path,Set,FileAttribute[])} method. |
|
528 |
* |
|
529 |
* @param path |
|
530 |
* the path to the file to open or create |
|
531 |
* @param options |
|
532 |
* options specifying how the file is opened |
|
533 |
* @param attrs |
|
534 |
* an optional list of file attributes to set atomically when |
|
535 |
* creating the file |
|
536 |
* |
|
537 |
* @return a new seekable byte channel |
|
538 |
* |
|
539 |
* @throws IllegalArgumentException |
|
540 |
* if the set contains an invalid combination of options |
|
541 |
* @throws UnsupportedOperationException |
|
542 |
* if an unsupported open option is specified or the array contains |
|
543 |
* attributes that cannot be set atomically when creating the file |
|
544 |
* @throws FileAlreadyExistsException |
|
545 |
* if a file of that name already exists and the {@link |
|
546 |
* StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified |
|
547 |
* <i>(optional specific exception)</i> |
|
548 |
* @throws IOException |
|
549 |
* if an I/O error occurs |
|
550 |
* @throws SecurityException |
|
551 |
* In the case of the default provider, and a security manager is |
|
552 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
553 |
* method is invoked to check read access to the path if the file is |
|
554 |
* opened for reading. The {@link SecurityManager#checkWrite(String) |
|
555 |
* checkWrite} method is invoked to check write access to the path |
|
556 |
* if the file is opened for writing. The {@link |
|
557 |
* SecurityManager#checkDelete(String) checkDelete} method is |
|
558 |
* invoked to check delete access if the file is opened with the |
|
559 |
* {@code DELETE_ON_CLOSE} option. |
|
560 |
*/ |
|
561 |
public abstract SeekableByteChannel newByteChannel(Path path, |
|
562 |
Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException; |
|
563 |
||
564 |
/** |
|
565 |
* Opens a directory, returning a {@code DirectoryStream} to iterate over |
|
566 |
* the entries in the directory. This method works in exactly the manner |
|
567 |
* specified by the {@link |
|
568 |
* Files#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)} |
|
569 |
* method. |
|
570 |
* |
|
571 |
* @param dir |
|
572 |
* the path to the directory |
|
573 |
* @param filter |
|
574 |
* the directory stream filter |
|
575 |
* |
|
576 |
* @return a new and open {@code DirectoryStream} object |
|
577 |
* |
|
578 |
* @throws NotDirectoryException |
|
579 |
* if the file could not otherwise be opened because it is not |
|
580 |
* a directory <i>(optional specific exception)</i> |
|
581 |
* @throws IOException |
|
582 |
* if an I/O error occurs |
|
583 |
* @throws SecurityException |
|
584 |
* In the case of the default provider, and a security manager is |
|
585 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
586 |
* method is invoked to check read access to the directory. |
|
587 |
*/ |
|
588 |
public abstract DirectoryStream<Path> newDirectoryStream(Path dir, |
|
589 |
DirectoryStream.Filter<? super Path> filter) throws IOException; |
|
590 |
||
591 |
/** |
|
592 |
* Creates a new directory. This method works in exactly the manner |
|
593 |
* specified by the {@link Files#createDirectory} method. |
|
594 |
* |
|
595 |
* @param dir |
|
596 |
* the directory to create |
|
597 |
* @param attrs |
|
598 |
* an optional list of file attributes to set atomically when |
|
599 |
* creating the directory |
|
600 |
* |
|
601 |
* @throws UnsupportedOperationException |
|
602 |
* if the array contains an attribute that cannot be set atomically |
|
603 |
* when creating the directory |
|
604 |
* @throws FileAlreadyExistsException |
|
605 |
* if a directory could not otherwise be created because a file of |
|
606 |
* that name already exists <i>(optional specific exception)</i> |
|
607 |
* @throws IOException |
|
608 |
* if an I/O error occurs or the parent directory does not exist |
|
609 |
* @throws SecurityException |
|
610 |
* In the case of the default provider, and a security manager is |
|
611 |
* installed, the {@link SecurityManager#checkWrite(String) checkWrite} |
|
612 |
* method is invoked to check write access to the new directory. |
|
613 |
*/ |
|
614 |
public abstract void createDirectory(Path dir, FileAttribute<?>... attrs) |
|
615 |
throws IOException; |
|
616 |
||
617 |
/** |
|
618 |
* Creates a symbolic link to a target. This method works in exactly the |
|
619 |
* manner specified by the {@link Files#createSymbolicLink} method. |
|
620 |
* |
|
621 |
* <p> The default implementation of this method throws {@code |
|
622 |
* UnsupportedOperationException}. |
|
623 |
* |
|
624 |
* @param link |
|
625 |
* the path of the symbolic link to create |
|
626 |
* @param target |
|
627 |
* the target of the symbolic link |
|
628 |
* @param attrs |
|
629 |
* the array of attributes to set atomically when creating the |
|
630 |
* symbolic link |
|
631 |
* |
|
632 |
* @throws UnsupportedOperationException |
|
633 |
* if the implementation does not support symbolic links or the |
|
634 |
* array contains an attribute that cannot be set atomically when |
|
635 |
* creating the symbolic link |
|
636 |
* @throws FileAlreadyExistsException |
|
637 |
* if a file with the name already exists <i>(optional specific |
|
638 |
* exception)</i> |
|
639 |
* @throws IOException |
|
640 |
* if an I/O error occurs |
|
641 |
* @throws SecurityException |
|
642 |
* In the case of the default provider, and a security manager |
|
643 |
* is installed, it denies {@link LinkPermission}<tt>("symbolic")</tt> |
|
644 |
* or its {@link SecurityManager#checkWrite(String) checkWrite} |
|
645 |
* method denies write access to the path of the symbolic link. |
|
646 |
*/ |
|
647 |
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) |
|
648 |
throws IOException |
|
649 |
{ |
|
650 |
throw new UnsupportedOperationException(); |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* Creates a new link (directory entry) for an existing file. This method |
|
655 |
* works in exactly the manner specified by the {@link Files#createLink} |
|
656 |
* method. |
|
657 |
* |
|
658 |
* <p> The default implementation of this method throws {@code |
|
659 |
* UnsupportedOperationException}. |
|
660 |
* |
|
661 |
* @param link |
|
662 |
* the link (directory entry) to create |
|
663 |
* @param existing |
|
664 |
* a path to an existing file |
|
665 |
* |
|
666 |
* @throws UnsupportedOperationException |
|
667 |
* if the implementation does not support adding an existing file |
|
668 |
* to a directory |
|
669 |
* @throws FileAlreadyExistsException |
|
670 |
* if the entry could not otherwise be created because a file of |
|
671 |
* that name already exists <i>(optional specific exception)</i> |
|
672 |
* @throws IOException |
|
673 |
* if an I/O error occurs |
|
674 |
* @throws SecurityException |
|
675 |
* In the case of the default provider, and a security manager |
|
676 |
* is installed, it denies {@link LinkPermission}<tt>("hard")</tt> |
|
677 |
* or its {@link SecurityManager#checkWrite(String) checkWrite} |
|
678 |
* method denies write access to either the link or the |
|
679 |
* existing file. |
|
680 |
*/ |
|
681 |
public void createLink(Path link, Path existing) throws IOException { |
|
682 |
throw new UnsupportedOperationException(); |
|
683 |
} |
|
684 |
||
685 |
/** |
|
686 |
* Deletes a file. This method works in exactly the manner specified by the |
|
687 |
* {@link Files#delete} method. |
|
688 |
* |
|
689 |
* @param path |
|
690 |
* the path to the file to delete |
|
691 |
* |
|
692 |
* @throws NoSuchFileException |
|
693 |
* if the file does not exist <i>(optional specific exception)</i> |
|
694 |
* @throws DirectoryNotEmptyException |
|
695 |
* if the file is a directory and could not otherwise be deleted |
|
696 |
* because the directory is not empty <i>(optional specific |
|
697 |
* exception)</i> |
|
698 |
* @throws IOException |
|
699 |
* if an I/O error occurs |
|
700 |
* @throws SecurityException |
|
701 |
* In the case of the default provider, and a security manager is |
|
702 |
* installed, the {@link SecurityManager#checkDelete(String)} method |
|
703 |
* is invoked to check delete access to the file |
|
704 |
*/ |
|
705 |
public abstract void delete(Path path) throws IOException; |
|
706 |
||
707 |
/** |
|
708 |
* Deletes a file if it exists. This method works in exactly the manner |
|
709 |
* specified by the {@link Files#deleteIfExists} method. |
|
710 |
* |
|
711 |
* <p> The default implementation of this method simply invokes {@link |
|
712 |
* #delete} ignoring the {@code NoSuchFileException} when the file does not |
|
713 |
* exist. It may be overridden where appropriate. |
|
714 |
* |
|
715 |
* @param path |
|
716 |
* the path to the file to delete |
|
717 |
* |
|
718 |
* @return {@code true} if the file was deleted by this method; {@code |
|
719 |
* false} if the file could not be deleted because it did not |
|
720 |
* exist |
|
721 |
* |
|
722 |
* @throws DirectoryNotEmptyException |
|
723 |
* if the file is a directory and could not otherwise be deleted |
|
724 |
* because the directory is not empty <i>(optional specific |
|
725 |
* exception)</i> |
|
726 |
* @throws IOException |
|
727 |
* if an I/O error occurs |
|
728 |
* @throws SecurityException |
|
729 |
* In the case of the default provider, and a security manager is |
|
730 |
* installed, the {@link SecurityManager#checkDelete(String)} method |
|
731 |
* is invoked to check delete access to the file |
|
732 |
*/ |
|
733 |
public boolean deleteIfExists(Path path) throws IOException { |
|
734 |
try { |
|
735 |
delete(path); |
|
736 |
return true; |
|
737 |
} catch (NoSuchFileException ignore) { |
|
738 |
return false; |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
/** |
|
743 |
* Reads the target of a symbolic link. This method works in exactly the |
|
744 |
* manner specified by the {@link Files#readSymbolicLink} method. |
|
745 |
* |
|
746 |
* <p> The default implementation of this method throws {@code |
|
747 |
* UnsupportedOperationException}. |
|
748 |
* |
|
749 |
* @param link |
|
750 |
* the path to the symbolic link |
|
751 |
* |
|
752 |
* @throws UnsupportedOperationException |
|
753 |
* if the implementation does not support symbolic links |
|
754 |
* @throws NotLinkException |
|
755 |
* if the target could otherwise not be read because the file |
|
756 |
* is not a symbolic link <i>(optional specific exception)</i> |
|
757 |
* @throws IOException |
|
758 |
* if an I/O error occurs |
|
759 |
* @throws SecurityException |
|
760 |
* In the case of the default provider, and a security manager |
|
761 |
* is installed, it checks that {@code FilePermission} has been |
|
762 |
* granted with the "{@code readlink}" action to read the link. |
|
763 |
*/ |
|
764 |
public Path readSymbolicLink(Path link) throws IOException { |
|
765 |
throw new UnsupportedOperationException(); |
|
766 |
} |
|
767 |
||
768 |
/** |
|
769 |
* Copy a file to a target file. This method works in exactly the manner |
|
770 |
* specified by the {@link Files#copy(Path,Path,CopyOption[])} method |
|
771 |
* except that both the source and target paths must be associated with |
|
772 |
* this provider. |
|
773 |
* |
|
774 |
* @param source |
|
775 |
* the path to the file to copy |
|
776 |
* @param target |
|
777 |
* the path to the target file |
|
778 |
* @param options |
|
779 |
* options specifying how the copy should be done |
|
780 |
* |
|
781 |
* @throws UnsupportedOperationException |
|
782 |
* if the array contains a copy option that is not supported |
|
783 |
* @throws FileAlreadyExistsException |
|
784 |
* if the target file exists but cannot be replaced because the |
|
785 |
* {@code REPLACE_EXISTING} option is not specified <i>(optional |
|
786 |
* specific exception)</i> |
|
787 |
* @throws DirectoryNotEmptyException |
|
788 |
* the {@code REPLACE_EXISTING} option is specified but the file |
|
789 |
* cannot be replaced because it is a non-empty directory |
|
790 |
* <i>(optional specific exception)</i> |
|
791 |
* @throws IOException |
|
792 |
* if an I/O error occurs |
|
793 |
* @throws SecurityException |
|
794 |
* In the case of the default provider, and a security manager is |
|
795 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
796 |
* method is invoked to check read access to the source file, the |
|
797 |
* {@link SecurityManager#checkWrite(String) checkWrite} is invoked |
|
798 |
* to check write access to the target file. If a symbolic link is |
|
799 |
* copied the security manager is invoked to check {@link |
|
800 |
* LinkPermission}{@code ("symbolic")}. |
|
801 |
*/ |
|
802 |
public abstract void copy(Path source, Path target, CopyOption... options) |
|
803 |
throws IOException; |
|
804 |
||
805 |
/** |
|
806 |
* Move or rename a file to a target file. This method works in exactly the |
|
807 |
* manner specified by the {@link Files#move} method except that both the |
|
808 |
* source and target paths must be associated with this provider. |
|
809 |
* |
|
810 |
* @param source |
|
811 |
* the path to the file to move |
|
812 |
* @param target |
|
813 |
* the path to the target file |
|
814 |
* @param options |
|
815 |
* options specifying how the move should be done |
|
816 |
* |
|
817 |
* @throws UnsupportedOperationException |
|
818 |
* if the array contains a copy option that is not supported |
|
819 |
* @throws FileAlreadyExistsException |
|
820 |
* if the target file exists but cannot be replaced because the |
|
821 |
* {@code REPLACE_EXISTING} option is not specified <i>(optional |
|
822 |
* specific exception)</i> |
|
823 |
* @throws DirectoryNotEmptyException |
|
824 |
* the {@code REPLACE_EXISTING} option is specified but the file |
|
825 |
* cannot be replaced because it is a non-empty directory |
|
826 |
* <i>(optional specific exception)</i> |
|
827 |
* @throws AtomicMoveNotSupportedException |
|
828 |
* if the options array contains the {@code ATOMIC_MOVE} option but |
|
829 |
* the file cannot be moved as an atomic file system operation. |
|
830 |
* @throws IOException |
|
831 |
* if an I/O error occurs |
|
832 |
* @throws SecurityException |
|
833 |
* In the case of the default provider, and a security manager is |
|
834 |
* installed, the {@link SecurityManager#checkWrite(String) checkWrite} |
|
835 |
* method is invoked to check write access to both the source and |
|
836 |
* target file. |
|
837 |
*/ |
|
838 |
public abstract void move(Path source, Path target, CopyOption... options) |
|
839 |
throws IOException; |
|
840 |
||
841 |
/** |
|
842 |
* Tests if two paths locate the same file. This method works in exactly the |
|
843 |
* manner specified by the {@link Files#isSameFile} method. |
|
844 |
* |
|
845 |
* @param path |
|
846 |
* one path to the file |
|
847 |
* @param path2 |
|
848 |
* the other path |
|
849 |
* |
|
850 |
* @return {@code true} if, and only if, the two paths locate the same file |
|
851 |
* |
|
852 |
* @throws IOException |
|
853 |
* if an I/O error occurs |
|
854 |
* @throws SecurityException |
|
855 |
* In the case of the default provider, and a security manager is |
|
856 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
857 |
* method is invoked to check read access to both files. |
|
858 |
*/ |
|
859 |
public abstract boolean isSameFile(Path path, Path path2) |
|
860 |
throws IOException; |
|
861 |
||
862 |
/** |
|
863 |
* Tells whether or not a file is considered <em>hidden</em>. This method |
|
864 |
* works in exactly the manner specified by the {@link Files#isHidden} |
|
865 |
* method. |
|
866 |
* |
|
867 |
* <p> This method is invoked by the {@link Files#isHidden isHidden} method. |
|
868 |
* |
|
869 |
* @param path |
|
870 |
* the path to the file to test |
|
871 |
* |
|
872 |
* @return {@code true} if the file is considered hidden |
|
873 |
* |
|
874 |
* @throws IOException |
|
875 |
* if an I/O error occurs |
|
876 |
* @throws SecurityException |
|
877 |
* In the case of the default provider, and a security manager is |
|
878 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
879 |
* method is invoked to check read access to the file. |
|
880 |
*/ |
|
881 |
public abstract boolean isHidden(Path path) throws IOException; |
|
882 |
||
883 |
/** |
|
884 |
* Returns the {@link FileStore} representing the file store where a file |
|
885 |
* is located. This method works in exactly the manner specified by the |
|
886 |
* {@link Files#getFileStore} method. |
|
887 |
* |
|
888 |
* @param path |
|
889 |
* the path to the file |
|
890 |
* |
|
891 |
* @return the file store where the file is stored |
|
892 |
* |
|
893 |
* @throws IOException |
|
894 |
* if an I/O error occurs |
|
895 |
* @throws SecurityException |
|
896 |
* In the case of the default provider, and a security manager is |
|
897 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
898 |
* method is invoked to check read access to the file, and in |
|
899 |
* addition it checks {@link RuntimePermission}<tt> |
|
900 |
* ("getFileStoreAttributes")</tt> |
|
901 |
*/ |
|
902 |
public abstract FileStore getFileStore(Path path) throws IOException; |
|
903 |
||
904 |
/** |
|
905 |
* Checks the existence, and optionally the accessibility, of a file. |
|
906 |
* |
|
907 |
* <p> This method may be used by the {@link Files#isReadable isReadable}, |
|
908 |
* {@link Files#isWritable isWritable} and {@link Files#isExecutable |
|
909 |
* isExecutable} methods to check the accessibility of a file. |
|
910 |
* |
|
911 |
* <p> This method checks the existence of a file and that this Java virtual |
|
912 |
* machine has appropriate privileges that would allow it access the file |
|
913 |
* according to all of access modes specified in the {@code modes} parameter |
|
914 |
* as follows: |
|
915 |
* |
|
916 |
* <table border=1 cellpadding=5 summary=""> |
|
917 |
* <tr> <th>Value</th> <th>Description</th> </tr> |
|
918 |
* <tr> |
|
919 |
* <td> {@link AccessMode#READ READ} </td> |
|
920 |
* <td> Checks that the file exists and that the Java virtual machine has |
|
921 |
* permission to read the file. </td> |
|
922 |
* </tr> |
|
923 |
* <tr> |
|
924 |
* <td> {@link AccessMode#WRITE WRITE} </td> |
|
925 |
* <td> Checks that the file exists and that the Java virtual machine has |
|
926 |
* permission to write to the file, </td> |
|
927 |
* </tr> |
|
928 |
* <tr> |
|
929 |
* <td> {@link AccessMode#EXECUTE EXECUTE} </td> |
|
930 |
* <td> Checks that the file exists and that the Java virtual machine has |
|
931 |
* permission to {@link Runtime#exec execute} the file. The semantics |
|
932 |
* may differ when checking access to a directory. For example, on UNIX |
|
933 |
* systems, checking for {@code EXECUTE} access checks that the Java |
|
934 |
* virtual machine has permission to search the directory in order to |
|
935 |
* access file or subdirectories. </td> |
|
936 |
* </tr> |
|
937 |
* </table> |
|
938 |
* |
|
939 |
* <p> If the {@code modes} parameter is of length zero, then the existence |
|
940 |
* of the file is checked. |
|
941 |
* |
|
942 |
* <p> This method follows symbolic links if the file referenced by this |
|
943 |
* object is a symbolic link. Depending on the implementation, this method |
|
944 |
* may require to read file permissions, access control lists, or other |
|
945 |
* file attributes in order to check the effective access to the file. To |
|
946 |
* determine the effective access to a file may require access to several |
|
947 |
* attributes and so in some implementations this method may not be atomic |
|
948 |
* with respect to other file system operations. |
|
949 |
* |
|
950 |
* @param path |
|
951 |
* the path to the file to check |
|
952 |
* @param modes |
|
953 |
* The access modes to check; may have zero elements |
|
954 |
* |
|
955 |
* @throws UnsupportedOperationException |
|
956 |
* an implementation is required to support checking for |
|
957 |
* {@code READ}, {@code WRITE}, and {@code EXECUTE} access. This |
|
958 |
* exception is specified to allow for the {@code Access} enum to |
|
959 |
* be extended in future releases. |
|
960 |
* @throws NoSuchFileException |
|
961 |
* if a file does not exist <i>(optional specific exception)</i> |
|
962 |
* @throws AccessDeniedException |
|
963 |
* the requested access would be denied or the access cannot be |
|
964 |
* determined because the Java virtual machine has insufficient |
|
965 |
* privileges or other reasons. <i>(optional specific exception)</i> |
|
966 |
* @throws IOException |
|
967 |
* if an I/O error occurs |
|
968 |
* @throws SecurityException |
|
969 |
* In the case of the default provider, and a security manager is |
|
970 |
* installed, the {@link SecurityManager#checkRead(String) checkRead} |
|
971 |
* is invoked when checking read access to the file or only the |
|
972 |
* existence of the file, the {@link SecurityManager#checkWrite(String) |
|
973 |
* checkWrite} is invoked when checking write access to the file, |
|
974 |
* and {@link SecurityManager#checkExec(String) checkExec} is invoked |
|
975 |
* when checking execute access. |
|
976 |
*/ |
|
977 |
public abstract void checkAccess(Path path, AccessMode... modes) |
|
978 |
throws IOException; |
|
979 |
||
980 |
/** |
|
981 |
* Returns a file attribute view of a given type. This method works in |
|
982 |
* exactly the manner specified by the {@link Files#getFileAttributeView} |
|
983 |
* method. |
|
984 |
* |
|
985 |
* @param path |
|
986 |
* the path to the file |
|
987 |
* @param type |
|
988 |
* the {@code Class} object corresponding to the file attribute view |
|
989 |
* @param options |
|
990 |
* options indicating how symbolic links are handled |
|
991 |
* |
|
992 |
* @return a file attribute view of the specified type, or {@code null} if |
|
993 |
* the attribute view type is not available |
|
994 |
*/ |
|
995 |
public abstract <V extends FileAttributeView> V |
|
996 |
getFileAttributeView(Path path, Class<V> type, LinkOption... options); |
|
997 |
||
998 |
/** |
|
999 |
* Reads a file's attributes as a bulk operation. This method works in |
|
1000 |
* exactly the manner specified by the {@link |
|
1001 |
* Files#readAttributes(Path,Class,LinkOption[])} method. |
|
1002 |
* |
|
1003 |
* @param path |
|
1004 |
* the path to the file |
|
1005 |
* @param type |
|
1006 |
* the {@code Class} of the file attributes required |
|
1007 |
* to read |
|
1008 |
* @param options |
|
1009 |
* options indicating how symbolic links are handled |
|
1010 |
* |
|
1011 |
* @return the file attributes |
|
1012 |
* |
|
1013 |
* @throws UnsupportedOperationException |
|
1014 |
* if an attributes of the given type are not supported |
|
1015 |
* @throws IOException |
|
1016 |
* if an I/O error occurs |
|
1017 |
* @throws SecurityException |
|
1018 |
* In the case of the default provider, a security manager is |
|
1019 |
* installed, its {@link SecurityManager#checkRead(String) checkRead} |
|
1020 |
* method is invoked to check read access to the file |
|
1021 |
*/ |
|
1022 |
public abstract <A extends BasicFileAttributes> A |
|
1023 |
readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException; |
|
1024 |
||
1025 |
/** |
|
1026 |
* Reads a set of file attributes as a bulk operation. This method works in |
|
1027 |
* exactly the manner specified by the {@link |
|
1028 |
* Files#readAttributes(Path,String,LinkOption[])} method. |
|
1029 |
* |
|
1030 |
* @param path |
|
1031 |
* the path to the file |
|
1032 |
* @param attributes |
|
1033 |
* the attributes to read |
|
1034 |
* @param options |
|
1035 |
* options indicating how symbolic links are handled |
|
1036 |
* |
|
1037 |
* @return a map of the attributes returned; may be empty. The map's keys |
|
1038 |
* are the attribute names, its values are the attribute values |
|
1039 |
* |
|
8808 | 1040 |
* @throws UnsupportedOperationException |
1041 |
* if the attribute view is not available |
|
1042 |
* @throws IllegalArgumentException |
|
1043 |
* if no attributes are specified or an unrecognized attributes is |
|
1044 |
* specified |
|
8158 | 1045 |
* @throws IOException |
1046 |
* If an I/O error occurs |
|
1047 |
* @throws SecurityException |
|
1048 |
* In the case of the default provider, and a security manager is |
|
1049 |
* installed, its {@link SecurityManager#checkRead(String) checkRead} |
|
1050 |
* method denies read access to the file. If this method is invoked |
|
1051 |
* to read security sensitive attributes then the security manager |
|
1052 |
* may be invoke to check for additional permissions. |
|
1053 |
*/ |
|
1054 |
public abstract Map<String,Object> readAttributes(Path path, String attributes, |
|
1055 |
LinkOption... options) |
|
1056 |
throws IOException; |
|
1057 |
||
1058 |
/** |
|
1059 |
* Sets the value of a file attribute. This method works in exactly the |
|
1060 |
* manner specified by the {@link Files#setAttribute} method. |
|
1061 |
* |
|
1062 |
* @param path |
|
1063 |
* the path to the file |
|
1064 |
* @param attribute |
|
1065 |
* the attribute to set |
|
1066 |
* @param value |
|
1067 |
* the attribute value |
|
1068 |
* @param options |
|
1069 |
* options indicating how symbolic links are handled |
|
1070 |
* |
|
1071 |
* @throws UnsupportedOperationException |
|
8808 | 1072 |
* if the attribute view is not available |
8158 | 1073 |
* @throws IllegalArgumentException |
8808 | 1074 |
* if the attribute name is not specified, or is not recognized, or |
1075 |
* the attribute value is of the correct type but has an |
|
8158 | 1076 |
* inappropriate value |
1077 |
* @throws ClassCastException |
|
1078 |
* If the attribute value is not of the expected type or is a |
|
1079 |
* collection containing elements that are not of the expected |
|
1080 |
* type |
|
1081 |
* @throws IOException |
|
1082 |
* If an I/O error occurs |
|
1083 |
* @throws SecurityException |
|
1084 |
* In the case of the default provider, and a security manager is |
|
1085 |
* installed, its {@link SecurityManager#checkWrite(String) checkWrite} |
|
1086 |
* method denies write access to the file. If this method is invoked |
|
1087 |
* to set security sensitive attributes then the security manager |
|
1088 |
* may be invoked to check for additional permissions. |
|
1089 |
*/ |
|
1090 |
public abstract void setAttribute(Path path, String attribute, |
|
1091 |
Object value, LinkOption... options) |
|
1092 |
throws IOException; |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1093 |
} |