APIdia Launch Partner
Top Description Fields Constructors Methods
sun.nio.fs

pack-priv abstract Class UnixUserDefinedFileAttributeView

extends AbstractUserDefinedFileAttributeView
Class Inheritance
Known Direct Subclasses
sun.nio.fs.LinuxUserDefinedFileAttributeView
Imports
java.io.IOException, java.nio.file.*, java.nio.ByteBuffer, java.util.*, jdk.internal.access.JavaNioAccess, .SharedSecrets, jdk.internal.misc.Unsafe

Unix implementation of UserDefinedFileAttributeView using extended attributes.

Field Summary

Modifier and TypeField and Description
private final UnixPath
private final boolean
private static final int
private static final int
private static final JavaNioAccess
private static final Unsafe
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv
UnixUserDefinedFileAttributeView(UnixPath file, boolean followLinks)

Method Summary

Modifier and TypeMethod and Description
private static List<String>
asList(long address, int size)

private static void
copyExtendedAttribute(int ofd, byte[] name, int nfd)

pack-priv static void
copyExtendedAttributes(int
file descriptor for source file
ofd
,
int
file descriptor for target file
nfd
)

Used by copyTo/moveTo to copy extended attributes from source to target.

public void
delete(String name)

Implements java.nio.file.attribute.UserDefinedFileAttributeView.delete.

Deletes a user-defined attribute.

private static List<String>
list(int fd, int bufSize)

public List<String>
list()

Implements java.nio.file.attribute.UserDefinedFileAttributeView.list.

Returns a list containing the names of the user-defined attributes.

protected abstract int
maxNameLength()

Returns: the maximum supported length of xattr names (in bytes, including namespace)

private byte[]
public int
read(String name, ByteBuffer dst)

Implements java.nio.file.attribute.UserDefinedFileAttributeView.read.

Read the value of a user-defined attribute into a buffer.

private int
read(String name, long address, int rem)

public int
size(String name)

Implements java.nio.file.attribute.UserDefinedFileAttributeView.size.

Returns the size of the value of a user-defined attribute.

public int
write(String name, ByteBuffer src)

Implements java.nio.file.attribute.UserDefinedFileAttributeView.write.

Writes the value of a user-defined attribute from a buffer.

private void
write(String name, long address, int rem)

Inherited from sun.nio.fs.AbstractUserDefinedFileAttributeView:
namereadAttributessetAttribute

Field Detail

fileback to summary
private final UnixPath file
MAX_LISTXATTR_BUF_SIZEback to summary
private static final int MAX_LISTXATTR_BUF_SIZE
MIN_LISTXATTR_BUF_SIZEback to summary
private static final int MIN_LISTXATTR_BUF_SIZE
NIO_ACCESSback to summary
private static final JavaNioAccess NIO_ACCESS
unsafeback to summary
private static final Unsafe unsafe
USER_NAMESPACEback to summary
private static final String USER_NAMESPACE

Constructor Detail

UnixUserDefinedFileAttributeViewback to summary
pack-priv UnixUserDefinedFileAttributeView(UnixPath file, boolean followLinks)

Method Detail

asListback to summary
private static List<String> asList(long address, int size)
copyExtendedAttributeback to summary
private static void copyExtendedAttribute(int ofd, byte[] name, int nfd) throws UnixException
copyExtendedAttributesback to summary
pack-priv static void copyExtendedAttributes(int ofd, int nfd)

Used by copyTo/moveTo to copy extended attributes from source to target.

Parameters
ofd:int

file descriptor for source file

nfd:int

file descriptor for target file

deleteback to summary
public void delete(String name) throws IOException

Implements java.nio.file.attribute.UserDefinedFileAttributeView.delete.

Doc from java.nio.file.attribute.UserDefinedFileAttributeView.delete.

Deletes a user-defined attribute.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the attribute does not exist
listback to summary
private static List<String> list(int fd, int bufSize) throws UnixException
listback to summary
public List<String> list() throws IOException

Implements java.nio.file.attribute.UserDefinedFileAttributeView.list.

Doc from java.nio.file.attribute.UserDefinedFileAttributeView.list.

Returns a list containing the names of the user-defined attributes.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
maxNameLengthback to summary
protected abstract int maxNameLength()
Returns:int

the maximum supported length of xattr names (in bytes, including namespace)

nameAsBytesback to summary
private byte[] nameAsBytes(UnixPath file, String name) throws IOException
readback to summary
public int read(String name, ByteBuffer dst) throws IOException

Implements java.nio.file.attribute.UserDefinedFileAttributeView.read.

Doc from java.nio.file.attribute.UserDefinedFileAttributeView.read.

Read the value of a user-defined attribute into a buffer.

This method reads the value of the attribute into the given buffer as a sequence of bytes, failing if the number of bytes remaining in the buffer is insufficient to read the complete attribute value. The number of bytes transferred into the buffer is n, where n is the size of the attribute value. The first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Usage Example: Suppose we want to read a file's MIME type that is stored as a user-defined attribute with the name "user.mimetype".

UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); String name = "user.mimetype"; ByteBuffer buf = ByteBuffer.allocate(view.size(name)); view.read(name, buf); buf.flip(); String value = Charset.defaultCharset().decode(buf).toString();
UserDefinedFileAttributeView view =
    Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
String name = "user.mimetype";
ByteBuffer buf = ByteBuffer.allocate(view.size(name));
view.read(name, buf);
buf.flip();
String value = Charset.defaultCharset().decode(buf).toString();
Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or there is insufficient space in the destination buffer for the attribute value
readback to summary
private int read(String name, long address, int rem) throws IOException
sizeback to summary
public int size(String name) throws IOException

Implements java.nio.file.attribute.UserDefinedFileAttributeView.size.

Doc from java.nio.file.attribute.UserDefinedFileAttributeView.size.

Returns the size of the value of a user-defined attribute.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public int write(String name, ByteBuffer src) throws IOException

Implements java.nio.file.attribute.UserDefinedFileAttributeView.write.

Doc from java.nio.file.attribute.UserDefinedFileAttributeView.write.

Writes the value of a user-defined attribute from a buffer.

This method writes the value of the attribute from a given buffer as a sequence of bytes. The size of the value to transfer is r, where r is the number of bytes remaining in the buffer, that is src.remaining(). The sequence of bytes is transferred from the buffer starting at index p, where p is the buffer's position. Upon return, the buffer's position will be equal to p + n, where n is the number of bytes transferred; its limit will not have changed.

If an attribute of the given name already exists then its value is replaced. If the attribute does not exist then it is created. It is implementation specific if a test to check for the existence of the attribute and the creation of attribute are atomic with respect to other file system activities.

Where there is insufficient space to store the attribute, or the attribute name or value exceed an implementation specific maximum size then an IOException is thrown.

Usage Example: Suppose we want to write a file's MIME type as a user-defined attribute:

UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); view.write("user.mimetype", Charset.defaultCharset().encode("text/html"));
UserDefinedFileAttributeView view =
    Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
view.write("user.mimetype", Charset.defaultCharset().encode("text/html"));
Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
private void write(String name, long address, int rem) throws IOException