AsynchronousSocketChannel.Read Method

Definition

Overloads

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

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

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

Reads a sequence of bytes from this channel into the given buffer.

Read(ByteBuffer)
Read(ByteBuffer, Object, ICompletionHandler)

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

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

[Android.Runtime.Register("read", "([Ljava/nio/ByteBuffer;IIJLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetRead_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 Read (Java.Nio.ByteBuffer[]? dsts, int offset, int length, long timeout, Java.Util.Concurrent.TimeUnit? unit, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("read", "([Ljava/nio/ByteBuffer;IIJLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetRead_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 Read : Java.Nio.ByteBuffer[] * int * int * int64 * Java.Util.Concurrent.TimeUnit * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

dsts
ByteBuffer[]

The buffers into which bytes are to be transferred

offset
Int32

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

length
Int32

The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.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

Reads a sequence of bytes from this channel into a subsequence of the given buffers. This operation, sometimes called a <em>scattering read</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 read operation completes (or fails). The result passed to the completion handler is the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream.

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

<blockquote>

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

</blockquote>

at the moment that the read is attempted.

Suppose that a byte sequence of length n is read, where 0&nbsp;<&nbsp;n&nbsp;<=&nbsp;r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into 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 read, or will not be read from the channel into the given buffers, then further attempts to read from the channel will cause an unspecific runtime exception to be thrown.

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

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

Reads a sequence of bytes from this channel into the given buffer.

[Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;JLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetRead_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 Read (Java.Nio.ByteBuffer? dst, long timeout, Java.Util.Concurrent.TimeUnit? unit, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;JLjava/util/concurrent/TimeUnit;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetRead_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 Read : Java.Nio.ByteBuffer * int64 * Java.Util.Concurrent.TimeUnit * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

dst
ByteBuffer

The buffer into which bytes are to be transferred

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

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a sequence of bytes from this channel into the given buffer. The handler parameter is a completion handler that is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of bytes read or -1 if no bytes could be read because the channel has reached end-of-stream.

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

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

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

Read(ByteBuffer)

[Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetRead_Ljava_nio_ByteBuffer_Handler", ApiSince=26)]
public abstract Java.Util.Concurrent.IFuture? Read (Java.Nio.ByteBuffer? dst);
[<Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetRead_Ljava_nio_ByteBuffer_Handler", ApiSince=26)>]
abstract member Read : Java.Nio.ByteBuffer -> Java.Util.Concurrent.IFuture

Parameters

Returns

Implements

Attributes

Remarks

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

Read(ByteBuffer, Object, ICompletionHandler)

[Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "A" })]
public void Read (Java.Nio.ByteBuffer? dst, Java.Lang.Object? attachment, Java.Nio.Channels.ICompletionHandler? handler);
[<Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "A" })>]
abstract member Read : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit
override this.Read : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

attachment
Object

Implements

Attributes

Remarks

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