Share via


AsynchronousSocketChannel.Write Method

Definition

Overloads

Write(ByteBuffer, Int64, TimeUnit, Object, ICompletionHandler)

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

Write(ByteBuffer)
Write(ByteBuffer, Object, ICompletionHandler)
Write(ByteBuffer[], Int32, Int32, Int64, TimeUnit, Object, ICompletionHandler)

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

Write(ByteBuffer, Int64, TimeUnit, Object, ICompletionHandler)

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

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;JLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_Ljava_nio_ByteBuffer_JLjava_util_concurrent_TimeUnit_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "A" })]
public abstract void Write (Java.Nio.ByteBuffer? src, long timeout, Java.Util.Concurrent.TimeUnit? unit, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;JLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_Ljava_nio_ByteBuffer_JLjava_util_concurrent_TimeUnit_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "A" })>]
abstract member Write : Java.Nio.ByteBuffer * int64 * Java.Util.Concurrent.TimeUnit * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

src
ByteBuffer

The buffer from which bytes are to be retrieved

timeout
Int64

The maximum time for the I/O operation to complete

unit
TimeUnit

The time unit of the timeout argument

attachment
Object

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

handler
ICompletionHandler

The handler for consuming the result

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.

If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffer, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.

Otherwise this method works in the same manner as the AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler) method.

Java documentation for java.nio.channels.AsynchronousSocketChannel.write(java.nio.ByteBuffer, long, java.util.concurrent.TimeUnit, 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

Write(ByteBuffer)

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetWrite_Ljava_nio_ByteBuffer_Handler", ApiSince=26)]
public abstract 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", ApiSince=26)>]
abstract member Write : Java.Nio.ByteBuffer -> Java.Util.Concurrent.IFuture

Parameters

Returns

Implements

Attributes

Remarks

Java documentation for java.nio.channels.AsynchronousSocketChannel.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)

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "", 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", "", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "A" })>]
abstract member Write : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit
override this.Write : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

attachment
Object

Implements

Attributes

Remarks

Java documentation for java.nio.channels.AsynchronousSocketChannel.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

Write(ByteBuffer[], Int32, Int32, Int64, TimeUnit, Object, ICompletionHandler)

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

[Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;IIJLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_arrayLjava_nio_ByteBuffer_IIJLjava_util_concurrent_TimeUnit_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "A" })]
public abstract void Write (Java.Nio.ByteBuffer[]? srcs, int offset, int length, long timeout, Java.Util.Concurrent.TimeUnit? unit, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;IIJLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetWrite_arrayLjava_nio_ByteBuffer_IIJLjava_util_concurrent_TimeUnit_Ljava_lang_Object_Ljava_nio_channels_CompletionHandler_Handler", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "A" })>]
abstract member Write : Java.Nio.ByteBuffer[] * int * int * int64 * Java.Util.Concurrent.TimeUnit * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

srcs
ByteBuffer[]

The buffers from which bytes are to be retrieved

offset
Int32

The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length

length
Int32

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

timeout
Int64

The maximum time for the I/O operation to complete

unit
TimeUnit

The time unit of the timeout argument

attachment
Object

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

handler
ICompletionHandler

The handler for consuming the result

Attributes

Remarks

Writes a sequence of bytes to this channel from a subsequence of the given buffers. This operation, sometimes called a <em>gathering write</em>, is often useful when implementing network protocols that group data into segments consisting of one or more fixed-length headers followed by a variable-length body. 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.

This method initiates a write of up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

<blockquote>

srcs[offset].remaining()
                + srcs[offset+1].remaining()
                + ... + srcs[offset+length-1].remaining()

</blockquote>

at the moment that the write is attempted.

Suppose that a byte sequence of length n is written, where 0&nbsp;<&nbsp;n&nbsp;<=&nbsp;r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.

If a timeout is specified and the timeout elapses before the operation completes then it completes with the exception InterruptedByTimeoutException. Where a timeout occurs, and the implementation cannot guarantee that bytes have not been written, or will not be written to the channel from the given buffers, then further attempts to write to the channel will cause an unspecific runtime exception to be thrown.

Java documentation for java.nio.channels.AsynchronousSocketChannel.write(java.nio.ByteBuffer[], int, int, long, java.util.concurrent.TimeUnit, A, java.nio.channels.CompletionHandler<java.lang.Long, ? 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