52
53 public class Basic {
54 public static void main(String[] args) throws Exception {
55 // Test: zip should should be returned in provider list
56 boolean found = false;
57 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
58 if (provider.getScheme().equalsIgnoreCase("jar")) {
59 found = true;
60 break;
61 }
62 }
63 if (!found)
64 throw new RuntimeException("'jar' provider not installed");
65
66 // create JAR file for test
67 Path jarFile = Utils.createJarFile("basic.jar",
68 "META-INF/services/java.nio.file.spi.FileSystemProvider");
69
70 // Test: FileSystems#newFileSystem(Path)
71 Map<String,?> env = Collections.emptyMap();
72 FileSystems.newFileSystem(jarFile, null).close();
73
74 // Test: FileSystems#newFileSystem(URI)
75 URI uri = new URI("jar", jarFile.toUri().toString(), null);
76 FileSystem fs = FileSystems.newFileSystem(uri, env, null);
77
78 // Test: exercise toUri method
79 String expected = uri.toString() + "!/foo";
80 String actual = fs.getPath("/foo").toUri().toString();
81 if (!actual.equals(expected)) {
82 throw new RuntimeException("toUri returned '" + actual +
83 "', expected '" + expected + "'");
84 }
85
86 // Test: exercise directory iterator and retrieval of basic attributes
87 Files.walkFileTree(fs.getPath("/"), new FileTreePrinter());
88
89 // Test: copy file from zip file to current (scratch) directory
90 Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider");
91 if (Files.exists(source)) {
92 Path target = Paths.get(source.getFileName().toString());
|
52
53 public class Basic {
54 public static void main(String[] args) throws Exception {
55 // Test: zip should should be returned in provider list
56 boolean found = false;
57 for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
58 if (provider.getScheme().equalsIgnoreCase("jar")) {
59 found = true;
60 break;
61 }
62 }
63 if (!found)
64 throw new RuntimeException("'jar' provider not installed");
65
66 // create JAR file for test
67 Path jarFile = Utils.createJarFile("basic.jar",
68 "META-INF/services/java.nio.file.spi.FileSystemProvider");
69
70 // Test: FileSystems#newFileSystem(Path)
71 Map<String,?> env = Collections.emptyMap();
72 FileSystems.newFileSystem(jarFile, (ClassLoader)null).close();
73
74 // Test: FileSystems#newFileSystem(URI)
75 URI uri = new URI("jar", jarFile.toUri().toString(), null);
76 FileSystem fs = FileSystems.newFileSystem(uri, env, null);
77
78 // Test: exercise toUri method
79 String expected = uri.toString() + "!/foo";
80 String actual = fs.getPath("/foo").toUri().toString();
81 if (!actual.equals(expected)) {
82 throw new RuntimeException("toUri returned '" + actual +
83 "', expected '" + expected + "'");
84 }
85
86 // Test: exercise directory iterator and retrieval of basic attributes
87 Files.walkFileTree(fs.getPath("/"), new FileTreePrinter());
88
89 // Test: copy file from zip file to current (scratch) directory
90 Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider");
91 if (Files.exists(source)) {
92 Path target = Paths.get(source.getFileName().toString());
|