Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/nio/channels/unixdomain/FileAttributes.java
41153 views
1
/*
2
* Copyright (c) 2021, 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
/**
25
* @test
26
* @bug 8252971
27
* @library /test/lib
28
* @run testng FileAttributes
29
*/
30
31
import java.io.IOException;
32
import java.io.File;
33
import java.net.*;
34
import java.nio.channels.*;
35
import java.nio.file.Files;
36
import java.nio.file.Path;
37
import java.nio.file.attribute.BasicFileAttributes;
38
import java.util.Arrays;
39
import org.testng.annotations.Test;
40
import org.testng.SkipException;
41
42
import static java.net.StandardProtocolFamily.UNIX;
43
import static org.testng.Assert.assertFalse;
44
import static org.testng.Assert.assertThrows;
45
import static org.testng.Assert.assertTrue;
46
47
/**
48
*/
49
public class FileAttributes {
50
51
@Test
52
public static void test() throws Exception {
53
checkSupported();
54
Path path = null;
55
try (var chan = SocketChannel.open(UNIX)) {
56
path = Path.of("foo.sock");
57
var addr = UnixDomainSocketAddress.of(path);
58
59
chan.bind(addr);
60
61
// Check file exists
62
63
File f = path.toFile();
64
assertTrue(f.exists(), "File.exists failed");
65
66
assertTrue(Files.exists(path), "Files.exists failed");
67
68
// Check basic attributes
69
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
70
71
assertFalse(attrs.isDirectory(), "file is not a directory");
72
assertTrue(attrs.isOther(), "file is other");
73
assertFalse(attrs.isRegularFile(), "file is not a regular file");
74
assertFalse(attrs.isSymbolicLink(), "file is not a symbolic link");
75
76
// Check can't copy
77
final Path src = path;
78
final Path dest = Path.of("bar.sock");
79
assertThrows(IOException.class, () -> Files.copy(src, dest));
80
81
// Check deletion
82
assertTrue(f.delete(), "File.delete failed");
83
} finally {
84
Files.deleteIfExists(path);
85
}
86
}
87
88
static void checkSupported() {
89
try {
90
SocketChannel.open(UNIX).close();
91
} catch (UnsupportedOperationException e) {
92
throw new SkipException("Unix domain channels not supported");
93
} catch (Exception e) {
94
// continue test to see what problem is
95
}
96
}
97
}
98
99