Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java
41159 views
1
/*
2
* Copyright (c) 2008, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.nio.fs;
27
28
import java.nio.ByteBuffer;
29
import java.nio.file.attribute.UserDefinedFileAttributeView;
30
import java.io.IOException;
31
import java.util.*;
32
33
/**
34
* Base implementation of UserDefinedAttributeView
35
*/
36
37
abstract class AbstractUserDefinedFileAttributeView
38
implements UserDefinedFileAttributeView, DynamicFileAttributeView
39
{
40
protected AbstractUserDefinedFileAttributeView() { }
41
42
protected void checkAccess(String file,
43
boolean checkRead,
44
boolean checkWrite)
45
{
46
assert checkRead || checkWrite;
47
@SuppressWarnings("removal")
48
SecurityManager sm = System.getSecurityManager();
49
if (sm != null) {
50
if (checkRead)
51
sm.checkRead(file);
52
if (checkWrite)
53
sm.checkWrite(file);
54
sm.checkPermission(new RuntimePermission("accessUserDefinedAttributes"));
55
}
56
}
57
58
@Override
59
public final String name() {
60
return "user";
61
}
62
63
@Override
64
public final void setAttribute(String attribute, Object value)
65
throws IOException
66
{
67
ByteBuffer bb;
68
if (value instanceof byte[]) {
69
bb = ByteBuffer.wrap((byte[])value);
70
} else {
71
bb = (ByteBuffer)value;
72
}
73
write(attribute, bb);
74
}
75
76
@Override
77
public final Map<String,Object> readAttributes(String[] attributes)
78
throws IOException
79
{
80
// names of attributes to return
81
List<String> names = new ArrayList<>();
82
for (String name: attributes) {
83
if (name.equals("*")) {
84
names = list();
85
break;
86
} else {
87
if (name.isEmpty())
88
throw new IllegalArgumentException();
89
names.add(name);
90
}
91
}
92
93
// read each value and return in map
94
Map<String,Object> result = new HashMap<>();
95
for (String name: names) {
96
int size = size(name);
97
byte[] buf = new byte[size];
98
int n = read(name, ByteBuffer.wrap(buf));
99
byte[] value = (n == size) ? buf : Arrays.copyOf(buf, n);
100
result.put(name, value);
101
}
102
return result;
103
}
104
}
105
106