1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
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
21  * questions.
22  */
23 
24 package p;
25 
26 import java.io.File;
27 import java.nio.file.FileSystem;
28 import java.nio.file.FileSystems;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 
32 /**
33  * Launched by SetDefaultProvider to test startup with the default file system
34  * provider overridden.
35  */
36 
37 public class Main {
main(String[] args)38     public static void main(String[] args) throws Exception {
39         FileSystem fs = FileSystems.getDefault();
40         if (fs.getClass().getModule() == Object.class.getModule())
41             throw new RuntimeException("FileSystemProvider not overridden");
42 
43         // exercise the file system
44         Path dir = Files.createTempDirectory("tmp");
45         if (dir.getFileSystem() != fs)
46             throw new RuntimeException("'dir' not in default file system");
47         System.out.println("created: " + dir);
48 
49         Path foo = Files.createFile(dir.resolve("foo"));
50         if (foo.getFileSystem() != fs)
51             throw new RuntimeException("'foo' not in default file system");
52         System.out.println("created: " + foo);
53 
54         // exercise interop with java.io.File
55         File file = foo.toFile();
56         Path path = file.toPath();
57         if (path.getFileSystem() != fs)
58             throw new RuntimeException("'path' not in default file system");
59         if (!path.equals(foo))
60             throw new RuntimeException(path + " not equal to " + foo);
61     }
62 }
63