AsynchronousFileChannel Class

Definition

An asynchronous channel for reading, writing, and manipulating a file.

[Android.Runtime.Register("java/nio/channels/AsynchronousFileChannel", ApiSince=26, DoNotGenerateAcw=true)]
public abstract class AsynchronousFileChannel : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Nio.Channels.IAsynchronousChannel
[<Android.Runtime.Register("java/nio/channels/AsynchronousFileChannel", ApiSince=26, DoNotGenerateAcw=true)>]
type AsynchronousFileChannel = class
    inherit Object
    interface IAsynchronousChannel
    interface IChannel
    interface ICloseable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
AsynchronousFileChannel
Attributes
Implements

Remarks

An asynchronous channel for reading, writing, and manipulating a file.

An asynchronous file channel is created when a file is opened by invoking one of the #open open methods defined by this class. The file contains a variable-length sequence of bytes that can be read and written and whose current size can be #size() queried. The size of the file increases when bytes are written beyond its current size; the size of the file decreases when it is #truncate truncated.

An asynchronous file channel does not have a current position within the file. Instead, the file position is specified to each read and write method that initiates asynchronous operations. A CompletionHandler is specified as a parameter and is invoked to consume the result of the I/O operation. This class also defines read and write methods that initiate asynchronous operations, returning a Future to represent the pending result of the operation. The Future may be used to check if the operation has completed, wait for its completion, and retrieve the result.

In addition to read and write operations, this class defines the following operations:

<ul>

<li>

Updates made to a file may be #force <i>forced out</i> to the underlying storage device, ensuring that data are not lost in the event of a system crash.

</li>

<li>

A region of a file may be #lock <i>locked</i> against access by other programs.

</li>

</ul>

An AsynchronousFileChannel is associated with a thread pool to which tasks are submitted to handle I/O events and dispatch to completion handlers that consume the results of I/O operations on the channel. The completion handler for an I/O operation initiated on a channel is guaranteed to be invoked by one of the threads in the thread pool (This ensures that the completion handler is run by a thread with the expected <em>identity</em>). Where an I/O operation completes immediately, and the initiating thread is itself a thread in the thread pool, then the completion handler may be invoked directly by the initiating thread. When an AsynchronousFileChannel is created without specifying a thread pool then the channel is associated with a system-dependent default thread pool that may be shared with other channels. The default thread pool is configured by the system properties defined by the AsynchronousChannelGroup class.

Channels of this type are safe for use by multiple concurrent threads. The Channel#close close method may be invoked at any time, as specified by the Channel interface. This causes all outstanding asynchronous operations on the channel to complete with the exception AsynchronousCloseException. Multiple read and write operations may be outstanding at the same time. When multiple read and write operations are outstanding then the ordering of the I/O operations, and the order that the completion handlers are invoked, is not specified; they are not, in particular, guaranteed to execute in the order that the operations were initiated. The java.nio.ByteBuffer ByteBuffers used when reading or writing are not safe for use by multiple concurrent I/O operations. Furthermore, after an I/O operation is initiated then care should be taken to ensure that the buffer is not accessed until after the operation has completed.

As with FileChannel, the view of a file provided by an instance of this class is guaranteed to be consistent with other views of the same file provided by other instances in the same program. The view provided by an instance of this class may or may not, however, be consistent with the views seen by other concurrently-running programs due to caching performed by the underlying operating system and delays induced by network-filesystem protocols. This is true regardless of the language in which these other programs are written, and whether they are running on the same machine or on some other machine. The exact nature of any such inconsistencies are system-dependent and are therefore unspecified.

Added in 1.7.

Java documentation for java.nio.channels.AsynchronousFileChannel.

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.

Constructors

AsynchronousFileChannel()

Initializes a new instance of this class.

AsynchronousFileChannel(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsOpen
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass
ThresholdType

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Close()

Closes this channel.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Force(Boolean)

Forces any updates to this channel's file to be written to the storage device that contains it.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Lock()

Acquires an exclusive lock on this channel's file.

Lock(Int64, Int64, Boolean, Object, ICompletionHandler)

Acquires a lock on the given region of this channel's file.

Lock(Int64, Int64, Boolean)

Acquires a lock on the given region of this channel's file.

Lock(Object, ICompletionHandler)

Acquires an exclusive lock on this channel's file.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Open(IPath, ICollection<IOpenOption>, IExecutorService, IFileAttribute[])

Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file.

Open(IPath, IOpenOption[])

Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file.

Read(ByteBuffer, Int64, Object, ICompletionHandler)

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

Read(ByteBuffer, Int64)

Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Size()

Returns the current size of this channel's file.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
Truncate(Int64)

Truncates this channel's file to the given size.

TryLock()

Attempts to acquire an exclusive lock on this channel's file.

TryLock(Int64, Int64, Boolean)

Attempts to acquire a lock on the given region of this channel's file.

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Write(ByteBuffer, Int64, Object, ICompletionHandler)

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

Write(ByteBuffer, Int64)

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to