Share via


IAsynchronousByteChannel.Write Method

Definition

Overloads

Write(ByteBuffer)

Writes a sequence of bytes to this channel from the given buffer.

Write(ByteBuffer, Object, ICompletionHandler)

Writes a sequence of bytes to this channel from the given buffer.

Write(ByteBuffer)

Writes a sequence of bytes to this channel from the given buffer.

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetWrite_Ljava_nio_ByteBuffer_Handler:Java.Nio.Channels.IAsynchronousByteChannelInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
public Java.Util.Concurrent.IFuture? Write (Java.Nio.ByteBuffer? src);
[<Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetWrite_Ljava_nio_ByteBuffer_Handler:Java.Nio.Channels.IAsynchronousByteChannelInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
abstract member Write : Java.Nio.ByteBuffer -> Java.Util.Concurrent.IFuture

Parameters

src
ByteBuffer

The buffer from which bytes are to be retrieved

Returns

A Future representing the result of the operation

Attributes

Remarks

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a sequence of bytes to this channel from the given buffer. The method behaves in exactly the same manner as the #write(ByteBuffer,Object,CompletionHandler) write(ByteBuffer,Object,CompletionHandler) method except that instead of specifying a completion handler, this method returns a Future representing the pending result. The Future's Future#get() get method returns the number of bytes written.

Java documentation for java.nio.channels.AsynchronousByteChannel.write(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

Write(ByteBuffer, Object, ICompletionHandler)

Writes a sequence of bytes to this channel from the given buffer.

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_Ljava_nio_ByteBuffer_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler:Java.Nio.Channels.IAsynchronousByteChannelInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "A" })]
public void Write (Java.Nio.ByteBuffer? src, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_Ljava_nio_ByteBuffer_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler:Java.Nio.Channels.IAsynchronousByteChannelInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "A" })>]
abstract member Write : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

src
ByteBuffer

The buffer from which bytes are to be retrieved

attachment
Object

The object to attach to the I/O operation; can be null

handler
ICompletionHandler

The completion handler object

Attributes

Remarks

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a sequence of bytes to this channel from the given buffer. The handler parameter is a completion handler that is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of bytes written.

The write operation may write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining() at the time that the write is attempted. Where r is 0, the write operation completes immediately with a result of 0 without initiating an I/O operation.

Suppose that a byte sequence of length n is written, where 0&nbsp;<&nbsp;n&nbsp;<=&nbsp;r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment the write is performed; the index of the last byte written will be p&nbsp;+&nbsp;n&nbsp;-&nbsp;1. Upon completion the buffer's position will be equal to p&nbsp;+&nbsp;n; its limit will not have changed.

Buffers are not safe for use by multiple concurrent threads so care should be taken to not access the buffer until the operation has completed.

This method may be invoked at any time. Some channel types may not allow more than one write to be outstanding at any given time. If a thread initiates a write operation before a previous write operation has completed then a WritePendingException will be thrown.

Java documentation for java.nio.channels.AsynchronousByteChannel.write(java.nio.ByteBuffer, A, java.nio.channels.CompletionHandler<java.lang.Integer, ? super A>).

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