46 // namespace for extended user attributes
47 private static final String USER_NAMESPACE = "user.";
48
49 // maximum bytes in extended attribute name (includes namespace)
50 private static final int XATTR_NAME_MAX = 255;
51
52 private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
53 if (name == null)
54 throw new NullPointerException("'name' is null");
55 name = USER_NAMESPACE + name;
56 byte[] bytes = name.getBytes();
57 if (bytes.length > XATTR_NAME_MAX) {
58 throw new FileSystemException(file.getPathForExecptionMessage(),
59 null, "'" + name + "' is too big");
60 }
61 return bytes;
62 }
63
64 // Parses buffer as array of NULL-terminated C strings.
65 private List<String> asList(long address, int size) {
66 final List<String> list = new ArrayList<String>();
67 int start = 0;
68 int pos = 0;
69 while (pos < size) {
70 if (unsafe.getByte(address + pos) == 0) {
71 int len = pos - start;
72 byte[] value = new byte[len];
73 unsafe.copyMemory(null, address+start, value,
74 Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
75 String s = new String(value);
76 if (s.startsWith(USER_NAMESPACE)) {
77 s = s.substring(USER_NAMESPACE.length());
78 list.add(s);
79 }
80 start = pos + 1;
81 }
82 pos++;
83 }
84 return list;
85 }
86
|
46 // namespace for extended user attributes
47 private static final String USER_NAMESPACE = "user.";
48
49 // maximum bytes in extended attribute name (includes namespace)
50 private static final int XATTR_NAME_MAX = 255;
51
52 private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
53 if (name == null)
54 throw new NullPointerException("'name' is null");
55 name = USER_NAMESPACE + name;
56 byte[] bytes = name.getBytes();
57 if (bytes.length > XATTR_NAME_MAX) {
58 throw new FileSystemException(file.getPathForExecptionMessage(),
59 null, "'" + name + "' is too big");
60 }
61 return bytes;
62 }
63
64 // Parses buffer as array of NULL-terminated C strings.
65 private List<String> asList(long address, int size) {
66 final List<String> list = new ArrayList<>();
67 int start = 0;
68 int pos = 0;
69 while (pos < size) {
70 if (unsafe.getByte(address + pos) == 0) {
71 int len = pos - start;
72 byte[] value = new byte[len];
73 unsafe.copyMemory(null, address+start, value,
74 Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
75 String s = new String(value);
76 if (s.startsWith(USER_NAMESPACE)) {
77 s = s.substring(USER_NAMESPACE.length());
78 list.add(s);
79 }
80 start = pos + 1;
81 }
82 pos++;
83 }
84 return list;
85 }
86
|