19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.nio.file.*; |
24 import java.nio.file.AccessMode; |
25 import java.nio.file.attribute.*; |
25 import java.nio.file.ClosedFileSystemException; |
|
26 import java.nio.file.DirectoryStream; |
|
27 import java.nio.file.FileStore; |
|
28 import java.nio.file.FileSystem; |
|
29 import java.nio.file.FileSystems; |
|
30 import java.nio.file.FileVisitResult; |
|
31 import java.nio.file.Files; |
|
32 import java.nio.file.Path; |
|
33 import java.nio.file.Paths; |
|
34 import java.nio.file.SimpleFileVisitor; |
|
35 import java.nio.file.StandardCopyOption; |
|
36 import java.nio.file.attribute.BasicFileAttributes; |
26 import java.nio.file.spi.FileSystemProvider; |
37 import java.nio.file.spi.FileSystemProvider; |
27 import java.util.*; |
|
28 import java.net.URI; |
38 import java.net.URI; |
29 import java.io.IOException; |
39 import java.io.IOException; |
|
40 import java.util.Collections; |
|
41 import java.util.Map; |
30 |
42 |
31 /** |
43 /** |
32 * |
|
33 * @test |
44 * @test |
34 * @bug 8038500 8040059 |
45 * @bug 8038500 8040059 |
35 * @summary Basic test for zip provider |
46 * @summary Basic test for zip provider |
36 * |
47 * |
37 * @run main Basic |
48 * @run main Basic |
38 * @run main/othervm/java.security.policy=test.policy Basic |
49 * @run main/othervm/java.security.policy=test.policy Basic |
39 */ |
50 */ |
40 |
51 |
41 public class Basic { |
52 public class Basic { |
42 public static void main(String[] args) throws Exception { |
53 public static void main(String[] args) throws Exception { |
43 Path zipfile = Paths.get(System.getProperty("test.jdk"), |
|
44 "jre/lib/ext/zipfs.jar"); |
|
45 // Test: zip should should be returned in provider list |
54 // Test: zip should should be returned in provider list |
46 boolean found = false; |
55 boolean found = false; |
47 |
|
48 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { |
56 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { |
49 if (provider.getScheme().equalsIgnoreCase("jar")) { |
57 if (provider.getScheme().equalsIgnoreCase("jar")) { |
50 found = true; |
58 found = true; |
51 break; |
59 break; |
52 } |
60 } |
53 } |
61 } |
54 if (!found) |
62 if (!found) |
55 throw new RuntimeException("'jar' provider not installed"); |
63 throw new RuntimeException("'jar' provider not installed"); |
56 |
64 |
|
65 // create JAR file for test |
|
66 Path jarFile = Utils.createJarFile("basic.jar", |
|
67 "META-INF/services/java.nio.file.spi.FileSystemProvider"); |
|
68 |
57 // Test: FileSystems#newFileSystem(Path) |
69 // Test: FileSystems#newFileSystem(Path) |
58 Map<String,?> env = new HashMap<String,Object>(); |
70 Map<String,?> env = Collections.emptyMap(); |
59 FileSystems.newFileSystem(zipfile, null).close(); |
71 FileSystems.newFileSystem(jarFile, null).close(); |
60 |
72 |
61 // Test: FileSystems#newFileSystem(URI) |
73 // Test: FileSystems#newFileSystem(URI) |
62 URI uri = new URI("jar", zipfile.toUri().toString(), null); |
74 URI uri = new URI("jar", jarFile.toUri().toString(), null); |
63 FileSystem fs = FileSystems.newFileSystem(uri, env, null); |
75 FileSystem fs = FileSystems.newFileSystem(uri, env, null); |
64 |
76 |
65 // Test: exercise toUri method |
77 // Test: exercise toUri method |
66 String expected = uri.toString() + "!/foo"; |
78 String expected = uri.toString() + "!/foo"; |
67 String actual = fs.getPath("/foo").toUri().toString(); |
79 String actual = fs.getPath("/foo").toUri().toString(); |