Freigeben über


AtomicFile Class

Definition

Helper class for performing atomic operations on a file by writing to a new file and renaming it into the place of the original file after the write has successfully completed.

[Android.Runtime.Register("android/util/AtomicFile", DoNotGenerateAcw=true)]
public class AtomicFile : Java.Lang.Object
[<Android.Runtime.Register("android/util/AtomicFile", DoNotGenerateAcw=true)>]
type AtomicFile = class
    inherit Object
Inheritance
AtomicFile
Attributes

Remarks

Helper class for performing atomic operations on a file by writing to a new file and renaming it into the place of the original file after the write has successfully completed. If you need this on older versions of the platform you can use androidx.core.util.AtomicFile in AndroidX.

Atomic file guarantees file integrity by ensuring that a file has been completely written and sync'd to disk before renaming it to the original file. Previously this is done by renaming the original file to a backup file beforehand, but this approach couldn't handle the case where the file is created for the first time. This class will also handle the backup file created by the old implementation properly.

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.

Java documentation for android.util.AtomicFile.

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

AtomicFile(File)

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

AtomicFile(IntPtr, JniHandleOwnership)

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

Properties

BaseFile

Return the path to the base file.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LastModifiedTime

Gets the last modified time of the atomic file.

PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Delete()

Delete the atomic file.

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

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

(Inherited from Object)
FailWrite(Stream)

Call when you have failed for some reason at writing to the stream returned by #startWrite().

FailWriteAsync(Stream)
FinishWrite(Stream)

Call when you have successfully finished writing to the stream returned by #startWrite().

FinishWriteAsync(Stream)
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)
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)
OpenRead()

Open the atomic file for reading.

ReadFully()

A convenience for #openRead() that also reads all of the file contents into a byte array which is returned.

ReadFullyAsync()
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
StartWrite()

Start a new write operation on the file.

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

Returns a string representation of the object.

(Inherited from Object)
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)

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