Android Guides | Samples

Android.Util.AtomicFile Class

Helper class for performing atomic operations on a file by creating a backup file until a write has successfully completed.

See Also: AtomicFile

Syntax

[Android.Runtime.Register("android/util/AtomicFile", DoNotGenerateAcw=true)]
public class AtomicFile : Object

Remarks

Helper class for performing atomic operations on a file by creating a backup file until a write has successfully completed. If you need this on older versions of the platform you can use NoType:android/support/v4/util/AtomicFile;Href=../../../reference/android/support/v4/util/AtomicFile.html in the v4 support library.

Atomic file guarantees file integrity by ensuring that a file has been completely written and sync'd to disk before removing its backup. As long as the backup file exists, the original file is considered to be invalid (left over from a previous attempt to write the file).

Atomic file does not confer any file locking semantics. Do not use this class when the file may be accessed or modified concurrently by multiple threads or processes. The caller is responsible for ensuring appropriate mutual exclusion invariants whenever it accesses the file.

[Android Documentation]

Requirements

Namespace: Android.Util
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 17

The members of Android.Util.AtomicFile are listed below.

See Also: Object

Public Constructors

Create a new AtomicFile for a file located at the given File path.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
BaseFileFile. Return the path to the base file.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Delete()
Delete the atomic file.
FailWrite(Stream)
Call when you have failed for some reason at writing to the stream returned by AtomicFile.StartWrite.
FailWriteAsync(Stream) : Task
FinishWrite(Stream)
Call when you have successfully finished writing to the stream returned by AtomicFile.StartWrite.
FinishWriteAsync(Stream) : Task
OpenRead() : Stream
Open the atomic file for reading.
ReadFully() : Byte[]
A convenience for AtomicFile.OpenRead that also reads all of the file contents into a byte array which is returned.
ReadFullyAsync() : System.Threading.Tasks.Task<Byte[]>
StartWrite() : Stream
Start a new write operation on the file.
StartWriteAsync() : System.Threading.Tasks.Task<System.IO.Stream>