IUserDefinedFileAttributeView.Write(String, ByteBuffer) Method

Definition

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

[Android.Runtime.Register("write", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)I", "GetWrite_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 Write (string? name, Java.Nio.ByteBuffer? src);
[<Android.Runtime.Register("write", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)I", "GetWrite_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 Write : string * Java.Nio.ByteBuffer -> int

Parameters

name
String

The attribute name

src
ByteBuffer

The buffer containing the attribute value

Returns

The number of bytes written, possibly zero

Attributes

Remarks

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. If it 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.

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

Java documentation for java.nio.file.attribute.UserDefinedFileAttributeView.write(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