次の方法で共有


IAsynchronousByteChannel.Read Method

Definition

Overloads

Read(ByteBuffer)

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

Read(ByteBuffer, Object, ICompletionHandler)

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

Read(ByteBuffer)

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

[Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetRead_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? Read (Java.Nio.ByteBuffer? dst);
[<Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;)Ljava/util/concurrent/Future;", "GetRead_Ljava_nio_ByteBuffer_Handler:Java.Nio.Channels.IAsynchronousByteChannelInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
abstract member Read : Java.Nio.ByteBuffer -> Java.Util.Concurrent.IFuture

Parameters

dst
ByteBuffer

The buffer into which bytes are to be transferred

Returns

A Future representing the result of the operation

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 method behaves in exactly the same manner as the #read(ByteBuffer,Object,CompletionHandler) read(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 read or -1 if no bytes could be read because the channel has reached end-of-stream.

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

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

[Android.Runtime.Register("read", "(Ljava/nio/ByteBuffer;Ljava/lang/Object;Ljava/nio/channels/CompletionHandler;)V", "GetRead_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 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", "GetRead_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 Read : Java.Nio.ByteBuffer * Java.Lang.Object * Java.Nio.Channels.ICompletionHandler -> unit

Parameters

dst
ByteBuffer

The buffer into which bytes are to be transferred

attachment
Object

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

handler
ICompletionHandler

The completion handler

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.

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

Suppose that a byte sequence of length n is read, where 0&nbsp;<&nbsp;n&nbsp;<=&nbsp;r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p&nbsp;+&nbsp;n&nbsp;-&nbsp;1, where p is the buffer's position at the moment the read is performed. 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 read to be outstanding at any given time. If a thread initiates a read operation before a previous read operation has completed then a ReadPendingException will be thrown.

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