Share via


IUserDefinedFileAttributeView.Read(String, ByteBuffer) Method

Definition

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

[Android.Runtime.Register("read", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)I", "GetRead_Ljava_lang_String_Ljava_nio_ByteBuffer_Handler:Java.Nio.FileNio.Attributes.IUserDefinedFileAttributeViewInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
public int Read (string? name, Java.Nio.ByteBuffer? dst);
[<Android.Runtime.Register("read", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)I", "GetRead_Ljava_lang_String_Ljava_nio_ByteBuffer_Handler:Java.Nio.FileNio.Attributes.IUserDefinedFileAttributeViewInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
abstract member Read : string * Java.Nio.ByteBuffer -> int

Parameters

name
String

The attribute name

dst
ByteBuffer

The destination buffer

Returns

The number of bytes read, possibly zero

Attributes

Remarks

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.

<b>Usage Example:</b> 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();

Java documentation for java.nio.file.attribute.UserDefinedFileAttributeView.read(java.lang.String, java.nio.ByteBuffer).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to