Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/file/FileSystem/Basic.java
38828 views
1
/*
2
* Copyright (c) 2008, 2019, 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
/* @test
25
* @bug 4313887 6838333
26
* @summary Unit test for java.nio.file.FileSystem
27
* @library .. /lib/testlibrary
28
* @build jdk.testlibrary.FileUtils
29
* @run main Basic
30
*/
31
32
import java.io.File;
33
import java.io.IOException;
34
import java.net.URI;
35
import java.net.URISyntaxException;
36
import java.nio.file.Files;
37
import java.nio.file.FileStore;
38
import java.nio.file.FileSystem;
39
import java.nio.file.FileSystems;
40
import java.nio.file.Path;
41
import java.nio.file.Paths;
42
import java.nio.file.ProviderNotFoundException;
43
import java.util.HashMap;
44
import java.util.concurrent.TimeUnit;
45
import jdk.testlibrary.FileUtils;
46
47
/**
48
* Simple santity checks for java.nio.file.FileSystem
49
*/
50
public class Basic {
51
52
static void check(boolean okay, String msg) {
53
if (!okay)
54
throw new RuntimeException(msg);
55
}
56
57
static void checkFileStores(FileSystem fs) throws IOException {
58
// sanity check method
59
if (FileUtils.areFileSystemsAccessible()) {
60
System.out.println("\n--- Begin FileStores ---");
61
for (FileStore store: fs.getFileStores()) {
62
System.out.println(store);
63
}
64
System.out.println("--- EndFileStores ---\n");
65
} else {
66
System.err.println
67
("Skipping FileStore check due to file system access failure");
68
}
69
}
70
71
static void checkSupported(FileSystem fs, String... views) {
72
for (String view: views) {
73
check(fs.supportedFileAttributeViews().contains(view),
74
"support for '" + view + "' expected");
75
}
76
}
77
78
public static void main(String[] args)
79
throws IOException, URISyntaxException {
80
String os = System.getProperty("os.name");
81
FileSystem fs = FileSystems.getDefault();
82
83
// close should throw UOE
84
try {
85
fs.close();
86
throw new RuntimeException("UnsupportedOperationException expected");
87
} catch (UnsupportedOperationException e) { }
88
check(fs.isOpen(), "should be open");
89
90
check(!fs.isReadOnly(), "should provide read-write access");
91
92
check(fs.provider().getScheme().equals("file"),
93
"should use 'file' scheme");
94
95
// sanity check FileStores
96
checkFileStores(fs);
97
98
// sanity check supportedFileAttributeViews
99
checkSupported(fs, "basic");
100
if (os.equals("SunOS"))
101
checkSupported(fs, "posix", "unix", "owner", "acl", "user");
102
if (os.equals("Linux"))
103
checkSupported(fs, "posix", "unix", "owner", "dos", "user");
104
if (os.contains("OS X"))
105
checkSupported(fs, "posix", "unix", "owner");
106
if (os.equals("Windows"))
107
checkSupported(fs, "owner", "dos", "acl", "user");
108
}
109
}
110
111